Change the compilation related Exception

 - Change the compilation related Exception from AsterixException to CompilationException
   to meet requirement of the new exception handling proposal.
 - This is an 1:1 string conversion and no errorcode handling part is included.
   That needs to be done gradually when the related  part is changed.

Change-Id: I3ff2bc3b70ad78e53a19ad94d98d17a4469ca4e1
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1437
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlExpressionToPlanTranslator.java
index 7d1ce7d..110c2b7 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlExpressionToPlanTranslator.java
@@ -22,7 +22,7 @@
 import java.util.List;
 
 import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
 import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
@@ -71,7 +71,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(ForClause fc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         LogicalVariable v = context.newVar(fc.getVarExpr());
         Expression inExpr = fc.getInExpr();
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(inExpr, tupSource);
@@ -91,7 +91,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FLWOGRExpression flwor, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> flworPlan = tupSource;
         boolean isTop = context.isTopFlwor();
         if (!isTop) {
@@ -139,13 +139,13 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(Query q, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         return q.getBody().accept(this, tupSource);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(DistinctClause dc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         List<Mutable<ILogicalExpression>> exprList = new ArrayList<>();
         Mutable<ILogicalOperator> input = null;
         for (Expression expr : dc.getDistinctByExpr()) {
@@ -160,7 +160,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(UnionExpr unionExpr, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         List<ILangExpression> inputExprs = new ArrayList<>();
         inputExprs.addAll(unionExpr.getExprs());
         Pair<ILogicalOperator, LogicalVariable> result = translateUnionAllFromInputExprs(inputExprs, tupSource);
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlPlusExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlPlusExpressionToPlanTranslator.java
index d9136ac..09d8055 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlPlusExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlPlusExpressionToPlanTranslator.java
@@ -26,7 +26,7 @@
 import java.util.logging.Logger;
 
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.common.transactions.JobId;
@@ -180,11 +180,11 @@
     private class MetaScopeLogicalVariable {
         private HashMap<Identifier, LogicalVariable> map = new HashMap<Identifier, LogicalVariable>();
 
-        public VariableReferenceExpression getVariableReferenceExpression(Identifier id) throws AsterixException {
+        public VariableReferenceExpression getVariableReferenceExpression(Identifier id) throws CompilationException {
             LogicalVariable var = map.get(id);
             LOGGER.fine("get:" + id + ":" + var);
             if (var == null) {
-                throw new AsterixException("Identifier " + id + " not found in AQL+ meta-scope.");
+                throw new CompilationException("Identifier " + id + " not found in AQL+ meta-scope.");
             }
             return new VariableReferenceExpression(var);
         }
@@ -198,10 +198,10 @@
     private class MetaScopeILogicalOperator {
         private HashMap<Identifier, ILogicalOperator> map = new HashMap<Identifier, ILogicalOperator>();
 
-        public ILogicalOperator get(Identifier id) throws AsterixException {
+        public ILogicalOperator get(Identifier id) throws CompilationException {
             ILogicalOperator op = map.get(id);
             if (op == null) {
-                throw new AsterixException("Identifier " + id + " not found in AQL+ meta-scope.");
+                throw new CompilationException("Identifier " + id + " not found in AQL+ meta-scope.");
             }
             return op;
         }
@@ -234,12 +234,12 @@
         return context.getVarCounter();
     }
 
-    public ILogicalPlan translate(Query expr) throws AlgebricksException, AsterixException {
+    public ILogicalPlan translate(Query expr) throws AlgebricksException, CompilationException {
         return translate(expr, null);
     }
 
     public ILogicalPlan translate(Query expr, MetadataProvider metadata)
-            throws AlgebricksException, AsterixException {
+            throws AlgebricksException, CompilationException {
         IDataFormat format = metadata.getFormat();
         if (format == null) {
             throw new AlgebricksException("Data format has not been set.");
@@ -294,7 +294,7 @@
         return plan;
     }
 
-    public ILogicalPlan translate(List<Clause> clauses) throws AlgebricksException, AsterixException {
+    public ILogicalPlan translate(List<Clause> clauses) throws AlgebricksException, CompilationException {
 
         if (clauses == null) {
             return null;
@@ -318,7 +318,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(ForClause fc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         LogicalVariable v = context.newVar(fc.getVarExpr());
 
         Expression inExpr = fc.getInExpr();
@@ -339,7 +339,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(LetClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         LogicalVariable v;
         ILogicalOperator returnedOp;
 
@@ -366,7 +366,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FLWOGRExpression flwor, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> flworPlan = tupSource;
         boolean isTop = context.isTopFlwor();
         if (isTop) {
@@ -407,7 +407,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FieldAccessor fa, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(fa.getExpr(), tupSource);
         LogicalVariable v = context.newVar();
         AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
@@ -424,7 +424,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(IndexAccessor ia, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(ia.getExpr(), tupSource);
         LogicalVariable v = context.newVar();
         AbstractFunctionCallExpression f;
@@ -446,7 +446,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CallExpr fcall, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         LogicalVariable v = context.newVar();
         FunctionSignature signature = fcall.getFunctionSignature();
         List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
@@ -517,7 +517,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(GroupbyClause gc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         GroupByOperator gOp = new GroupByOperator();
         Mutable<ILogicalOperator> topOp = tupSource;
         for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
@@ -570,7 +570,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(IfExpr ifexpr, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         // In the most general case, IfThenElse is translated in the following
         // way.
         //
@@ -633,7 +633,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(OperatorExpr op, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         List<OperatorType> ops = op.getOpList();
         int nOps = ops.size();
 
@@ -711,7 +711,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(OrderbyClause oc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
 
         OrderOperator ord = new OrderOperator();
         Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
@@ -736,7 +736,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(QuantifiedExpression qe, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> topOp = tupSource;
 
         ILogicalOperator firstOp = null;
@@ -790,13 +790,13 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(Query q, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         return q.getBody().accept(this, tupSource);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(RecordConstructor rc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
                 FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
         LogicalVariable v1 = context.newVar();
@@ -816,7 +816,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(ListConstructor lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR)
                 ? BuiltinFunctions.ORDERED_LIST_CONSTRUCTOR : BuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
         AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(fid));
@@ -834,7 +834,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(UnaryExpr u, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Expression expr = u.getExpr();
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, tupSource);
         LogicalVariable v1 = context.newVar();
@@ -864,7 +864,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(WhereClause w, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(w.getWhereExpr(), tupSource);
         SelectOperator s = new SelectOperator(new MutableObject<ILogicalExpression>(p.first), false, null);
         s.getInputs().add(p.second);
@@ -874,7 +874,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(LimitClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getLimitExpr(), tupSource);
         LimitOperator opLim;
         Expression offset = lc.getOffset();
@@ -891,7 +891,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(DistinctClause dc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
         Mutable<ILogicalOperator> input = null;
         for (Expression expr : dc.getDistinctByExpr()) {
@@ -906,7 +906,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(UnionExpr unionExpr, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> ts = tupSource;
         ILogicalOperator lastOp = null;
         LogicalVariable lastVar = null;
@@ -989,7 +989,7 @@
     }
 
     private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(OperatorType t)
-            throws AsterixException {
+            throws CompilationException {
 
         FunctionIdentifier fid = null;
         switch (t) {
@@ -1050,7 +1050,7 @@
     }
 
     private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(Expression expr,
-            Mutable<ILogicalOperator> topOp) throws AsterixException {
+            Mutable<ILogicalOperator> topOp) throws CompilationException {
         switch (expr.getKind()) {
             case VARIABLE_EXPRESSION: {
                 VariableReferenceExpression ve =
@@ -1134,7 +1134,7 @@
     }
 
     private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(OperatorExpr op,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupSource) throws CompilationException {
         List<OperatorType> ops = op.getOpList();
         int nOps = ops.size();
 
@@ -1182,76 +1182,76 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(TypeDecl td, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(RecordTypeDefinition tre, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(TypeReferenceExpression tre, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(LoadStatement stmtLoad, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(DropDatasetStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CreateIndexStatement cis, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(OrderedListTypeDefinition olte, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(UnorderedListTypeDefinition ulte,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
+            Mutable<ILogicalOperator> arg) throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableClause(MetaVariableClause mc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupSource) throws CompilationException {
         return new Pair<ILogicalOperator, LogicalVariable>(metaScopeOp.get(mc.getVar()), null);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visitJoinClause(JoinClause jc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         // Pair<ILogicalOperator, LogicalVariable> leftSide =
         // jc.getLeftExpr().accept(this, tupSource);
         Mutable<ILogicalOperator> opRef = tupSource;
@@ -1294,7 +1294,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableExpr(MetaVariableExpr me,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupSource) throws CompilationException {
         LogicalVariable var = context.newVar();
         AssignOperator a = new AssignOperator(var,
                 new MutableObject<ILogicalExpression>(metaScopeExp.getVariableReferenceExpression(me.getVar())));
@@ -1335,161 +1335,161 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(InsertStatement insert, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(DeleteStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(UpdateStatement update, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(UpdateClause del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(DataverseDecl dv, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(DatasetDecl dd, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(SetStatement ss, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(WriteStatement ws, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CreateDataverseStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(IndexDropStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(NodeGroupDropStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(DataverseDropStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(TypeDropStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(DisconnectFeedStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FunctionDropStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(ConnectFeedStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FeedDropStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CompactStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CreatePrimaryFeedStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CreateSecondaryFeedStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
+            Mutable<ILogicalOperator> arg) throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CreateFeedPolicyStatement cfps, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FeedPolicyDropStatement dfs, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         // TODO Auto-generated method stub
         return null;
     }
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index cf722cc..dc1cb65 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -32,9 +32,9 @@
 
 import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
 import org.apache.asterix.algebra.operators.CommitOperator;
-import org.apache.asterix.common.config.MetadataProperties;
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.config.MetadataProperties;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.external.util.ExternalDataUtils;
@@ -71,7 +71,6 @@
 import org.apache.asterix.lang.common.struct.QuantifiedPair;
 import org.apache.asterix.lang.common.util.FunctionUtil;
 import org.apache.asterix.lang.common.visitor.base.AbstractQueryExpressionVisitor;
-import org.apache.asterix.lang.sqlpp.clause.Projection;
 import org.apache.asterix.metadata.MetadataException;
 import org.apache.asterix.metadata.MetadataManager;
 import org.apache.asterix.metadata.declared.DataSource;
@@ -732,7 +731,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(LetClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         LogicalVariable v;
         ILogicalOperator returnedOp;
         if (lc.getBindingExpr().getKind() == Kind.VARIABLE_EXPRESSION) {
@@ -752,7 +751,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FieldAccessor fa, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(fa.getExpr(), tupSource);
         LogicalVariable v = context.newVar();
         AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
@@ -768,7 +767,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(IndexAccessor ia, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(ia.getExpr(), tupSource);
         LogicalVariable v = context.newVar();
         AbstractFunctionCallExpression f;
@@ -790,7 +789,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CallExpr fcall, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         LogicalVariable v = context.newVar();
         FunctionSignature signature = fcall.getFunctionSignature();
         List<Mutable<ILogicalExpression>> args = new ArrayList<>();
@@ -824,7 +823,7 @@
         }
 
         if (f == null) {
-            throw new AsterixException(" Unknown function " + signature.getName() + "@" + signature.getArity());
+            throw new CompilationException(" Unknown function " + signature.getName() + "@" + signature.getArity());
         }
 
         // Put hints into function call expr.
@@ -902,7 +901,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(GroupbyClause gc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> topOp = tupSource;
         if (gc.hasGroupVar()) {
             List<Pair<Expression, Identifier>> groupFieldList = gc.getGroupFieldList();
@@ -966,7 +965,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(IfExpr ifexpr, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         // In the most general case, IfThenElse is translated in the following
         // way.
         //
@@ -1031,7 +1030,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(OperatorExpr op, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         List<OperatorType> ops = op.getOpList();
         int nOps = ops.size();
 
@@ -1113,7 +1112,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(OrderbyClause oc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         OrderOperator ord = new OrderOperator();
         Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
         Mutable<ILogicalOperator> topOp = tupSource;
@@ -1142,7 +1141,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(QuantifiedExpression qe, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> topOp = tupSource;
 
         ILogicalOperator firstOp = null;
@@ -1195,13 +1194,13 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(Query q, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         return q.getBody().accept(this, tupSource);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(RecordConstructor rc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
                 FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
         LogicalVariable v1 = context.newVar();
@@ -1221,7 +1220,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(ListConstructor lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         FunctionIdentifier fid = (lc.getType() == ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR)
                 ? BuiltinFunctions.ORDERED_LIST_CONSTRUCTOR : BuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
         AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(fid));
@@ -1239,7 +1238,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(UnaryExpr u, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Expression expr = u.getExpr();
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(expr, tupSource);
         LogicalVariable v1 = context.newVar();
@@ -1261,7 +1260,7 @@
                 a = processExists(eo.first, v1, true);
                 break;
             default:
-                throw new AsterixException("Unsupported operator: " + u);
+                throw new CompilationException("Unsupported operator: " + u);
         }
         a.getInputs().add(eo.second);
         return new Pair<>(a, v1);
@@ -1279,7 +1278,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(WhereClause w, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(w.getWhereExpr(), tupSource);
         SelectOperator s = new SelectOperator(new MutableObject<>(p.first), false, null);
         s.getInputs().add(p.second);
@@ -1288,7 +1287,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(LimitClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = langExprToAlgExpression(lc.getLimitExpr(), tupSource);
         LimitOperator opLim;
         Expression offset = lc.getOffset();
@@ -1329,7 +1328,7 @@
     }
 
     protected AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(OperatorType t)
-            throws AsterixException {
+            throws CompilationException {
         FunctionIdentifier fid;
         switch (t) {
             case PLUS:
@@ -1377,7 +1376,7 @@
     }
 
     protected Pair<ILogicalExpression, Mutable<ILogicalOperator>> langExprToAlgExpression(Expression expr,
-            Mutable<ILogicalOperator> topOpRef) throws AsterixException {
+            Mutable<ILogicalOperator> topOpRef) throws CompilationException {
         switch (expr.getKind()) {
             case VARIABLE_EXPRESSION:
                 VariableReferenceExpression ve = new VariableReferenceExpression(
@@ -1438,7 +1437,7 @@
     }
 
     protected Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(OperatorExpr op,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupSource) throws CompilationException {
         List<OperatorType> ops = op.getOpList();
         int nOps = ops.size();
 
@@ -1527,9 +1526,9 @@
      *
      * @param plan,
      *            the query plan.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    private void eliminateSharedOperatorReferenceForPlan(ILogicalPlan plan) throws AsterixException {
+    private void eliminateSharedOperatorReferenceForPlan(ILogicalPlan plan) throws CompilationException {
         for (Mutable<ILogicalOperator> opRef : plan.getRoots()) {
             Set<Mutable<ILogicalOperator>> opRefSet = new HashSet<>();
             eliminateSharedOperatorReference(opRef, opRefSet);
@@ -1546,10 +1545,11 @@
      *            the set storing seen operator references so far.
      * @return a mapping that maps old variables to new variables, for the ancestors of
      *         <code>currentOpRef</code> to replace variables properly.
-     * @throws AsterixException
+     * @throws CompilationException
      */
     private LinkedHashMap<LogicalVariable, LogicalVariable> eliminateSharedOperatorReference(
-            Mutable<ILogicalOperator> currentOpRef, Set<Mutable<ILogicalOperator>> opRefSet) throws AsterixException {
+            Mutable<ILogicalOperator> currentOpRef, Set<Mutable<ILogicalOperator>> opRefSet)
+            throws CompilationException {
         try {
             opRefSet.add(currentOpRef);
             AbstractLogicalOperator currentOperator = (AbstractLogicalOperator) currentOpRef.getValue();
@@ -1614,7 +1614,7 @@
             varMap.values().retainAll(liveVars);
             return varMap;
         } catch (AlgebricksException e) {
-            throw new AsterixException(e);
+            throw new CompilationException(e);
         }
     }
 
@@ -1628,10 +1628,10 @@
      * @param branchExpression,
      *            the expression to be evaluated in this branch.
      * @return a pair of the constructed subplan operator and the output variable for the branch.
-     * @throws AsterixException
+     * @throws CompilationException
      */
     protected Pair<ILogicalOperator, LogicalVariable> constructSubplanOperatorForBranch(ILogicalOperator inputOp,
-            Mutable<ILogicalExpression> selectExpr, Expression branchExpression) throws AsterixException {
+            Mutable<ILogicalExpression> selectExpr, Expression branchExpression) throws CompilationException {
         context.enterSubplan();
         SubplanOperator subplanOp = new SubplanOperator();
         subplanOp.getInputs().add(new MutableObject<>(inputOp));
@@ -1699,7 +1699,7 @@
 
     // Generates the plan for "UNION ALL" or union expression from its input expressions.
     protected Pair<ILogicalOperator, LogicalVariable> translateUnionAllFromInputExprs(List<ILangExpression> inputExprs,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupSource) throws CompilationException {
         List<Mutable<ILogicalOperator>> inputOpRefsToUnion = new ArrayList<>();
         List<LogicalVariable> vars = new ArrayList<>();
         for (ILangExpression expr : inputExprs) {
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
index 5778369..f46613b 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SqlppExpressionToPlanTranslator.java
@@ -25,7 +25,7 @@
 import java.util.List;
 
 import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause.ClauseType;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Expression.Kind;
@@ -120,7 +120,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(Query q, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Expression queryBody = q.getBody();
         if (queryBody.getKind() == Kind.SELECT_EXPRESSION) {
             SelectExpression selectExpr = (SelectExpression) queryBody;
@@ -141,7 +141,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(SelectExpression selectExpression,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupSource) throws CompilationException {
         if (selectExpression.isSubquery()) {
             context.enterSubplan();
         }
@@ -170,7 +170,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(IndependentSubquery independentSubquery,
-            Mutable<ILogicalOperator> tupleSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupleSource) throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo =
                 langExprToAlgExpression(independentSubquery.getExpr(), tupleSource);
         LogicalVariable var = context.newVar();
@@ -181,7 +181,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(SelectSetOperation selectSetOperation,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupSource) throws CompilationException {
         SetOperationInput leftInput = selectSetOperation.getLeftInput();
         if (!selectSetOperation.hasRightInputs()) {
             return leftInput.accept(this, tupSource);
@@ -193,7 +193,7 @@
         for (SetOperationRight setOperationRight : selectSetOperation.getRightInputs()) {
             SetOpType setOpType = setOperationRight.getSetOpType();
             if (setOpType != SetOpType.UNION || setOperationRight.isSetSemantics()) {
-                throw new AsterixException("Operation " + setOpType
+                throw new CompilationException("Operation " + setOpType
                         + (setOperationRight.isSetSemantics() ? " with set semantics" : "ALL") + " is not supported.");
             }
             SetOperationInput rightInput = setOperationRight.getSetOperationRightInput();
@@ -206,7 +206,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(SelectBlock selectBlock, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> currentOpRef = tupSource;
         if (selectBlock.hasFromClause()) {
             currentOpRef = new MutableObject<>(selectBlock.getFromClause().accept(this, currentOpRef).first);
@@ -235,7 +235,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FromClause fromClause, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> inputSrc = arg;
         Pair<ILogicalOperator, LogicalVariable> topUnnest = null;
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
@@ -247,7 +247,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(FromTerm fromTerm, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         LogicalVariable fromVar = context.newVar(fromTerm.getLeftVariable());
         Expression fromExpr = fromTerm.getLeftExpression();
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(fromExpr, tupSource);
@@ -283,7 +283,7 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(JoinClause joinClause, Mutable<ILogicalOperator> inputRef)
-            throws AsterixException {
+            throws CompilationException {
         Mutable<ILogicalOperator> leftInputRef = uncorrelatedLeftBranchStack.pop();
         if (joinClause.getJoinType() == JoinType.INNER) {
             Pair<ILogicalOperator, LogicalVariable> rightBranch =
@@ -424,20 +424,20 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(NestClause nestClause, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         throw new NotImplementedException("Nest clause has not been implemented");
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(UnnestClause unnestClause,
-            Mutable<ILogicalOperator> inputOpRef) throws AsterixException {
+            Mutable<ILogicalOperator> inputOpRef) throws CompilationException {
         return generateUnnestForBinaryCorrelateRightBranch(unnestClause, inputOpRef,
                 unnestClause.getJoinType() == JoinType.INNER);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(HavingClause havingClause, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
+            throws CompilationException {
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p =
                 langExprToAlgExpression(havingClause.getFilterExpression(), tupSource);
         SelectOperator s = new SelectOperator(new MutableObject<ILogicalExpression>(p.first), false, null);
@@ -447,7 +447,7 @@
 
     private Pair<ILogicalOperator, LogicalVariable> generateUnnestForBinaryCorrelateRightBranch(
             AbstractBinaryCorrelateClause binaryCorrelate, Mutable<ILogicalOperator> inputOpRef, boolean innerUnnest)
-            throws AsterixException {
+            throws CompilationException {
         LogicalVariable rightVar = context.newVar(binaryCorrelate.getRightVariable());
         Expression rightExpr = binaryCorrelate.getRightExpression();
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(rightExpr, inputOpRef);
@@ -470,31 +470,31 @@
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(SelectClause selectClause, Mutable<ILogicalOperator> tupSrc)
-            throws AsterixException {
+            throws CompilationException {
         throw new UnsupportedOperationException(ERR_MSG);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(SelectElement selectElement, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         throw new UnsupportedOperationException(ERR_MSG);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(SelectRegular selectRegular, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         throw new UnsupportedOperationException(ERR_MSG);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(Projection projection, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
+            throws CompilationException {
         throw new UnsupportedOperationException(ERR_MSG);
     }
 
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visit(CaseExpression caseExpression,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+            Mutable<ILogicalOperator> tupSource) throws CompilationException {
         //Creates a series of subplan operators, one for each branch.
         Mutable<ILogicalOperator> currentOpRef = tupSource;
         ILogicalOperator currentOperator = null;
@@ -597,7 +597,7 @@
 
     // Generates the return expression for a select clause.
     private Pair<ILogicalOperator, LogicalVariable> processSelectClause(SelectBlock selectBlock,
-            Mutable<ILogicalOperator> tupSrc) throws AsterixException {
+            Mutable<ILogicalOperator> tupSrc) throws CompilationException {
         SelectClause selectClause = selectBlock.getSelectClause();
         Expression returnExpr;
         if (selectClause.selectElement()) {
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java
index 53b78bb..0660f23 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TranslationException.java
@@ -18,9 +18,9 @@
  */
 package org.apache.asterix.translator;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 
-public class TranslationException extends AsterixException {
+public class TranslationException extends CompilationException {
     private static final long serialVersionUID = 685960054131778068L;
 
     public TranslationException(String msg) {
diff --git a/asterixdb/asterix-algebra/src/main/javacc/AQLPlus.jj b/asterixdb/asterix-algebra/src/main/javacc/AQLPlus.jj
index 2c991cb..b44e1bc 100644
--- a/asterixdb/asterix-algebra/src/main/javacc/AQLPlus.jj
+++ b/asterixdb/asterix-algebra/src/main/javacc/AQLPlus.jj
@@ -41,7 +41,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
@@ -138,7 +138,7 @@
        return s.substring(1).trim();
     }
 
-    public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
+    public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException {
             File file = new File(args[0]);
             Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
             AQLPlusParser parser = new AQLPlusParser(fis);
@@ -703,7 +703,7 @@
         Token t = getToken(0);
         try{
           op.addOperator(t.toString());
-        } catch (AsterixException e){
+        } catch (CompilationException e){
           throw new ParseException(e.getMessage());
         }
     }
@@ -750,7 +750,7 @@
           uexpr = new UnaryExpr();
           try{
             uexpr.setExprType(token.image);
-          } catch (AsterixException e){
+          } catch (CompilationException e){
             throw new ParseException(e.getMessage());
           }
     }
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
index 754b7f9..4140f9a 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
@@ -29,7 +29,6 @@
 import java.util.Random;
 import java.util.Set;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
 import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory;
 import org.apache.asterix.api.common.Job.SubmissionMode;
@@ -38,7 +37,7 @@
 import org.apache.asterix.common.config.ExternalProperties;
 import org.apache.asterix.common.config.OptimizationConfUtil;
 import org.apache.asterix.common.exceptions.ACIDException;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.compiler.provider.IRuleSetFactory;
 import org.apache.asterix.dataflow.data.common.ConflictingTypeResolver;
@@ -50,9 +49,9 @@
 import org.apache.asterix.jobgen.QueryLogicalExpressionJobGen;
 import org.apache.asterix.lang.common.base.IAstPrintVisitorFactory;
 import org.apache.asterix.lang.common.base.IQueryRewriter;
+import org.apache.asterix.lang.common.base.IReturningStatement;
 import org.apache.asterix.lang.common.base.IRewriterFactory;
 import org.apache.asterix.lang.common.base.Statement;
-import org.apache.asterix.lang.common.base.IReturningStatement;
 import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
 import org.apache.asterix.lang.common.statement.FunctionDecl;
 import org.apache.asterix.lang.common.statement.Query;
@@ -91,6 +90,8 @@
 import org.apache.hyracks.api.job.JobId;
 import org.apache.hyracks.api.job.JobSpecification;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+
 /**
  * Provides helper methods for compilation of a query into a JobSpec and submission
  * to Hyracks through the Hyracks client interface.
@@ -145,7 +146,7 @@
     }
 
     public Pair<IReturningStatement, Integer> reWriteQuery(List<FunctionDecl> declaredFunctions,
-            MetadataProvider metadataProvider, IReturningStatement q, SessionConfig conf) throws AsterixException {
+            MetadataProvider metadataProvider, IReturningStatement q, SessionConfig conf) throws CompilationException {
         if (q == null) {
             return null;
         }
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 593adb2..f039271 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -40,7 +40,6 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.asterix.active.ActiveJobNotificationHandler;
 import org.apache.asterix.active.ActivityState;
 import org.apache.asterix.active.EntityId;
@@ -55,22 +54,22 @@
 import org.apache.asterix.app.result.ResultReader;
 import org.apache.asterix.app.result.ResultUtil;
 import org.apache.asterix.common.config.ClusterProperties;
-import org.apache.asterix.common.config.ExternalProperties;
-import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
 import org.apache.asterix.common.config.DatasetConfig.ExternalDatasetTransactionState;
 import org.apache.asterix.common.config.DatasetConfig.ExternalFilePendingOp;
 import org.apache.asterix.common.config.DatasetConfig.IndexType;
+import org.apache.asterix.common.config.ExternalProperties;
+import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.exceptions.ACIDException;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.external.api.IAdapterFactory;
 import org.apache.asterix.external.feed.api.IActiveLifecycleEventSubscriber;
 import org.apache.asterix.external.feed.api.IActiveLifecycleEventSubscriber.ActiveLifecycleEvent;
 import org.apache.asterix.external.feed.api.IFeed;
-import org.apache.asterix.external.feed.api.IFeedJoint;
 import org.apache.asterix.external.feed.api.IFeed.FeedType;
+import org.apache.asterix.external.feed.api.IFeedJoint;
 import org.apache.asterix.external.feed.api.IFeedJoint.FeedJointType;
 import org.apache.asterix.external.feed.management.ActiveLifecycleEventSubscriber;
 import org.apache.asterix.external.feed.management.FeedConnectionId;
@@ -88,10 +87,10 @@
 import org.apache.asterix.file.IndexOperations;
 import org.apache.asterix.formats.nontagged.TypeTraitProvider;
 import org.apache.asterix.lang.aql.statement.SubscribeFeedStatement;
+import org.apache.asterix.lang.common.base.IReturningStatement;
 import org.apache.asterix.lang.common.base.IRewriterFactory;
 import org.apache.asterix.lang.common.base.IStatementRewriter;
 import org.apache.asterix.lang.common.base.Statement;
-import org.apache.asterix.lang.common.base.IReturningStatement;
 import org.apache.asterix.lang.common.expression.TypeExpression;
 import org.apache.asterix.lang.common.statement.CompactStatement;
 import org.apache.asterix.lang.common.statement.ConnectFeedStatement;
@@ -206,9 +205,6 @@
 import org.apache.hyracks.api.job.JobId;
 import org.apache.hyracks.api.job.JobSpecification;
 import org.apache.hyracks.storage.am.lsm.common.api.ILSMMergePolicyFactory;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
 
 import com.google.common.collect.Lists;
 
@@ -405,7 +401,7 @@
                                 resultSetIdCounter);
                         break;
                     default:
-                        throw new AsterixException("Unknown function");
+                        throw new CompilationException("Unknown function");
                 }
             }
         } finally {
@@ -485,38 +481,38 @@
     }
 
     protected void validateCompactionPolicy(String compactionPolicy, Map<String, String> compactionPolicyProperties,
-            MetadataTransactionContext mdTxnCtx, boolean isExternalDataset) throws AsterixException, Exception {
+            MetadataTransactionContext mdTxnCtx, boolean isExternalDataset) throws CompilationException, Exception {
         CompactionPolicy compactionPolicyEntity = MetadataManager.INSTANCE.getCompactionPolicy(mdTxnCtx,
                 MetadataConstants.METADATA_DATAVERSE_NAME, compactionPolicy);
         if (compactionPolicyEntity == null) {
-            throw new AsterixException("Unknown compaction policy: " + compactionPolicy);
+            throw new CompilationException("Unknown compaction policy: " + compactionPolicy);
         }
         String compactionPolicyFactoryClassName = compactionPolicyEntity.getClassName();
         ILSMMergePolicyFactory mergePolicyFactory = (ILSMMergePolicyFactory) Class
                 .forName(compactionPolicyFactoryClassName).newInstance();
         if (isExternalDataset && mergePolicyFactory.getName().compareTo("correlated-prefix") == 0) {
-            throw new AsterixException("The correlated-prefix merge policy cannot be used with external dataset.");
+            throw new CompilationException("The correlated-prefix merge policy cannot be used with external dataset.");
         }
         if (compactionPolicyProperties == null) {
             if (mergePolicyFactory.getName().compareTo("no-merge") != 0) {
-                throw new AsterixException("Compaction policy properties are missing.");
+                throw new CompilationException("Compaction policy properties are missing.");
             }
         } else {
             for (Map.Entry<String, String> entry : compactionPolicyProperties.entrySet()) {
                 if (!mergePolicyFactory.getPropertiesNames().contains(entry.getKey())) {
-                    throw new AsterixException("Invalid compaction policy property: " + entry.getKey());
+                    throw new CompilationException("Invalid compaction policy property: " + entry.getKey());
                 }
             }
             for (String p : mergePolicyFactory.getPropertiesNames()) {
                 if (!compactionPolicyProperties.containsKey(p)) {
-                    throw new AsterixException("Missing compaction policy property: " + p);
+                    throw new CompilationException("Missing compaction policy property: " + p);
                 }
             }
         }
     }
 
     public void handleCreateDatasetStatement(MetadataProvider metadataProvider, Statement stmt,
-            IHyracksClientConnection hcc) throws AsterixException, Exception {
+            IHyracksClientConnection hcc) throws CompilationException, Exception {
         MutableObject<ProgressState> progress = new MutableObject<>(ProgressState.NO_PROGRESS);
         DatasetDecl dd = (DatasetDecl) stmt;
         String dataverseName = getActiveDataverse(dd.getDataverse());
@@ -617,7 +613,7 @@
                             ExternalDatasetTransactionState.COMMIT);
                     break;
                 default:
-                    throw new AsterixException("Unknown datatype " + dd.getDatasetType());
+                    throw new CompilationException("Unknown datatype " + dd.getDatasetType());
             }
 
             // #. initialize DatasetIdFactory if it is not initialized.
@@ -709,7 +705,8 @@
         }
     }
 
-    protected void validateIfResourceIsActiveInFeed(String dataverseName, String datasetName) throws AsterixException {
+    protected void validateIfResourceIsActiveInFeed(String dataverseName, String datasetName)
+            throws CompilationException {
         StringBuilder builder = null;
         IActiveEntityEventsListener[] listeners = ActiveJobNotificationHandler.INSTANCE.getEventListeners();
         for (IActiveEntityEventsListener listener : listeners) {
@@ -721,7 +718,7 @@
             }
         }
         if (builder != null) {
-            throw new AsterixException("Dataset " + dataverseName + "." + datasetName + " is currently being "
+            throw new CompilationException("Dataset " + dataverseName + "." + datasetName + " is currently being "
                     + "fed into by the following active entities.\n" + builder.toString());
         }
     }
@@ -739,7 +736,7 @@
     }
 
     protected String configureNodegroupForDataset(DatasetDecl dd, String dataverse, MetadataTransactionContext mdTxnCtx)
-            throws AsterixException {
+            throws CompilationException {
         int nodegroupCardinality;
         String nodegroupName;
         String hintValue = dd.getHints().get(DatasetNodegroupCardinalityHint.NAME);
@@ -751,7 +748,7 @@
             boolean valid = DatasetHints.validate(DatasetNodegroupCardinalityHint.NAME,
                     dd.getHints().get(DatasetNodegroupCardinalityHint.NAME)).first;
             if (!valid) {
-                throw new AsterixException("Incorrect use of hint:" + DatasetNodegroupCardinalityHint.NAME);
+                throw new CompilationException("Incorrect use of hint:" + DatasetNodegroupCardinalityHint.NAME);
             } else {
                 nodegroupCardinality = Integer.parseInt(dd.getHints().get(DatasetNodegroupCardinalityHint.NAME));
             }
@@ -961,7 +958,7 @@
                     spec = ExternalIndexingOperations.buildFilesIndexReplicationJobSpec(ds, externalFilesSnapshot,
                             metadataProvider, true);
                     if (spec == null) {
-                        throw new AsterixException(
+                        throw new CompilationException(
                                 "Failed to create job spec for replicating Files Index For external dataset");
                     }
                     filesIndexReplicated = true;
@@ -976,7 +973,7 @@
                 for (Index index : indexes) {
                     if (index.getKeyFieldNames().equals(indexFields)
                             && !index.getKeyFieldTypes().equals(indexFieldTypes) && index.isEnforcingKeyFileds()) {
-                        throw new AsterixException("Cannot create index " + indexName + " , enforced index "
+                        throw new CompilationException("Cannot create index " + indexName + " , enforced index "
                                 + index.getIndexName() + " on field \"" + StringUtils.join(indexFields, ',')
                                 + "\" is already defined with type \"" + index.getKeyFieldTypes() + "\"");
                     }
@@ -1001,7 +998,7 @@
             spec = IndexOperations.buildSecondaryIndexCreationJobSpec(cis, aRecordType, metaRecordType,
                     keySourceIndicators, enforcedType, metadataProvider);
             if (spec == null) {
-                throw new AsterixException("Failed to create job spec for creating index '"
+                throw new CompilationException("Failed to create job spec for creating index '"
                         + stmtCreateIndex.getDatasetName() + "." + stmtCreateIndex.getIndexName() + "'");
             }
             MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
@@ -1431,7 +1428,7 @@
             IActiveEntityEventsListener[] activeListeners = ActiveJobNotificationHandler.INSTANCE.getEventListeners();
             for (IActiveEntityEventsListener listener : activeListeners) {
                 if (listener.isEntityUsingDataset(dataverseName, datasetName)) {
-                    throw new AsterixException(
+                    throw new CompilationException(
                             "Can't drop dataset since it is connected to active entity: " + listener.getEntityId());
                 }
             }
@@ -1560,7 +1557,7 @@
                 }
             }
             if (builder != null) {
-                throw new AsterixException("Dataset" + datasetName
+                throw new CompilationException("Dataset" + datasetName
                         + " is currently being fed into by the following active entities: " + builder.toString());
             }
 
@@ -2195,7 +2192,7 @@
                 subscriberRegistered = listener.isFeedConnectionActive(feedConnId, eventSubscriber);
             }
             if (subscriberRegistered) {
-                throw new AsterixException("Feed " + cfs.getFeedName() + " is already connected to dataset "
+                throw new CompilationException("Feed " + cfs.getFeedName() + " is already connected to dataset "
                         + cfs.getDatasetName().getValue());
             }
             FeedPolicyEntity feedPolicy = FeedMetadataUtil.validateIfPolicyExists(dataverseName, cbfs.getPolicyName(),
@@ -2264,11 +2261,11 @@
      * @param feedPolicy
      * @param mdTxnCtx
      * @return
-     * @throws AsterixException
+     * @throws CompilationException
      */
     protected Triple<FeedConnectionRequest, Boolean, List<IFeedJoint>> getFeedConnectionRequest(String dataverse,
             Feed feed, String dataset, FeedPolicyEntity feedPolicy, MetadataTransactionContext mdTxnCtx)
-            throws AsterixException {
+            throws CompilationException {
         IFeedJoint sourceFeedJoint;
         FeedConnectionRequest request;
         List<String> functionsToApply = new ArrayList<>();
@@ -2281,7 +2278,7 @@
         FeedEventsListener listener = (FeedEventsListener) ActiveJobNotificationHandler.INSTANCE
                 .getActiveEntityListener(entityId);
         if (listener == null) {
-            throw new AsterixException("Feed Listener is not registered");
+            throw new CompilationException("Feed Listener is not registered");
         }
 
         boolean isFeedJointAvailable = listener.isFeedJointAvailable(feedJointKey);
@@ -2370,7 +2367,8 @@
         FeedEventsListener listener = (FeedEventsListener) ActiveJobNotificationHandler.INSTANCE
                 .getActiveEntityListener(entityId);
         if (listener == null || !listener.isEntityUsingDataset(dataverseName, datasetName)) {
-            throw new AsterixException("Feed " + feed.getFeedId().getEntityName() + " is currently not connected to "
+            throw new CompilationException(
+                    "Feed " + feed.getFeedId().getEntityName() + " is currently not connected to "
                     + cfs.getDatasetName().getValue() + ". Invalid operation!");
         }
         listener.registerFeedEventSubscriber(eventSubscriber);
@@ -2380,7 +2378,7 @@
             Dataset dataset = MetadataManager.INSTANCE.getDataset(metadataProvider.getMetadataTxnContext(),
                     dataverseName, cfs.getDatasetName().getValue());
             if (dataset == null) {
-                throw new AsterixException(
+                throw new CompilationException(
                         "Unknown dataset :" + cfs.getDatasetName().getValue() + " in dataverse " + dataverseName);
             }
             Pair<JobSpecification, Boolean> specDisconnectType = FeedOperations
@@ -2879,7 +2877,7 @@
     }
 
     protected void handleRunStatement(MetadataProvider metadataProvider, Statement stmt,
-            IHyracksClientConnection hcc) throws AsterixException, Exception {
+            IHyracksClientConnection hcc) throws CompilationException, Exception {
         RunStatement runStmt = (RunStatement) stmt;
         switch (runStmt.getSystem()) {
             case "pregel":
@@ -2966,12 +2964,13 @@
         // Validates the source/sink dataverses and datasets.
         Dataset fromDataset = metadataProvider.findDataset(dataverseNameFrom, datasetNameFrom);
         if (fromDataset == null) {
-            throw new AsterixException("The source dataset " + datasetNameFrom + " in dataverse " + dataverseNameFrom
+            throw new CompilationException(
+                    "The source dataset " + datasetNameFrom + " in dataverse " + dataverseNameFrom
                     + " could not be found for the Run command");
         }
         Dataset toDataset = metadataProvider.findDataset(dataverseNameTo, datasetNameTo);
         if (toDataset == null) {
-            throw new AsterixException("The sink dataset " + datasetNameTo + " in dataverse " + dataverseNameTo
+            throw new CompilationException("The sink dataset " + datasetNameTo + " in dataverse " + dataverseNameTo
                     + " could not be found for the Run command");
         }
 
@@ -3137,7 +3136,7 @@
         }
     }
 
-    protected void rewriteStatement(Statement stmt) throws AsterixException {
+    protected void rewriteStatement(Statement stmt) throws CompilationException {
         IStatementRewriter rewriter = rewriterFactory.createStatementRewriter();
         rewriter.rewrite(stmt);
     }
diff --git a/asterixdb/asterix-app/src/test/resources/metadata/testsuite.xml b/asterixdb/asterix-app/src/test/resources/metadata/testsuite.xml
index 298c458..a3864e4 100644
--- a/asterixdb/asterix-app/src/test/resources/metadata/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/metadata/testsuite.xml
@@ -336,7 +336,7 @@
     <test-case FilePath="basic">
       <compilation-unit name="issue_1419_drop_type_with_collection_2">
         <output-dir compare="Text">none</output-dir>
-        <expected-error>Error: Cannot drop type test.subType being used by type test.superType_superlist</expected-error>
+        <expected-error>Cannot drop type test.subType being used by type test.superType_superlist</expected-error>
       </compilation-unit>
     </test-case>
   </test-group>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index 2ee3a2c..ab55c89 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -3438,13 +3438,13 @@
       <test-case FilePath="open-index-enforced/error-checking">
         <compilation-unit name="index-type-collision">
           <output-dir compare="Text">index-type-collision</output-dir>
-          <expected-error>org.apache.asterix.common.exceptions.AsterixException: Cannot create index testIdx2 , enforced index testIdx1 on field "[value]" is already defined with type "[int32]"</expected-error>
+          <expected-error>Cannot create index testIdx2 , enforced index testIdx1 on field "[value]" is already defined with type "[int32]"</expected-error>
         </compilation-unit>
       </test-case>
       <test-case FilePath="open-index-enforced/error-checking">
         <compilation-unit name="index-type-promotion-collision">
           <output-dir compare="Text">index-type-promotion-collision</output-dir>
-          <expected-error>org.apache.asterix.common.exceptions.AsterixException: Cannot create index testIdx2 , enforced index testIdx1 on field "[value]" is already defined with type "[int64]"</expected-error>
+          <expected-error>Cannot create index testIdx2 , enforced index testIdx1 on field "[value]" is already defined with type "[int64]"</expected-error>
         </compilation-unit>
       </test-case>
       <test-case FilePath="open-index-enforced/error-checking">
@@ -6298,7 +6298,7 @@
     <test-case FilePath="cross-dataverse">
       <compilation-unit name="cross-dv13">
         <output-dir compare="Text">cross-dv13</output-dir>
-        <expected-error>Error: Recursive invocation testdv2.fun03@0</expected-error>
+        <expected-error>Recursive invocation testdv2.fun03@0</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="cross-dataverse">
@@ -6314,7 +6314,7 @@
     <test-case FilePath="cross-dataverse">
       <compilation-unit name="cross-dv16">
         <output-dir compare="Text">cross-dv16</output-dir>
-        <expected-error>Error: Recursive invocation testdv1.fun04@0</expected-error>
+        <expected-error>Recursive invocation testdv1.fun04@0</expected-error>
       </compilation-unit>
     </test-case>
     <!--NotImplementedException: No binary comparator factory implemented for type RECORD.
@@ -6353,19 +6353,19 @@
     <test-case FilePath="cross-dataverse">
       <compilation-unit name="drop-type-used-elsewhere">
         <output-dir compare="Text">drop-type-used-elsewhere</output-dir>
-        <expected-error>Error: Cannot drop type a.a being used by dataset b.b1</expected-error>
+        <expected-error>Cannot drop type a.a being used by dataset b.b1</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="cross-dataverse">
       <compilation-unit name="drop-type-used-here-dataset">
         <output-dir compare="Text">drop-type-used-here-dataset</output-dir>
-        <expected-error>Error: Cannot drop type c.a being used by dataset c.a1</expected-error>
+        <expected-error>Cannot drop type c.a being used by dataset c.a1</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="cross-dataverse">
       <compilation-unit name="drop-type-used-here-type">
         <output-dir compare="Text">drop-type-used-here-type</output-dir>
-        <expected-error>Error: Cannot drop type c.a being used by type c.b</expected-error>
+        <expected-error>Cannot drop type c.a being used by type c.b</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="cross-dataverse">
@@ -6403,7 +6403,7 @@
     <test-case FilePath="user-defined-functions">
       <compilation-unit name="query-issue455">
         <output-dir compare="Text">query-issue455</output-dir>
-        <expected-error>Error: function test.printName@0 is not defined</expected-error>
+        <expected-error>function test.printName@0 is not defined</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="user-defined-functions">
@@ -6547,7 +6547,7 @@
     <test-case FilePath="user-defined-functions">
       <compilation-unit name="udf26"><!-- Error not propagated properly -->
         <output-dir compare="Text">udf26</output-dir>
-        <expected-error>Error: function test.needs_f1@1 depends upon function test.f1@0 which is undefined</expected-error>
+        <expected-error>function test.needs_f1@1 depends upon function test.f1@0 which is undefined</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="user-defined-functions"><!-- Exception is never thrown!! -->
@@ -6568,7 +6568,7 @@
     <test-case FilePath="user-defined-functions">
       <compilation-unit name="udf30">
         <output-dir compare="Text">udf30</output-dir>
-        <expected-error>Error: can't find variable $y</expected-error>
+        <expected-error>can't find variable $y</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="user-defined-functions">
@@ -6579,7 +6579,7 @@
     <test-case FilePath="user-defined-functions">
       <compilation-unit name="f01">
         <output-dir compare="Text">f01</output-dir>
-        <expected-error>Error: function test.int8@0 is not defined</expected-error>
+        <expected-error>function test.int8@0 is not defined</expected-error>
       </compilation-unit>
     </test-case>
     <test-case FilePath="user-defined-functions">
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
index cb931dc..b53eec4 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/CompilationException.java
@@ -24,6 +24,7 @@
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 
 public class CompilationException extends AlgebricksException {
+    private static final long serialVersionUID = 1L;
 
     public CompilationException(int errorCode, Serializable... params) {
         super(ErrorCode.ASTERIX, errorCode, ErrorCode.getErrorMessage(errorCode), params);
@@ -33,4 +34,35 @@
         super(ErrorCode.ASTERIX, errorCode, ErrorCode.getErrorMessage(errorCode), params);
         addSuppressed(cause);
     }
+
+    /**
+     * @deprecated (Don't use this and provide an error code. This exists for the current exceptions and
+     *             those exceptions need to adopt error code as well.)
+     * @param message
+     */
+    @Deprecated
+    public CompilationException(String message) {
+        super(message);
+    }
+
+    /**
+     * @deprecated (Don't use this and provide an error code. This exists for the current exceptions and
+     *             those exceptions need to adopt error code as well.)
+     * @param message
+     */
+    @Deprecated
+    public CompilationException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * @deprecated (Don't use this and provide an error code. This exists for the current exceptions and
+     *             those exceptions need to adopt error code as well.)
+     * @param message
+     */
+    @Deprecated
+    public CompilationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
 }
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/DistinctClause.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/DistinctClause.java
index 9ee86e2..bb4d346 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/DistinctClause.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/DistinctClause.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
@@ -48,7 +48,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((IAQLVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/ForClause.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/ForClause.java
index 39e7bbb..6cdc2f3 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/ForClause.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/ForClause.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.aql.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
@@ -69,7 +69,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((IAQLVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/JoinClause.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/JoinClause.java
index 558bd52..4767f4f 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/JoinClause.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/JoinClause.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.base.IAQLPlusVisitor;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
@@ -46,7 +46,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((IAQLPlusVisitor<R, T>) visitor).visitJoinClause(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/MetaVariableClause.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/MetaVariableClause.java
index a33699e..871c2ce 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/MetaVariableClause.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/MetaVariableClause.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.aql.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.base.IAQLPlusVisitor;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.struct.VarIdentifier;
@@ -28,7 +28,7 @@
     private VarIdentifier var;
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((IAQLPlusVisitor<R, T>) visitor).visitMetaVariableClause(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/FLWOGRExpression.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/FLWOGRExpression.java
index 0761396..10143f2 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/FLWOGRExpression.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/FLWOGRExpression.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Clause.ClauseType;
@@ -72,7 +72,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((IAQLVisitor<R, T>) visitor).visit(this, arg);
     }
 }
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/MetaVariableExpr.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/MetaVariableExpr.java
index 99c7902..2964eff 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/MetaVariableExpr.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/MetaVariableExpr.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.aql.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.base.IAQLPlusVisitor;
 import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -26,7 +26,7 @@
 public class MetaVariableExpr extends VariableExpr {
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((IAQLPlusVisitor<R, T>) visitor).visitMetaVariableExpr(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/UnionExpr.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/UnionExpr.java
index 2c8756b..133cb46 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/UnionExpr.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/UnionExpr.java
@@ -21,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -56,7 +56,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((IAQLVisitor<R, T>) visitor).visit(this, arg);
     }
 }
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/FunctionParser.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/FunctionParser.java
index 1f58d08..47a9580 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/FunctionParser.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/FunctionParser.java
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.IParserFactory;
 import org.apache.asterix.lang.common.base.Statement;
@@ -39,7 +39,7 @@
         this.parserFactory = parserFactory;
     }
 
-    public FunctionDecl getFunctionDecl(Function function) throws AsterixException {
+    public FunctionDecl getFunctionDecl(Function function) throws CompilationException {
         String functionBody = function.getFunctionBody();
         List<String> params = function.getParams();
         List<VarIdentifier> varIdentifiers = new ArrayList<VarIdentifier>();
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java
index d70f399..977f6bb 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java
@@ -22,7 +22,7 @@
 import java.util.List;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
@@ -31,14 +31,13 @@
 import org.apache.asterix.lang.aql.parser.AQLParserFactory;
 import org.apache.asterix.lang.aql.parser.FunctionParser;
 import org.apache.asterix.lang.aql.rewrites.visitor.AqlBuiltinFunctionRewriteVisitor;
-import org.apache.asterix.lang.common.base.IReturningStatement;
-import org.apache.asterix.lang.common.util.CommonFunctionMapUtil;
 import org.apache.asterix.lang.aql.visitor.AQLInlineUdfsVisitor;
 import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.base.IQueryRewriter;
 import org.apache.asterix.lang.common.base.Expression.Kind;
+import org.apache.asterix.lang.common.base.IQueryRewriter;
+import org.apache.asterix.lang.common.base.IReturningStatement;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
@@ -46,6 +45,7 @@
 import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
 import org.apache.asterix.lang.common.statement.FunctionDecl;
 import org.apache.asterix.lang.common.struct.VarIdentifier;
+import org.apache.asterix.lang.common.util.CommonFunctionMapUtil;
 import org.apache.asterix.lang.common.util.FunctionUtil;
 import org.apache.asterix.lang.common.visitor.GatherFunctionCallsVisitor;
 import org.apache.asterix.metadata.declared.MetadataProvider;
@@ -68,7 +68,7 @@
 
     @Override
     public void rewrite(List<FunctionDecl> declaredFunctions, IReturningStatement topStatement,
-            MetadataProvider metadataProvider, LangRewritingContext context) throws AsterixException {
+            MetadataProvider metadataProvider, LangRewritingContext context) throws CompilationException {
         setup(declaredFunctions, topStatement, metadataProvider, context);
         if (topStatement.isTopLevel()) {
             wrapInLets();
@@ -96,7 +96,7 @@
         }
     }
 
-    private void rewriteFunctionName() throws AsterixException {
+    private void rewriteFunctionName() throws CompilationException {
         if (topStatement == null) {
             return;
         }
@@ -104,7 +104,7 @@
         topStatement.accept(visitor, null);
     }
 
-    private void inlineDeclaredUdfs() throws AsterixException {
+    private void inlineDeclaredUdfs() throws CompilationException {
         if (topStatement == null) {
             return;
         }
@@ -130,7 +130,7 @@
         declaredFunctions.removeAll(storedFunctionDecls);
     }
 
-    private Set<FunctionSignature> getFunctionCalls(Expression expression) throws AsterixException {
+    private Set<FunctionSignature> getFunctionCalls(Expression expression) throws CompilationException {
         GatherFunctionCalls gfc = new GatherFunctionCalls();
         expression.accept(gfc, null);
         return gfc.getCalls();
@@ -142,7 +142,7 @@
         }
 
         @Override
-        public Void visit(DistinctClause dc, Void arg) throws AsterixException {
+        public Void visit(DistinctClause dc, Void arg) throws CompilationException {
             for (Expression e : dc.getDistinctByExpr()) {
                 e.accept(this, arg);
             }
@@ -150,7 +150,7 @@
         }
 
         @Override
-        public Void visit(FLWOGRExpression flwor, Void arg) throws AsterixException {
+        public Void visit(FLWOGRExpression flwor, Void arg) throws CompilationException {
             for (Clause c : flwor.getClauseList()) {
                 c.accept(this, arg);
             }
@@ -159,7 +159,7 @@
         }
 
         @Override
-        public Void visit(ForClause fc, Void arg) throws AsterixException {
+        public Void visit(ForClause fc, Void arg) throws CompilationException {
             fc.getInExpr().accept(this, arg);
             if (fc.getPosVarExpr() != null) {
                 fc.getPosVarExpr().accept(this, arg);
@@ -168,7 +168,7 @@
         }
 
         @Override
-        public Void visit(GroupbyClause gc, Void arg) throws AsterixException {
+        public Void visit(GroupbyClause gc, Void arg) throws CompilationException {
             for (GbyVariableExpressionPair p : gc.getGbyPairList()) {
                 p.getExpr().accept(this, arg);
             }
@@ -179,13 +179,13 @@
         }
 
         @Override
-        public Void visit(LetClause lc, Void arg) throws AsterixException {
+        public Void visit(LetClause lc, Void arg) throws CompilationException {
             lc.getBindingExpr().accept(this, arg);
             return null;
         }
 
         @Override
-        public Void visit(UnionExpr u, Void arg) throws AsterixException {
+        public Void visit(UnionExpr u, Void arg) throws CompilationException {
             for (Expression e : u.getExprs()) {
                 e.accept(this, arg);
             }
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlStatementRewriter.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlStatementRewriter.java
index b9566f4..a89e8bd 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlStatementRewriter.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlStatementRewriter.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.aql.rewrites;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.AqlDeleteRewriteVisitor;
 import org.apache.asterix.lang.common.base.IStatementRewriter;
 import org.apache.asterix.lang.common.base.Statement;
@@ -26,11 +26,11 @@
 class AqlStatementRewriter implements IStatementRewriter {
 
     @Override
-    public void rewrite(Statement stmt) throws AsterixException {
+    public void rewrite(Statement stmt) throws CompilationException {
         rewriteDeleteStatement(stmt);
     }
 
-    private void rewriteDeleteStatement(Statement stmt) throws AsterixException {
+    private void rewriteDeleteStatement(Statement stmt) throws CompilationException {
         if (stmt != null) {
             AqlDeleteRewriteVisitor visitor = new AqlDeleteRewriteVisitor();
             stmt.accept(visitor, null);
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/visitor/AqlBuiltinFunctionRewriteVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/visitor/AqlBuiltinFunctionRewriteVisitor.java
index 4c9a615..4f422d4 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/visitor/AqlBuiltinFunctionRewriteVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/visitor/AqlBuiltinFunctionRewriteVisitor.java
@@ -22,18 +22,18 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
-import org.apache.asterix.lang.common.util.CommonFunctionMapUtil;
 import org.apache.asterix.lang.aql.visitor.base.AbstractAqlSimpleExpressionVisitor;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.expression.CallExpr;
+import org.apache.asterix.lang.common.util.CommonFunctionMapUtil;
 
 public class AqlBuiltinFunctionRewriteVisitor extends AbstractAqlSimpleExpressionVisitor {
 
     @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
         FunctionSignature functionSignature = callExpr.getFunctionSignature();
         callExpr.setFunctionSignature(CommonFunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature));
         List<Expression> newExprList = new ArrayList<>();
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/statement/SubscribeFeedStatement.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/statement/SubscribeFeedStatement.java
index f2f04d8..1d0d962 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/statement/SubscribeFeedStatement.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/statement/SubscribeFeedStatement.java
@@ -26,7 +26,7 @@
 
 import org.apache.asterix.active.EntityId;
 import org.apache.asterix.common.exceptions.ACIDException;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.external.feed.management.FeedConnectionRequest;
 import org.apache.asterix.external.feed.policy.FeedPolicyAccessor;
@@ -142,7 +142,7 @@
         try {
             statements = parser.parse();
             query = ((InsertStatement) statements.get(3)).getQuery();
-        } catch (AsterixException pe) {
+        } catch (CompilationException pe) {
             throw new MetadataException(pe);
         }
 
@@ -170,7 +170,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return null;
     }
 
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLFormatPrintUtil.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLFormatPrintUtil.java
index fe6c5ac..7848bf3 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLFormatPrintUtil.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLFormatPrintUtil.java
@@ -23,7 +23,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.AQLFormatPrintVisitor;
 import org.apache.asterix.lang.aql.visitor.AQLToSQLPPPrintVisitor;
 import org.apache.asterix.lang.common.base.ILangExpression;
@@ -31,12 +31,12 @@
 
 public class AQLFormatPrintUtil {
 
-    public static void print(ILangExpression expr, PrintWriter output) throws AsterixException {
+    public static void print(ILangExpression expr, PrintWriter output) throws CompilationException {
         AQLFormatPrintVisitor visitor = new AQLFormatPrintVisitor(output);
         expr.accept(visitor, 0);
     }
 
-    public static void print(List<Statement> exprs, PrintWriter output) throws AsterixException {
+    public static void print(List<Statement> exprs, PrintWriter output) throws CompilationException {
         AQLFormatPrintVisitor visitor = new AQLFormatPrintVisitor(output);
         for (Statement expr : exprs) {
             expr.accept(visitor, 0);
@@ -47,15 +47,15 @@
      * @param expr
      *            a language expression.
      * @return a formatted string of a language expression.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static String toString(ILangExpression expr) throws AsterixException {
+    public static String toString(ILangExpression expr) throws CompilationException {
         List<ILangExpression> exprs = new ArrayList<>();
         exprs.add(expr);
         return toString(exprs);
     }
 
-    public static String toString(List<ILangExpression> exprs) throws AsterixException {
+    public static String toString(List<ILangExpression> exprs) throws CompilationException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         PrintWriter output = new PrintWriter(bos);
         AQLFormatPrintVisitor visitor = new AQLFormatPrintVisitor(output);
@@ -66,7 +66,7 @@
         return bos.toString();
     }
 
-    public static String toSQLPPString(List<Statement> exprs) throws AsterixException {
+    public static String toSQLPPString(List<Statement> exprs) throws CompilationException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         PrintWriter output = new PrintWriter(bos);
         AQLToSQLPPPrintVisitor visitor = new AQLToSQLPPPrintVisitor(output);
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLVariableSubstitutionUtil.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLVariableSubstitutionUtil.java
index 717eb5c..096b12f 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLVariableSubstitutionUtil.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLVariableSubstitutionUtil.java
@@ -20,7 +20,7 @@
 
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.visitor.AQLCloneAndSubstituteVariablesVisitor;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
@@ -31,7 +31,7 @@
 public class AQLVariableSubstitutionUtil {
 
     public static ILangExpression substituteVariable(ILangExpression expression,
-            Map<VariableExpr, Expression> varExprMap) throws AsterixException {
+            Map<VariableExpr, Expression> varExprMap) throws CompilationException {
         AQLCloneAndSubstituteVariablesVisitor visitor = new AQLCloneAndSubstituteVariablesVisitor(
                 new LangRewritingContext(0));
         VariableSubstitutionEnvironment env = new VariableSubstitutionEnvironment(varExprMap);
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/RangeMapBuilder.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/RangeMapBuilder.java
index 2e03b8a..9cf8b8d 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/RangeMapBuilder.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/RangeMapBuilder.java
@@ -21,7 +21,7 @@
 import java.io.DataOutput;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.formats.nontagged.BinaryComparatorFactoryProvider;
 import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
 import org.apache.asterix.lang.aql.parser.AQLParserFactory;
@@ -58,7 +58,7 @@
 public abstract class RangeMapBuilder {
     private static final IParserFactory parserFactory = new AQLParserFactory();
 
-    public static IRangeMap parseHint(Object hint) throws AsterixException {
+    public static IRangeMap parseHint(Object hint) throws CompilationException {
         ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
         DataOutput out = abvs.getDataOutput();;
         abvs.reset();
@@ -66,17 +66,17 @@
         IParser parser = parserFactory.createParser((String) hint);
         List<Statement> hintStatements = parser.parse();
         if (hintStatements.size() != 1) {
-            throw new AsterixException("Only one range statement is allowed for the range hint.");
+            throw new CompilationException("Only one range statement is allowed for the range hint.");
         }
 
         // Translate the query into a Range Map
         if (hintStatements.get(0).getKind() != Statement.Kind.QUERY) {
-            throw new AsterixException("Not a proper query for the range hint.");
+            throw new CompilationException("Not a proper query for the range hint.");
         }
         Query q = (Query) hintStatements.get(0);
 
         if (q.getBody().getKind() != Kind.LIST_CONSTRUCTOR_EXPRESSION) {
-            throw new AsterixException("The range hint must be a list.");
+            throw new CompilationException("The range hint must be a list.");
         }
         List<Expression> el = ((ListConstructor) q.getBody()).getExprList();
         int offsets[] = new int[el.size()];
@@ -95,7 +95,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    private static void parseLiteralToBytes(Expression item, DataOutput out) throws AsterixException {
+    private static void parseLiteralToBytes(Expression item, DataOutput out) throws CompilationException {
         AMutableDouble aDouble = new AMutableDouble(0);
         AMutableFloat aFloat = new AMutableFloat(0);
         AMutableInt64 aInt64 = new AMutableInt64(0);
@@ -142,11 +142,11 @@
                             + item.getKind() + " type of expressions.");
             }
         } catch (HyracksDataException e) {
-            throw new AsterixException(e.getMessage());
+            throw new CompilationException(e.getMessage());
         }
     }
 
-    public static void verifyRangeOrder(IRangeMap rangeMap, boolean ascending) throws AsterixException {
+    public static void verifyRangeOrder(IRangeMap rangeMap, boolean ascending) throws CompilationException {
         // TODO Add support for composite fields.
         int fieldIndex = 0;
         int fieldType = rangeMap.getTag(0, 0);
@@ -157,7 +157,7 @@
         int c = 0;
         for (int split = 1; split < rangeMap.getSplitCount(); ++split) {
             if (fieldType != rangeMap.getTag(fieldIndex, split)) {
-                throw new AsterixException("Range field contains more than a single type of items (" + fieldType
+                throw new CompilationException("Range field contains more than a single type of items (" + fieldType
                         + " and " + rangeMap.getTag(fieldIndex, split) + ").");
             }
             int previousSplit = split - 1;
@@ -167,10 +167,10 @@
                         rangeMap.getLength(fieldIndex, previousSplit), rangeMap.getByteArray(fieldIndex, split),
                         rangeMap.getStartOffset(fieldIndex, split), rangeMap.getLength(fieldIndex, split));
             } catch (HyracksDataException e) {
-                throw new AsterixException(e);
+                throw new CompilationException(e);
             }
             if (c >= 0) {
-                throw new AsterixException("Range fields are not in sorted order.");
+                throw new CompilationException("Range fields are not in sorted order.");
             }
         }
     }
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLAstPrintVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLAstPrintVisitor.java
index 0636114..1f76f75 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLAstPrintVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLAstPrintVisitor.java
@@ -20,7 +20,7 @@
 
 import java.io.PrintWriter;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
 import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
@@ -45,7 +45,7 @@
     }
 
     @Override
-    public Void visit(FLWOGRExpression flwor, Integer step) throws AsterixException {
+    public Void visit(FLWOGRExpression flwor, Integer step) throws CompilationException {
         out.println(skip(step) + "FLWOGR [");
         for (Clause cl : flwor.getClauseList()) {
             cl.accept(this, step + 1);
@@ -57,7 +57,7 @@
     }
 
     @Override
-    public Void visit(ForClause fc, Integer step) throws AsterixException {
+    public Void visit(ForClause fc, Integer step) throws CompilationException {
         out.print(skip(step) + "For ");
         fc.getVarExpr().accept(this, 0);
         out.println(skip(step + 1) + "In ");
@@ -66,7 +66,7 @@
     }
 
     @Override
-    public Void visit(UnionExpr u, Integer step) throws AsterixException {
+    public Void visit(UnionExpr u, Integer step) throws CompilationException {
         out.println(skip(step) + "Union [");
         for (Expression expr : u.getExprs()) {
             expr.accept(this, step + 1);
@@ -76,7 +76,7 @@
     }
 
     @Override
-    public Void visit(DistinctClause dc, Integer step) throws AsterixException {
+    public Void visit(DistinctClause dc, Integer step) throws CompilationException {
         out.print(skip(step) + "Distinct ");
         for (Expression expr : dc.getDistinctByExpr()) {
             expr.accept(this, step + 1);
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLCloneAndSubstituteVariablesVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLCloneAndSubstituteVariablesVisitor.java
index 3352125..0e7b4ad 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLCloneAndSubstituteVariablesVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLCloneAndSubstituteVariablesVisitor.java
@@ -21,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
 import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
@@ -49,7 +49,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(ForClause fc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fc.getInExpr().accept(this, env);
         VariableExpr varExpr = fc.getVarExpr();
         VariableExpr newVe = generateNewVariable(context, varExpr);
@@ -68,7 +68,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FLWOGRExpression flwor,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<Clause> newClauses = new ArrayList<Clause>(flwor.getClauseList().size());
         VariableSubstitutionEnvironment currentEnv = env;
         for (Clause c : flwor.getClauseList()) {
@@ -84,7 +84,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(UnionExpr u,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<Expression> exprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(u.getExprs(), env, this);
         UnionExpr newU = new UnionExpr(exprList);
         return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newU, env);
@@ -92,7 +92,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(DistinctClause dc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<Expression> exprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(dc.getDistinctByExpr(), env,
                 this);
         DistinctClause dc2 = new DistinctClause(exprList);
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLFormatPrintVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLFormatPrintVisitor.java
index ae186ab..a12f089 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLFormatPrintVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLFormatPrintVisitor.java
@@ -20,7 +20,7 @@
 
 import java.io.PrintWriter;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
 import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
@@ -44,7 +44,7 @@
     }
 
     @Override
-    public Void visit(FLWOGRExpression flwor, Integer step) throws AsterixException {
+    public Void visit(FLWOGRExpression flwor, Integer step) throws CompilationException {
         for (Clause cl : flwor.getClauseList()) {
             cl.accept(this, step);
         }
@@ -54,7 +54,7 @@
     }
 
     @Override
-    public Void visit(ForClause fc, Integer step) throws AsterixException {
+    public Void visit(ForClause fc, Integer step) throws CompilationException {
         out.print("for ");
         fc.getVarExpr().accept(this, step + 2);
         if (fc.hasPosVar()) {
@@ -68,13 +68,13 @@
     }
 
     @Override
-    public Void visit(UnionExpr u, Integer step) throws AsterixException {
+    public Void visit(UnionExpr u, Integer step) throws CompilationException {
         printDelimitedExpressions(u.getExprs(), "\n" + skip(step) + "union\n", step);
         return null;
     }
 
     @Override
-    public Void visit(DistinctClause dc, Integer step) throws AsterixException {
+    public Void visit(DistinctClause dc, Integer step) throws CompilationException {
         out.print(skip(step) + "distinct by ");
         printDelimitedExpressions(dc.getDistinctByExpr(), COMMA, step + 2);
         out.println();
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLInlineUdfsVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLInlineUdfsVisitor.java
index 71ce034..fb452d2 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLInlineUdfsVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLInlineUdfsVisitor.java
@@ -21,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
 import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
@@ -47,7 +47,7 @@
     }
 
     @Override
-    public Boolean visit(FLWOGRExpression flwor, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(FLWOGRExpression flwor, List<FunctionDecl> arg) throws CompilationException {
         boolean changed = false;
         for (Clause c : flwor.getClauseList()) {
             if (c.accept(this, arg)) {
@@ -60,21 +60,21 @@
     }
 
     @Override
-    public Boolean visit(ForClause fc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(ForClause fc, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(fc.getInExpr(), arg);
         fc.setInExpr(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(UnionExpr u, List<FunctionDecl> fds) throws AsterixException {
+    public Boolean visit(UnionExpr u, List<FunctionDecl> fds) throws CompilationException {
         Pair<Boolean, List<Expression>> p = inlineUdfsInExprList(u.getExprs(), fds);
         u.setExprs(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(DistinctClause dc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(DistinctClause dc, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, List<Expression>> p = inlineUdfsInExprList(dc.getDistinctByExpr(), arg);
         dc.setDistinctByExpr(p.second);
         return p.first;
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java
index 0525f80..481dea7 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java
@@ -29,7 +29,7 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
@@ -83,7 +83,7 @@
     }
 
     @Override
-    public Void visit(FLWOGRExpression flwor, Integer step) throws AsterixException {
+    public Void visit(FLWOGRExpression flwor, Integer step) throws CompilationException {
         if (step != 0) {
             out.println("(");
         }
@@ -202,14 +202,14 @@
     }
 
     @Override
-    public Void visit(ForClause fc, Integer step) throws AsterixException {
+    public Void visit(ForClause fc, Integer step) throws CompilationException {
         // The processing of a "for" clause depends on its neighbor clauses,
         // hence the logic goes to visit(FLWOGRExpression).
         return null;
     }
 
     private void visitForClause(ForClause fc, Integer step, boolean startFor, boolean hasConsequentFor)
-            throws AsterixException {
+            throws CompilationException {
         if (startFor) {
             out.print(skip(step) + "from  ");
         } else {
@@ -229,7 +229,7 @@
     }
 
     private void visitLetClause(LetClause lc, Integer step, boolean startLet, boolean hasConsequentLet)
-            throws AsterixException {
+            throws CompilationException {
         if (startLet) {
             out.print(skip(step) + "with  ");
         } else {
@@ -245,7 +245,7 @@
     }
 
     @Override
-    public Void visit(Query q, Integer step) throws AsterixException {
+    public Void visit(Query q, Integer step) throws CompilationException {
         Expression expr = q.getBody();
         if (expr != null) {
             if (expr.getKind() != Kind.FLWOGR_EXPRESSION) {
@@ -262,19 +262,19 @@
     }
 
     @Override
-    public Void visit(DataverseDecl dv, Integer step) throws AsterixException {
+    public Void visit(DataverseDecl dv, Integer step) throws CompilationException {
         out.println(skip(step) + "use " + normalize(dv.getDataverseName().getValue()) + ";\n\n");
         return null;
     }
 
     @Override
-    public Void visit(UnionExpr u, Integer step) throws AsterixException {
+    public Void visit(UnionExpr u, Integer step) throws CompilationException {
         printDelimitedExpressions(u.getExprs(), "\n" + skip(step) + "union\n" + skip(step), step);
         return null;
     }
 
     @Override
-    public Void visit(DistinctClause dc, Integer step) throws AsterixException {
+    public Void visit(DistinctClause dc, Integer step) throws CompilationException {
         return null;
     }
 
@@ -289,7 +289,7 @@
     }
 
     @Override
-    public Void visit(LetClause lc, Integer step) throws AsterixException {
+    public Void visit(LetClause lc, Integer step) throws CompilationException {
         out.print(skip(step) + "with ");
         lc.getVarExpr().accept(this, step + 2);
         out.print(" as ");
@@ -300,7 +300,7 @@
     }
 
     @Override
-    public Void visit(CallExpr callExpr, Integer step) throws AsterixException {
+    public Void visit(CallExpr callExpr, Integer step) throws CompilationException {
         FunctionSignature signature = callExpr.getFunctionSignature();
         if (signature.getNamespace() != null && signature.getNamespace().equals("Metadata")
                 && signature.getName().equals("dataset") && signature.getArity() == 1) {
@@ -317,7 +317,7 @@
     }
 
     @Override
-    public Void visit(GroupbyClause gc, Integer step) throws AsterixException {
+    public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
         if (gc.hasHashGroupByHint()) {
             out.println(skip(step) + "/* +hash */");
         }
@@ -328,7 +328,7 @@
     }
 
     @Override
-    public Void visit(InsertStatement insert, Integer step) throws AsterixException {
+    public Void visit(InsertStatement insert, Integer step) throws CompilationException {
         out.print(skip(step) + "insert into " + generateFullName(insert.getDataverseName(), insert.getDatasetName())
                 + "\n");
         insert.getQuery().accept(this, step);
@@ -337,7 +337,7 @@
     }
 
     @Override
-    public Void visit(DeleteStatement del, Integer step) throws AsterixException {
+    public Void visit(DeleteStatement del, Integer step) throws CompilationException {
         out.print(skip(step) + "delete ");
         del.getVariableExpr().accept(this, step + 2);
         out.println(skip(step) + " from " + generateFullName(del.getDataverseName(), del.getDatasetName()));
@@ -366,7 +366,7 @@
 
     @Override
     protected void printDelimitedGbyExpressions(List<GbyVariableExpressionPair> gbyList, int step)
-            throws AsterixException {
+            throws CompilationException {
         int gbySize = gbyList.size();
         int gbyIndex = 0;
         for (GbyVariableExpressionPair pair : gbyList) {
@@ -445,7 +445,7 @@
     }
 
     // Processes leading "let"s in a FLWOGR.
-    private void processLeadingLetClauses(Integer step, List<Clause> clauseList) throws AsterixException {
+    private void processLeadingLetClauses(Integer step, List<Clause> clauseList) throws CompilationException {
         List<Clause> processedLetList = new ArrayList<Clause>();
         boolean firstLet = true;
         int size = clauseList.size();
@@ -473,10 +473,10 @@
      * @param clauseList
      *            , a list of clauses
      * @return the cutting group-by clause and the list of extracted clauses.
-     * @throws AsterixException
+     * @throws CompilationException
      */
     private Pair<GroupbyClause, List<Clause>> extractUnnestAfterGroupby(List<Clause> clauseList)
-            throws AsterixException {
+            throws CompilationException {
         List<Clause> nestedClauses = new ArrayList<Clause>();
         GroupbyClause cuttingGbyClause = null;
         boolean meetGroupBy = false;
@@ -519,7 +519,7 @@
 
     // Extracts the variables to be substituted.
     private Map<VariableExpr, Expression> extractLetBindingVariables(List<Clause> clauses,
-            GroupbyClause cuttingGbyClause) throws AsterixException {
+            GroupbyClause cuttingGbyClause) throws CompilationException {
         Map<VariableExpr, Expression> varExprMap = new HashMap<VariableExpr, Expression>();
         int gbyIndex = clauses.indexOf(cuttingGbyClause);
         for (int i = gbyIndex + 1; i < clauses.size(); i++) {
@@ -560,7 +560,7 @@
     }
 
     // Merge consecutive "where" clauses.
-    private void mergeConsecutiveWhereClauses(List<Clause> clauses) throws AsterixException {
+    private void mergeConsecutiveWhereClauses(List<Clause> clauses) throws CompilationException {
         List<Clause> results = new ArrayList<Clause>();
         int size = clauses.size();
         for (int index = 0; index < size;) {
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlAstVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlAstVisitor.java
index 05c1b81..a2b9ac6 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlAstVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlAstVisitor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.aql.visitor.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
 import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
@@ -28,22 +28,22 @@
 public abstract class AbstractAqlAstVisitor<R, T> extends AbstractAstVisitor<R, T> implements IAQLVisitor<R, T> {
 
     @Override
-    public R visit(FLWOGRExpression flwogreExpr, T arg) throws AsterixException {
+    public R visit(FLWOGRExpression flwogreExpr, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(UnionExpr u, T arg) throws AsterixException {
+    public R visit(UnionExpr u, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(ForClause forClause, T arg) throws AsterixException {
+    public R visit(ForClause forClause, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(DistinctClause distinctClause, T arg) throws AsterixException {
+    public R visit(DistinctClause distinctClause, T arg) throws CompilationException {
         return null;
     }
 
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlSimpleExpressionVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlSimpleExpressionVisitor.java
index 2b71202..4f52c37 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlSimpleExpressionVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlSimpleExpressionVisitor.java
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
 import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
@@ -55,7 +55,7 @@
 public class AbstractAqlSimpleExpressionVisitor extends AbstractAqlQueryExpressionVisitor<Expression, ILangExpression> {
 
     @Override
-    public Expression visit(FLWOGRExpression flwogreExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(FLWOGRExpression flwogreExpr, ILangExpression arg) throws CompilationException {
         for (Clause clause : flwogreExpr.getClauseList()) {
             clause.accept(this, arg);
         }
@@ -64,49 +64,49 @@
     }
 
     @Override
-    public Expression visit(UnionExpr u, ILangExpression arg) throws AsterixException {
+    public Expression visit(UnionExpr u, ILangExpression arg) throws CompilationException {
         u.setExprs(visit(u.getExprs(), arg));
         return u;
     }
 
     @Override
-    public Expression visit(ForClause forClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(ForClause forClause, ILangExpression arg) throws CompilationException {
         forClause.setInExpr(forClause.getInExpr().accept(this, arg));
         return null;
     }
 
     @Override
-    public Expression visit(DistinctClause distinctClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(DistinctClause distinctClause, ILangExpression arg) throws CompilationException {
         distinctClause.setDistinctByExpr(visit(distinctClause.getDistinctByExpr(), arg));
         return null;
     }
 
     @Override
-    public Expression visit(Query q, ILangExpression arg) throws AsterixException {
+    public Expression visit(Query q, ILangExpression arg) throws CompilationException {
         q.setBody(visit(q.getBody(), q));
         return null;
     }
 
     @Override
-    public Expression visit(FunctionDecl fd, ILangExpression arg) throws AsterixException {
+    public Expression visit(FunctionDecl fd, ILangExpression arg) throws CompilationException {
         fd.setFuncBody(visit(fd.getFuncBody(), fd));
         return null;
     }
 
     @Override
-    public Expression visit(WhereClause whereClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(WhereClause whereClause, ILangExpression arg) throws CompilationException {
         whereClause.setWhereExpr(visit(whereClause.getWhereExpr(), whereClause));
         return null;
     }
 
     @Override
-    public Expression visit(OrderbyClause oc, ILangExpression arg) throws AsterixException {
+    public Expression visit(OrderbyClause oc, ILangExpression arg) throws CompilationException {
         oc.setOrderbyList(visit(oc.getOrderbyList(), arg));
         return null;
     }
 
     @Override
-    public Expression visit(GroupbyClause gc, ILangExpression arg) throws AsterixException {
+    public Expression visit(GroupbyClause gc, ILangExpression arg) throws CompilationException {
         for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
             gbyVarExpr.setExpr(visit(gbyVarExpr.getExpr(), gc));
         }
@@ -114,7 +114,7 @@
     }
 
     @Override
-    public Expression visit(LimitClause limitClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(LimitClause limitClause, ILangExpression arg) throws CompilationException {
         limitClause.setLimitExpr(visit(limitClause.getLimitExpr(), limitClause));
         if (limitClause.hasOffset()) {
             limitClause.setOffset(visit(limitClause.getOffset(), limitClause));
@@ -123,24 +123,24 @@
     }
 
     @Override
-    public Expression visit(LetClause letClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(LetClause letClause, ILangExpression arg) throws CompilationException {
         letClause.setBindingExpr(visit(letClause.getBindingExpr(), letClause));
         return null;
     }
 
     @Override
-    public Expression visit(LiteralExpr l, ILangExpression arg) throws AsterixException {
+    public Expression visit(LiteralExpr l, ILangExpression arg) throws CompilationException {
         return l;
     }
 
     @Override
-    public Expression visit(ListConstructor lc, ILangExpression arg) throws AsterixException {
+    public Expression visit(ListConstructor lc, ILangExpression arg) throws CompilationException {
         lc.setExprList(visit(lc.getExprList(), arg));
         return lc;
     }
 
     @Override
-    public Expression visit(RecordConstructor rc, ILangExpression arg) throws AsterixException {
+    public Expression visit(RecordConstructor rc, ILangExpression arg) throws CompilationException {
         for (FieldBinding binding : rc.getFbList()) {
             binding.setLeftExpr(visit(binding.getLeftExpr(), rc));
             binding.setRightExpr(visit(binding.getRightExpr(), rc));
@@ -149,13 +149,13 @@
     }
 
     @Override
-    public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws CompilationException {
         operatorExpr.setExprList(visit(operatorExpr.getExprList(), arg));
         return operatorExpr;
     }
 
     @Override
-    public Expression visit(IfExpr ifExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(IfExpr ifExpr, ILangExpression arg) throws CompilationException {
         ifExpr.setCondExpr(visit(ifExpr.getCondExpr(), ifExpr));
         ifExpr.setThenExpr(visit(ifExpr.getThenExpr(), ifExpr));
         ifExpr.setElseExpr(visit(ifExpr.getElseExpr(), ifExpr));
@@ -163,7 +163,7 @@
     }
 
     @Override
-    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws AsterixException {
+    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws CompilationException {
         for (QuantifiedPair pair : qe.getQuantifiedList()) {
             pair.setExpr(visit(pair.getExpr(), qe));
         }
@@ -172,30 +172,30 @@
     }
 
     @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
         callExpr.setExprList(visit(callExpr.getExprList(), arg));
         return callExpr;
     }
 
     @Override
-    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws CompilationException {
         return varExpr;
     }
 
     @Override
-    public Expression visit(UnaryExpr u, ILangExpression arg) throws AsterixException {
+    public Expression visit(UnaryExpr u, ILangExpression arg) throws CompilationException {
         u.setExpr(visit(u.getExpr(), u));
         return u;
     }
 
     @Override
-    public Expression visit(FieldAccessor fa, ILangExpression arg) throws AsterixException {
+    public Expression visit(FieldAccessor fa, ILangExpression arg) throws CompilationException {
         fa.setExpr(visit(fa.getExpr(), fa));
         return fa;
     }
 
     @Override
-    public Expression visit(IndexAccessor ia, ILangExpression arg) throws AsterixException {
+    public Expression visit(IndexAccessor ia, ILangExpression arg) throws CompilationException {
         ia.setExpr(visit(ia.getExpr(), ia));
         if (ia.getIndexExpr() != null) {
             ia.setIndexExpr(visit(ia.getIndexExpr(), arg));
@@ -203,19 +203,19 @@
         return ia;
     }
 
-    protected Expression visit(Expression expr, ILangExpression arg) throws AsterixException {
+    protected Expression visit(Expression expr, ILangExpression arg) throws CompilationException {
         return postVisit(preVisit(expr).accept(this, arg));
     }
 
-    protected Expression preVisit(Expression expr) throws AsterixException {
+    protected Expression preVisit(Expression expr) throws CompilationException {
         return expr;
     }
 
-    protected Expression postVisit(Expression expr) throws AsterixException {
+    protected Expression postVisit(Expression expr) throws CompilationException {
         return expr;
     }
 
-    private List<Expression> visit(List<Expression> exprs, ILangExpression arg) throws AsterixException {
+    private List<Expression> visit(List<Expression> exprs, ILangExpression arg) throws CompilationException {
         List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : exprs) {
             newExprList.add(visit(expr, arg));
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLPlusVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLPlusVisitor.java
index f2037e7..b0c5464 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLPlusVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLPlusVisitor.java
@@ -18,16 +18,16 @@
  */
 package org.apache.asterix.lang.aql.visitor.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.JoinClause;
 import org.apache.asterix.lang.aql.clause.MetaVariableClause;
 import org.apache.asterix.lang.aql.expression.MetaVariableExpr;
 
 public interface IAQLPlusVisitor<R, T> extends IAQLVisitor<R, T> {
 
-    R visitJoinClause(JoinClause c, T arg) throws AsterixException;
+    R visitJoinClause(JoinClause c, T arg) throws CompilationException;
 
-    R visitMetaVariableClause(MetaVariableClause c, T arg) throws AsterixException;
+    R visitMetaVariableClause(MetaVariableClause c, T arg) throws CompilationException;
 
-    R visitMetaVariableExpr(MetaVariableExpr v, T arg) throws AsterixException;
+    R visitMetaVariableExpr(MetaVariableExpr v, T arg) throws CompilationException;
 }
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLVisitor.java
index d990005..303f47b 100644
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLVisitor.java
+++ b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLVisitor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.aql.visitor.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
 import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
@@ -27,12 +27,12 @@
 
 public interface IAQLVisitor<R, T> extends ILangVisitor<R, T> {
 
-    R visit(FLWOGRExpression flwogreExpr, T arg) throws AsterixException;
+    R visit(FLWOGRExpression flwogreExpr, T arg) throws CompilationException;
 
-    R visit(UnionExpr u, T arg) throws AsterixException;
+    R visit(UnionExpr u, T arg) throws CompilationException;
 
-    R visit(ForClause forClause, T arg) throws AsterixException;
+    R visit(ForClause forClause, T arg) throws CompilationException;
 
-    R visit(DistinctClause distinctClause, T arg) throws AsterixException;
+    R visit(DistinctClause distinctClause, T arg) throws CompilationException;
 
 }
diff --git a/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj b/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
index 9be5f8a..4b2091c 100644
--- a/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
+++ b/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
@@ -43,7 +43,7 @@
 import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
 import org.apache.asterix.common.config.DatasetConfig.IndexType;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.aql.clause.DistinctClause;
 import org.apache.asterix.lang.aql.clause.ForClause;
@@ -198,7 +198,7 @@
          try {
            throw new ParseException("Need a binding variable for the enclosed expression: " +
                                        AQLFormatPrintUtil.toString(bodyExpression));
-         } catch (AsterixException e){
+         } catch (CompilationException e){
            throw new ParseException(e.getLocalizedMessage());
          }
        }
@@ -252,7 +252,7 @@
         super.setInput(s);
     }
 
-    public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
+    public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException {
         File file = new File(args[0]);
         Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
         AQLParser parser = new AQLParser(fis);
@@ -260,15 +260,15 @@
         //st.accept(new AQLPrintVisitor(), 0);
     }
 
-    public List<Statement> parse() throws AsterixException {
+    public List<Statement> parse() throws CompilationException {
         try {
             return Statement();
         } catch (Error e) {
             // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
             // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
-            throw new AsterixException(new ParseException(e.getMessage()));
+            throw new CompilationException(new ParseException(e.getMessage()));
         } catch (ParseException e){
-            throw new AsterixException(e.getMessage());
+            throw new CompilationException(e.getMessage());
         }
     }
 }
@@ -1652,7 +1652,7 @@
         }
         try{
           op.addOperator(token.image);
-        } catch (AsterixException e){
+        } catch (CompilationException e){
           throw new ParseException(e.getMessage());
         }
     }
@@ -1687,7 +1687,7 @@
         }
         try{
           op.addOperator(token.image);
-        } catch (AsterixException e){
+        } catch (CompilationException e){
           throw new ParseException(e.getMessage());
         }
     }
@@ -1743,7 +1743,7 @@
           }
          try{
            op.addOperator(token.image);
-         } catch (AsterixException e){
+         } catch (CompilationException e){
            throw new ParseException(e.getMessage());
          }
       }
@@ -1786,7 +1786,7 @@
         }
         try{
           ((OperatorExpr)op).addOperator(token.image);
-        } catch (AsterixException e){
+        } catch (CompilationException e){
           throw new ParseException(e.getMessage());
         }
     }
@@ -1819,7 +1819,7 @@
         }
         try{
           op.addOperator(token.image);
-        } catch (AsterixException e){
+        } catch (CompilationException e){
           throw new ParseException(e.getMessage());
         }
     }
@@ -1851,7 +1851,7 @@
         }
         try{
           op.addOperator(token.image);
-        } catch (AsterixException e){
+        } catch (CompilationException e){
           throw new ParseException(e.getMessage());
         }
     }
@@ -1898,7 +1898,7 @@
           uexpr = new UnaryExpr();
           try{
             uexpr.setExprType(token.image);
-          } catch (AsterixException e){
+          } catch (CompilationException e){
             throw new ParseException(e.getMessage());
           }
     }
@@ -2417,7 +2417,7 @@
           if (hint.startsWith(RANGE_HINT)) {
             try{
               oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length())));
-            } catch (AsterixException e) {
+            } catch (CompilationException e) {
               throw new ParseException(e.getMessage());
             }
           }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/ILangExpression.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/ILangExpression.java
index 5837021..f6b9399 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/ILangExpression.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/ILangExpression.java
@@ -18,9 +18,9 @@
  */
 package org.apache.asterix.lang.common.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 
 public interface ILangExpression {
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException;
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException;
 }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IParser.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IParser.java
index ad57fa9..b1287224 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IParser.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IParser.java
@@ -20,10 +20,10 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 
 public interface IParser {
 
-    public List<Statement> parse() throws AsterixException;
+    public List<Statement> parse() throws CompilationException;
 
 }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IQueryRewriter.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IQueryRewriter.java
index d77592a..0c6c04c 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IQueryRewriter.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IQueryRewriter.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
 import org.apache.asterix.lang.common.statement.FunctionDecl;
 import org.apache.asterix.metadata.declared.MetadataProvider;
@@ -40,5 +40,5 @@
      *            manages ids of variables and guarantees uniqueness of variables.
      */
     public void rewrite(List<FunctionDecl> declaredFunctions, IReturningStatement topExpr,
-            MetadataProvider metadataProvider, LangRewritingContext context) throws AsterixException;
+            MetadataProvider metadataProvider, LangRewritingContext context) throws CompilationException;
 }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IStatementRewriter.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IStatementRewriter.java
index ec4f24c..7de67f7 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IStatementRewriter.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/base/IStatementRewriter.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 
 public interface IStatementRewriter {
 
@@ -26,6 +26,6 @@
      * @param statement,
      *            a non-query statement.
      */
-    public void rewrite(Statement statement) throws AsterixException;
+    public void rewrite(Statement statement) throws CompilationException;
 
 }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
index 7dacd39..ac7cbbf 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/GroupbyClause.java
@@ -22,7 +22,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
@@ -104,7 +104,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/LetClause.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/LetClause.java
index 7043a34..7c813d3 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/LetClause.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/LetClause.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.expression.VariableExpr;
@@ -61,7 +61,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/LimitClause.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/LimitClause.java
index f9123ef..68220fc 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/LimitClause.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/LimitClause.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -63,7 +63,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/OrderbyClause.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/OrderbyClause.java
index 8574c76..0dcbd8e 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/OrderbyClause.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/OrderbyClause.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -70,7 +70,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/UpdateClause.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/UpdateClause.java
index 50bf7a5..75f6fbd 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/UpdateClause.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/UpdateClause.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.statement.DeleteStatement;
@@ -88,7 +88,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/WhereClause.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/WhereClause.java
index eaa17e2..c540588 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/WhereClause.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/clause/WhereClause.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -49,7 +49,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
index 1b7b918..30b7297 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/CallExpr.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.AbstractExpression;
 import org.apache.asterix.lang.common.base.Expression;
@@ -63,7 +63,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/FieldAccessor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/FieldAccessor.java
index 0a76730..7009d90 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/FieldAccessor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/FieldAccessor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -46,7 +46,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/IfExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/IfExpr.java
index 2709f80..26b9c83 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/IfExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/IfExpr.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.commons.lang3.ObjectUtils;
@@ -68,7 +68,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/IndexAccessor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/IndexAccessor.java
index 07a8254..36111a6 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/IndexAccessor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/IndexAccessor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.commons.lang3.ObjectUtils;
@@ -57,7 +57,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/ListConstructor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/ListConstructor.java
index 7fdca69..9a6d3f6 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/ListConstructor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/ListConstructor.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.commons.lang3.ObjectUtils;
@@ -65,7 +65,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/LiteralExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/LiteralExpr.java
index 46c3c32..600a82c 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/LiteralExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/LiteralExpr.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Literal;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -49,7 +49,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java
index 1418be7..954f715 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java
@@ -22,7 +22,7 @@
 import java.util.List;
 import java.util.Optional;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.AbstractExpression;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.struct.OperatorType;
@@ -91,12 +91,12 @@
         return cmp;
     }
 
-    public void addOperator(String strOp) throws AsterixException {
+    public void addOperator(String strOp) throws CompilationException {
         Optional<OperatorType> op = OperatorType.fromSymbol(strOp);
         if (op.isPresent()) {
             opList.add(op.get());
         } else {
-            throw new AsterixException("Unsupported operator: " + strOp);
+            throw new CompilationException("Unsupported operator: " + strOp);
         }
     }
 
@@ -106,7 +106,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OrderedListTypeDefinition.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OrderedListTypeDefinition.java
index 08b9c53..7b04c7f 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OrderedListTypeDefinition.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OrderedListTypeDefinition.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.commons.lang.ObjectUtils;
 
@@ -36,7 +36,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
index e1372cd..40322d7 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/QuantifiedExpression.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.struct.QuantifiedPair;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -72,7 +72,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/RecordConstructor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/RecordConstructor.java
index 144b27c..6b17461 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/RecordConstructor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/RecordConstructor.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.commons.lang3.ObjectUtils;
@@ -51,7 +51,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/RecordTypeDefinition.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/RecordTypeDefinition.java
index 800af9f..39fbbc4 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/RecordTypeDefinition.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/RecordTypeDefinition.java
@@ -23,7 +23,7 @@
 
 import org.apache.asterix.common.annotations.IRecordFieldDataGen;
 import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.commons.lang3.ObjectUtils;
 
@@ -88,7 +88,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/TypeReferenceExpression.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/TypeReferenceExpression.java
index b360797..e87b2cc 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/TypeReferenceExpression.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/TypeReferenceExpression.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.commons.lang.ObjectUtils;
@@ -42,7 +42,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/UnaryExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/UnaryExpr.java
index 929587c..99197c6 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/UnaryExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/UnaryExpr.java
@@ -20,7 +20,7 @@
 
 import java.util.Optional;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.struct.UnaryExprType;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -43,12 +43,12 @@
         return unaryExprType;
     }
 
-    public void setExprType(String strType) throws AsterixException {
+    public void setExprType(String strType) throws CompilationException {
         Optional<UnaryExprType> exprType = UnaryExprType.fromSymbol(strType);
         if (exprType.isPresent()) {
             this.unaryExprType = exprType.get();
         } else {
-            throw new AsterixException("Unsupported operator: " + strType);
+            throw new CompilationException("Unsupported operator: " + strType);
         }
     }
 
@@ -66,7 +66,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/UnorderedListTypeDefinition.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/UnorderedListTypeDefinition.java
index a0726e2..ad6426e 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/UnorderedListTypeDefinition.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/UnorderedListTypeDefinition.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.commons.lang3.ObjectUtils;
 
@@ -36,7 +36,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java
index dbaea37..8fcd2ad 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/VariableExpr.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.struct.VarIdentifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -61,7 +61,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CompactStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CompactStatement.java
index 94aa1ac..08f12c3 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CompactStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CompactStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -47,7 +47,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/ConnectFeedStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/ConnectFeedStatement.java
index fd1ca5e..ceab6e9 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/ConnectFeedStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/ConnectFeedStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -86,7 +86,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateDataverseStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateDataverseStatement.java
index a475051..b03955a 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateDataverseStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateDataverseStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -54,7 +54,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFeedPolicyStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFeedPolicyStatement.java
index 75fc556..466920d 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFeedPolicyStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFeedPolicyStatement.java
@@ -20,7 +20,7 @@
 
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 
@@ -63,7 +63,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFeedStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFeedStatement.java
index 54b6a94..56e7d33 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFeedStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFeedStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
@@ -55,7 +55,7 @@
     }
 
     @Override
-    public abstract <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException;
+    public abstract <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException;
 
     @Override
     public byte getCategory() {
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFunctionStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFunctionStatement.java
index 5a75f43..6d74957 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFunctionStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateFunctionStatement.java
@@ -21,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.VarIdentifier;
@@ -71,7 +71,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateIndexStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateIndexStatement.java
index 7f36c45..7297bf5 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateIndexStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateIndexStatement.java
@@ -22,7 +22,7 @@
 import java.util.List;
 
 import org.apache.asterix.common.config.DatasetConfig.IndexType;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.expression.TypeExpression;
 import org.apache.asterix.lang.common.struct.Identifier;
@@ -135,7 +135,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreatePrimaryFeedStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreatePrimaryFeedStatement.java
index 6c4d84e..c584ed0 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreatePrimaryFeedStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreatePrimaryFeedStatement.java
@@ -20,7 +20,7 @@
 
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
@@ -53,7 +53,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateSecondaryFeedStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateSecondaryFeedStatement.java
index 6787426..241bcd8 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateSecondaryFeedStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/CreateSecondaryFeedStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
@@ -55,7 +55,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DatasetDecl.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DatasetDecl.java
index bf27988..2eba48a 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DatasetDecl.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DatasetDecl.java
@@ -21,7 +21,7 @@
 import java.util.Map;
 
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -136,7 +136,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DataverseDecl.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DataverseDecl.java
index 5067f9f..4da9c57 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DataverseDecl.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DataverseDecl.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -41,7 +41,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DataverseDropStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DataverseDropStatement.java
index 64ba087..8346912 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DataverseDropStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DataverseDropStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -47,7 +47,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DeleteStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DeleteStatement.java
index d779b4f..3bd309a 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DeleteStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DeleteStatement.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.expression.VariableExpr;
@@ -84,7 +84,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DisconnectFeedStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DisconnectFeedStatement.java
index af4d1fb..4352b18 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DisconnectFeedStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DisconnectFeedStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -66,7 +66,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DropDatasetStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DropDatasetStatement.java
index 7dc1ad8..27eda01 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DropDatasetStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/DropDatasetStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -53,7 +53,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FeedDropStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FeedDropStatement.java
index 0391a4b..a06ed80 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FeedDropStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FeedDropStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -53,7 +53,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FeedPolicyDropStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FeedPolicyDropStatement.java
index d08dc31..b511b06 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FeedPolicyDropStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FeedPolicyDropStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -53,7 +53,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FunctionDecl.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FunctionDecl.java
index 08c90c5..78567b5 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FunctionDecl.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FunctionDecl.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Statement;
@@ -78,7 +78,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FunctionDropStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FunctionDropStatement.java
index 00ae48c6..41cec29 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FunctionDropStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/FunctionDropStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -47,7 +47,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/IndexDropStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/IndexDropStatement.java
index 1b8d0d5..d20e2eb 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/IndexDropStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/IndexDropStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -60,7 +60,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/InsertStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/InsertStatement.java
index 6ddf071..cc72e1c 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/InsertStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/InsertStatement.java
@@ -21,10 +21,10 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.base.IReturningStatement;
+import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -114,7 +114,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/LoadStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/LoadStatement.java
index 145514f..82527b1 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/LoadStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/LoadStatement.java
@@ -20,7 +20,7 @@
 
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -80,7 +80,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/NodeGroupDropStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/NodeGroupDropStatement.java
index e27b447..7fa5056 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/NodeGroupDropStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/NodeGroupDropStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -47,7 +47,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/NodegroupDecl.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/NodegroupDecl.java
index 092e804..c5e1d9c 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/NodegroupDecl.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/NodegroupDecl.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -59,7 +59,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java
index f878998..2aee087 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java
@@ -22,7 +22,7 @@
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.IReturningStatement;
 import org.apache.asterix.lang.common.base.Statement;
@@ -95,7 +95,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/RefreshExternalDatasetStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/RefreshExternalDatasetStatement.java
index ab35b27..a6eb257 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/RefreshExternalDatasetStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/RefreshExternalDatasetStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -45,7 +45,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return null;
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/RunStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/RunStatement.java
index 006799d..cee6e77 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/RunStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/RunStatement.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -69,7 +69,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return null;
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/SetStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/SetStatement.java
index dfa8406..52b839c 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/SetStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/SetStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 
@@ -46,7 +46,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/TypeDecl.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/TypeDecl.java
index a9eb795..3aecfb3 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/TypeDecl.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/TypeDecl.java
@@ -19,7 +19,7 @@
 package org.apache.asterix.lang.common.statement;
 
 import org.apache.asterix.common.annotations.TypeDataGen;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.expression.TypeExpression;
 import org.apache.asterix.lang.common.struct.Identifier;
@@ -68,7 +68,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/TypeDropStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/TypeDropStatement.java
index 99b9bb1..9a5557d 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/TypeDropStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/TypeDropStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -53,7 +53,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/UpdateStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/UpdateStatement.java
index 09ed242..2f3be71 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/UpdateStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/UpdateStatement.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.clause.UpdateClause;
@@ -64,7 +64,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/WriteStatement.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/WriteStatement.java
index 311e650..ae67ad0 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/WriteStatement.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/WriteStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.statement;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.struct.Identifier;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -53,7 +53,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return visitor.visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
index 0a85bed..33e0c52 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/CommonFunctionMapUtil.java
@@ -22,7 +22,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.om.functions.BuiltinFunctions;
 
@@ -87,7 +87,8 @@
      * @return the corresponding system internal function signature if it exists, otherwise
      *         the input function synature.
      */
-    public static FunctionSignature normalizeBuiltinFunctionSignature(FunctionSignature fs) throws AsterixException {
+    public static FunctionSignature normalizeBuiltinFunctionSignature(FunctionSignature fs)
+            throws CompilationException {
         String name = fs.getName();
         String lowerCaseName = name.toLowerCase();
         String mappedName = FUNCTION_NAME_MAP.get(lowerCaseName);
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java
index fe43e21..351ac70 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/FunctionUtil.java
@@ -23,7 +23,7 @@
 import java.util.List;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
@@ -50,17 +50,17 @@
 
     @FunctionalInterface
     public interface IFunctionCollector {
-        Set<FunctionSignature> getFunctionCalls(Expression expression) throws AsterixException;
+        Set<FunctionSignature> getFunctionCalls(Expression expression) throws CompilationException;
     }
 
     @FunctionalInterface
     public interface IFunctionParser {
-        FunctionDecl getFunctionDecl(Function function) throws AsterixException;
+        FunctionDecl getFunctionDecl(Function function) throws CompilationException;
     }
 
     @FunctionalInterface
     public interface IFunctionNormalizer {
-        FunctionSignature normalizeBuiltinFunctionSignature(FunctionSignature fs) throws AsterixException;
+        FunctionSignature normalizeBuiltinFunctionSignature(FunctionSignature fs) throws CompilationException;
     }
 
     /**
@@ -78,12 +78,12 @@
      *            for parsing stored functions in the string represetnation.
      * @param functionNormalizer,
      *            for normalizing function names.
-     * @throws AsterixException
+     * @throws CompilationException
      */
     public static List<FunctionDecl> retrieveUsedStoredFunctions(MetadataProvider metadataProvider,
             Expression expression, List<FunctionSignature> declaredFunctions, List<FunctionDecl> inputFunctionDecls,
             IFunctionCollector functionCollector, IFunctionParser functionParser,
-            IFunctionNormalizer functionNormalizer) throws AsterixException {
+            IFunctionNormalizer functionNormalizer) throws CompilationException {
         List<FunctionDecl> functionDecls = inputFunctionDecls == null ? new ArrayList<>()
                 : new ArrayList<>(inputFunctionDecls);
         if (expression == null) {
@@ -103,7 +103,7 @@
             // Checks the existence of the referred dataverse.
             if (metadataProvider.findDataverse(namespace) == null
                     && !namespace.equals(FunctionConstants.ASTERIX_NS)) {
-                throw new AsterixException("In function call \"" + namespace + "." + signature.getName()
+                throw new CompilationException("In function call \"" + namespace + "." + signature.getName()
                         + "(...)\", the dataverse \"" + namespace + "\" cannot be found!");
             }
             Function function = lookupUserDefinedFunctionDecl(metadataProvider.getMetadataTxnContext(), signature);
@@ -120,14 +120,14 @@
                 } else {
                     messageBuilder.append("function " + signature + " is not defined");
                 }
-                throw new AsterixException(messageBuilder.toString());
+                throw new CompilationException(messageBuilder.toString());
             }
 
             if (function.getLanguage().equalsIgnoreCase(Function.LANGUAGE_AQL)) {
                 FunctionDecl functionDecl = functionParser.getFunctionDecl(function);
                 if (functionDecl != null) {
                     if (functionDecls.contains(functionDecl)) {
-                        throw new AsterixException(
+                        throw new CompilationException(
                                 "Recursive invocation " + functionDecls.get(functionDecls.size() - 1).getSignature()
                                         + " <==> " + functionDecl.getSignature());
                     }
@@ -141,7 +141,7 @@
     }
 
     private static Function lookupUserDefinedFunctionDecl(MetadataTransactionContext mdTxnCtx,
-            FunctionSignature signature) throws AsterixException {
+            FunctionSignature signature) throws CompilationException {
         if (signature.getNamespace() == null) {
             return null;
         }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VariableCloneAndSubstitutionUtil.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VariableCloneAndSubstitutionUtil.java
index 1948b84..e5cf386 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VariableCloneAndSubstitutionUtil.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/util/VariableCloneAndSubstitutionUtil.java
@@ -22,7 +22,7 @@
 import java.util.LinkedList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
@@ -39,7 +39,7 @@
 
     public static List<GbyVariableExpressionPair> substInVarExprPair(LangRewritingContext context,
             List<GbyVariableExpressionPair> gbyVeList, VariableSubstitutionEnvironment newSubs,
-            CloneAndSubstituteVariablesVisitor visitor) throws AsterixException {
+            CloneAndSubstituteVariablesVisitor visitor) throws CompilationException {
         VariableSubstitutionEnvironment subs = newSubs;
         List<GbyVariableExpressionPair> veList = new LinkedList<>();
         for (GbyVariableExpressionPair vep : gbyVeList) {
@@ -64,7 +64,8 @@
     }
 
     public static List<Expression> visitAndCloneExprList(List<Expression> oldExprList,
-            VariableSubstitutionEnvironment arg, CloneAndSubstituteVariablesVisitor visitor) throws AsterixException {
+            VariableSubstitutionEnvironment arg, CloneAndSubstituteVariablesVisitor visitor)
+            throws CompilationException {
         List<Expression> exprs = new ArrayList<>(oldExprList.size());
         for (Expression e : oldExprList) {
             Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = e.accept(visitor, arg);
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java
index 725d7f4..858a8c2 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/AbstractInlineUdfsVisitor.java
@@ -22,7 +22,7 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Expression.Kind;
@@ -84,17 +84,17 @@
      * @return a query expression which is upto a specific langauge, e.g., FLWOGR in AQL and expression query in SQL++.
      */
     protected abstract Expression generateQueryExpression(List<LetClause> letClauses, Expression returnExpr)
-            throws AsterixException;
+            throws CompilationException;
 
     @Override
-    public Boolean visit(Query q, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(Query q, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(q.getBody(), arg);
         q.setBody(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(FunctionDecl fd, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(FunctionDecl fd, List<FunctionDecl> arg) throws CompilationException {
         // Careful, we should only do this after analyzing the graph of function
         // calls.
         Pair<Boolean, Expression> p = inlineUdfsInExpr(fd.getFuncBody(), arg);
@@ -103,14 +103,14 @@
     }
 
     @Override
-    public Boolean visit(ListConstructor lc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(ListConstructor lc, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, List<Expression>> p = inlineUdfsInExprList(lc.getExprList(), arg);
         lc.setExprList(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(RecordConstructor rc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(RecordConstructor rc, List<FunctionDecl> arg) throws CompilationException {
         boolean changed = false;
         for (FieldBinding b : rc.getFbList()) {
             Pair<Boolean, Expression> leftExprInlined = inlineUdfsInExpr(b.getLeftExpr(), arg);
@@ -124,35 +124,35 @@
     }
 
     @Override
-    public Boolean visit(CallExpr pf, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(CallExpr pf, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, List<Expression>> p = inlineUdfsInExprList(pf.getExprList(), arg);
         pf.setExprList(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(OperatorExpr ifbo, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(OperatorExpr ifbo, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, List<Expression>> p = inlineUdfsInExprList(ifbo.getExprList(), arg);
         ifbo.setExprList(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(FieldAccessor fa, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(FieldAccessor fa, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(fa.getExpr(), arg);
         fa.setExpr(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(IndexAccessor fa, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(IndexAccessor fa, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(fa.getExpr(), arg);
         fa.setExpr(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(IfExpr ifexpr, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(IfExpr ifexpr, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, Expression> p1 = inlineUdfsInExpr(ifexpr.getCondExpr(), arg);
         ifexpr.setCondExpr(p1.second);
         Pair<Boolean, Expression> p2 = inlineUdfsInExpr(ifexpr.getThenExpr(), arg);
@@ -163,7 +163,7 @@
     }
 
     @Override
-    public Boolean visit(QuantifiedExpression qe, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(QuantifiedExpression qe, List<FunctionDecl> arg) throws CompilationException {
         boolean changed = false;
         for (QuantifiedPair t : qe.getQuantifiedList()) {
             Pair<Boolean, Expression> p = inlineUdfsInExpr(t.getExpr(), arg);
@@ -178,28 +178,28 @@
     }
 
     @Override
-    public Boolean visit(LetClause lc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(LetClause lc, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(lc.getBindingExpr(), arg);
         lc.setBindingExpr(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(WhereClause wc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(WhereClause wc, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(wc.getWhereExpr(), arg);
         wc.setWhereExpr(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(OrderbyClause oc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(OrderbyClause oc, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, List<Expression>> p = inlineUdfsInExprList(oc.getOrderbyList(), arg);
         oc.setOrderbyList(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(GroupbyClause gc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(GroupbyClause gc, List<FunctionDecl> arg) throws CompilationException {
         boolean changed = false;
         for (GbyVariableExpressionPair p : gc.getGbyPairList()) {
             Pair<Boolean, Expression> be = inlineUdfsInExpr(p.getExpr(), arg);
@@ -219,7 +219,7 @@
     }
 
     @Override
-    public Boolean visit(LimitClause lc, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(LimitClause lc, List<FunctionDecl> arg) throws CompilationException {
         Pair<Boolean, Expression> p1 = inlineUdfsInExpr(lc.getLimitExpr(), arg);
         lc.setLimitExpr(p1.second);
         boolean changed = p1.first;
@@ -232,22 +232,22 @@
     }
 
     @Override
-    public Boolean visit(UnaryExpr u, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(UnaryExpr u, List<FunctionDecl> arg) throws CompilationException {
         return u.getExpr().accept(this, arg);
     }
 
     @Override
-    public Boolean visit(VariableExpr v, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(VariableExpr v, List<FunctionDecl> arg) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(LiteralExpr l, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(LiteralExpr l, List<FunctionDecl> arg) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(InsertStatement insert, List<FunctionDecl> arg) throws AsterixException {
+    public Boolean visit(InsertStatement insert, List<FunctionDecl> arg) throws CompilationException {
         boolean changed = false;
         Expression returnExpression = insert.getReturnExpression();
         if (returnExpression != null) {
@@ -261,7 +261,7 @@
     }
 
     protected Pair<Boolean, Expression> inlineUdfsInExpr(Expression expr, List<FunctionDecl> arg)
-            throws AsterixException {
+            throws CompilationException {
         if (expr.getKind() != Kind.CALL_EXPRESSION) {
             boolean r = expr.accept(this, arg);
             return new Pair<>(r, expr);
@@ -308,7 +308,7 @@
     }
 
     protected Pair<Boolean, List<Expression>> inlineUdfsInExprList(List<Expression> exprList, List<FunctionDecl> fds)
-            throws AsterixException {
+            throws CompilationException {
         ArrayList<Expression> newList = new ArrayList<>();
         boolean changed = false;
         for (Expression e : exprList) {
@@ -321,7 +321,7 @@
         return new Pair<>(changed, newList);
     }
 
-    protected Expression rewriteFunctionBody(Expression expr) throws AsterixException {
+    protected Expression rewriteFunctionBody(Expression expr) throws CompilationException {
         Query wrappedQuery = new Query(false);
         wrappedQuery.setBody(expr);
         wrappedQuery.setTopLevel(false);
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java
index 3fdb141..9b419f1 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/CloneAndSubstituteVariablesVisitor.java
@@ -24,7 +24,7 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Expression.Kind;
 import org.apache.asterix.lang.common.base.ILangExpression;
@@ -68,7 +68,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LetClause lc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = lc.getBindingExpr().accept(this, env);
         VariableExpr varExpr = lc.getVarExpr();
         VariableExpr newVe = generateNewVariable(context, varExpr);
@@ -78,7 +78,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(GroupbyClause gc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         VariableSubstitutionEnvironment newSubs = env;
         List<GbyVariableExpressionPair> newGbyList =
                 VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getGbyPairList(), newSubs, this);
@@ -112,7 +112,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(QuantifiedExpression qe,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<QuantifiedPair> oldPairs = qe.getQuantifiedList();
         List<QuantifiedPair> newPairs = new ArrayList<>(oldPairs.size());
         VariableSubstitutionEnvironment newSubs = env;
@@ -131,7 +131,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(WhereClause wc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = wc.getWhereExpr().accept(this, env);
         WhereClause newW = new WhereClause((Expression) p1.first);
         return new Pair<>(newW, p1.second);
@@ -139,7 +139,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(CallExpr pf,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<Expression> exprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(pf.getExprList(), env, this);
         CallExpr f = new CallExpr(pf.getFunctionSignature(), exprList);
         return new Pair<>(f, env);
@@ -147,16 +147,17 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FunctionDecl fd,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<VarIdentifier> newList = new ArrayList<>(fd.getParamList().size());
         for (VarIdentifier vi : fd.getParamList()) {
             VariableExpr varExpr = new VariableExpr(vi);
             if (!env.constainsOldVar(varExpr)) {
-                throw new AsterixException("Parameter " + vi + " does not appear in the substitution list.");
+                throw new CompilationException("Parameter " + vi + " does not appear in the substitution list.");
             }
             Expression newExpr = env.findSubstitution(varExpr);
             if (newExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
-                throw new AsterixException("Parameter " + vi + " cannot be substituted by a non-variable expression.");
+                throw new CompilationException(
+                        "Parameter " + vi + " cannot be substituted by a non-variable expression.");
             }
             newList.add(((VariableExpr) newExpr).getVar());
         }
@@ -168,7 +169,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(IfExpr ifexpr,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = ifexpr.getCondExpr().accept(this, env);
         Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = ifexpr.getThenExpr().accept(this, env);
         Pair<ILangExpression, VariableSubstitutionEnvironment> p3 = ifexpr.getElseExpr().accept(this, env);
@@ -178,7 +179,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LimitClause lc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = lc.getLimitExpr().accept(this, env);
         Pair<ILangExpression, VariableSubstitutionEnvironment> p2;
         Expression lcOffsetExpr = lc.getOffset();
@@ -193,7 +194,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(ListConstructor lc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<Expression> oldExprList = lc.getExprList();
         List<Expression> exprs = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(oldExprList, env, this);
         ListConstructor c = new ListConstructor(lc.getType(), exprs);
@@ -202,13 +203,13 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LiteralExpr l,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         return new Pair<>(l, env);
     }
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(OperatorExpr op,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<Expression> oldExprList = op.getExprList();
         List<Expression> exprs = new ArrayList<>(oldExprList.size());
         for (Expression e : oldExprList) {
@@ -221,7 +222,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(OrderbyClause oc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<Expression> exprList =
                 VariableCloneAndSubstitutionUtil.visitAndCloneExprList(oc.getOrderbyList(), env, this);
         OrderbyClause oc2 = new OrderbyClause(exprList, oc.getModifierList());
@@ -233,7 +234,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(Query q, VariableSubstitutionEnvironment env)
-            throws AsterixException {
+            throws CompilationException {
         Query newQ = new Query(q.isExplain());
         Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = q.getBody().accept(this, env);
         newQ.setBody((Expression) p1.first);
@@ -242,7 +243,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(RecordConstructor rc,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<FieldBinding> oldFbs = rc.getFbList();
         ArrayList<FieldBinding> newFbs = new ArrayList<>(oldFbs.size());
         for (FieldBinding fb : oldFbs) {
@@ -257,7 +258,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(UnaryExpr u,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = u.getExpr().accept(this, env);
         UnaryExpr newU = new UnaryExpr(u.getExprType(), (Expression) p1.first);
         return new Pair<>(newU, env);
@@ -265,7 +266,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(IndexAccessor ia,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = ia.getExpr().accept(this, env);
         Expression indexExpr = null;
         if (!ia.isAny()) {
@@ -279,7 +280,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FieldAccessor fa,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p = fa.getExpr().accept(this, env);
         FieldAccessor newF = new FieldAccessor((Expression) p.first, fa.getIdent());
         return new Pair<>(newF, p.second);
@@ -287,13 +288,13 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(VariableExpr v,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         return new Pair<>(rewriteVariableExpr(v, env), env);
     }
 
     // Replace a variable expression if the variable is to-be substituted.
     protected Expression rewriteVariableExpr(VariableExpr expr, VariableSubstitutionEnvironment env)
-            throws AsterixException {
+            throws CompilationException {
         if (env.constainsOldVar(expr)) {
             return env.findSubstitution(expr);
         } else {
@@ -329,10 +330,10 @@
      * @param env,
      *            the variable substitution environment.
      * @return a pair of an ILangExpression and a variable substitution environment.
-     * @throws AsterixException
+     * @throws CompilationException
      */
     protected Pair<ILangExpression, VariableSubstitutionEnvironment> visitUnnesBindingExpression(Expression expr,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         return expr.accept(this, env);
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java
index 7a96fac..eefed9d 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/FormatPrintVisitor.java
@@ -30,7 +30,7 @@
 
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
 import org.apache.asterix.common.config.DatasetConfig.IndexType;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Literal;
@@ -145,7 +145,7 @@
     }
 
     @Override
-    public Void visit(Query q, Integer step) throws AsterixException {
+    public Void visit(Query q, Integer step) throws CompilationException {
         if (q.getBody() != null) {
             q.getBody().accept(this, step);
         }
@@ -185,7 +185,7 @@
     }
 
     @Override
-    public Void visit(ListConstructor lc, Integer step) throws AsterixException {
+    public Void visit(ListConstructor lc, Integer step) throws CompilationException {
         boolean ordered = false;
         if (lc.getType().equals(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR)) {
             ordered = true;
@@ -197,7 +197,7 @@
     }
 
     @Override
-    public Void visit(RecordConstructor rc, Integer step) throws AsterixException {
+    public Void visit(RecordConstructor rc, Integer step) throws CompilationException {
         out.print("{");
         // print all field bindings
         int size = rc.getFbList().size();
@@ -215,7 +215,7 @@
     }
 
     @Override
-    public Void visit(CallExpr callExpr, Integer step) throws AsterixException {
+    public Void visit(CallExpr callExpr, Integer step) throws CompilationException {
         printHints(callExpr.getHints(), step);
         out.print(generateFullName(callExpr.getFunctionSignature().getNamespace(),
                 callExpr.getFunctionSignature().getName()) + "(");
@@ -225,7 +225,7 @@
     }
 
     @Override
-    public Void visit(OperatorExpr operatorExpr, Integer step) throws AsterixException {
+    public Void visit(OperatorExpr operatorExpr, Integer step) throws CompilationException {
         List<Expression> exprList = operatorExpr.getExprList();
         List<OperatorType> opList = operatorExpr.getOpList();
         if (operatorExpr.isCurrentop()) {
@@ -247,7 +247,7 @@
     }
 
     @Override
-    public Void visit(IfExpr ifexpr, Integer step) throws AsterixException {
+    public Void visit(IfExpr ifexpr, Integer step) throws CompilationException {
         out.print("if (");
         ifexpr.getCondExpr().accept(this, step + 2);
         out.println(")");
@@ -260,7 +260,7 @@
     }
 
     @Override
-    public Void visit(QuantifiedExpression qe, Integer step) throws AsterixException {
+    public Void visit(QuantifiedExpression qe, Integer step) throws CompilationException {
         out.print(qe.getQuantifier().toString().toLowerCase() + " ");
         // quantifiedList accept visitor
         int index = 0;
@@ -279,7 +279,7 @@
     }
 
     @Override
-    public Void visit(LetClause lc, Integer step) throws AsterixException {
+    public Void visit(LetClause lc, Integer step) throws CompilationException {
         out.print(skip(step) + "let ");
         lc.getVarExpr().accept(this, 0);
         out.print(assignSymbol);
@@ -289,7 +289,7 @@
     }
 
     @Override
-    public Void visit(WhereClause wc, Integer step) throws AsterixException {
+    public Void visit(WhereClause wc, Integer step) throws CompilationException {
         out.print(skip(step) + "where ");
         wc.getWhereExpr().accept(this, step + 1);
         out.println();
@@ -297,7 +297,7 @@
     }
 
     @Override
-    public Void visit(OrderbyClause oc, Integer step) throws AsterixException {
+    public Void visit(OrderbyClause oc, Integer step) throws CompilationException {
         out.print(skip(step) + "order by ");
         List<OrderModifier> mlist = oc.getModifierList();
         List<Expression> list = oc.getOrderbyList();
@@ -318,7 +318,7 @@
     }
 
     @Override
-    public Void visit(GroupbyClause gc, Integer step) throws AsterixException {
+    public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
         if (gc.hasHashGroupByHint()) {
             out.println(skip(step) + "/* +hash */");
         }
@@ -351,7 +351,7 @@
     }
 
     @Override
-    public Void visit(LimitClause lc, Integer step) throws AsterixException {
+    public Void visit(LimitClause lc, Integer step) throws CompilationException {
         out.print(skip(step) + "limit ");
         lc.getLimitExpr().accept(this, step + 1);
         if (lc.getOffset() != null) {
@@ -363,7 +363,7 @@
     }
 
     @Override
-    public Void visit(FunctionDecl fd, Integer step) throws AsterixException {
+    public Void visit(FunctionDecl fd, Integer step) throws CompilationException {
         out.print(skip(step) + "declare function " + generateFullName(null, fd.getSignature().getName()) + "(");
         List<Identifier> parameters = new ArrayList<Identifier>();
         parameters.addAll(fd.getParamList());
@@ -377,21 +377,21 @@
     }
 
     @Override
-    public Void visit(UnaryExpr u, Integer step) throws AsterixException {
+    public Void visit(UnaryExpr u, Integer step) throws CompilationException {
         out.print(u.getExprType() == UnaryExprType.NEGATIVE ? "-" : "");
         u.getExpr().accept(this, 0);
         return null;
     }
 
     @Override
-    public Void visit(FieldAccessor fa, Integer step) throws AsterixException {
+    public Void visit(FieldAccessor fa, Integer step) throws CompilationException {
         fa.getExpr().accept(this, step + 1);
         out.print("." + normalize(fa.getIdent().getValue()));
         return null;
     }
 
     @Override
-    public Void visit(IndexAccessor fa, Integer step) throws AsterixException {
+    public Void visit(IndexAccessor fa, Integer step) throws CompilationException {
         fa.getExpr().accept(this, step + 1);
         out.print("[");
         if (fa.isAny()) {
@@ -404,7 +404,7 @@
     }
 
     @Override
-    public Void visit(TypeDecl t, Integer step) throws AsterixException {
+    public Void visit(TypeDecl t, Integer step) throws CompilationException {
         out.println(skip(step) + "create type " + generateFullName(t.getDataverseName(), t.getIdent())
                 + generateIfNotExists(t.getIfNotExists()) + " as");
         t.getTypeDef().accept(this, step + 1);
@@ -413,7 +413,7 @@
     }
 
     @Override
-    public Void visit(TypeReferenceExpression t, Integer arg) throws AsterixException {
+    public Void visit(TypeReferenceExpression t, Integer arg) throws CompilationException {
         if (t.getIdent().first != null && t.getIdent().first.getValue() != null) {
             out.print(normalize(t.getIdent().first.getValue()));
             out.print('.');
@@ -423,7 +423,7 @@
     }
 
     @Override
-    public Void visit(RecordTypeDefinition r, Integer step) throws AsterixException {
+    public Void visit(RecordTypeDefinition r, Integer step) throws CompilationException {
         if (r.getRecordKind() == RecordKind.CLOSED) {
             out.print(" closed ");
         }
@@ -454,7 +454,7 @@
     }
 
     @Override
-    public Void visit(OrderedListTypeDefinition x, Integer step) throws AsterixException {
+    public Void visit(OrderedListTypeDefinition x, Integer step) throws CompilationException {
         out.print("[");
         x.getItemTypeExpression().accept(this, step + 2);
         out.print("]");
@@ -462,7 +462,7 @@
     }
 
     @Override
-    public Void visit(UnorderedListTypeDefinition x, Integer step) throws AsterixException {
+    public Void visit(UnorderedListTypeDefinition x, Integer step) throws CompilationException {
         out.print("{{");
         x.getItemTypeExpression().accept(this, step + 2);
         out.print("}}");
@@ -470,7 +470,7 @@
     }
 
     @Override
-    public Void visit(DatasetDecl dd, Integer step) throws AsterixException {
+    public Void visit(DatasetDecl dd, Integer step) throws CompilationException {
         if (dd.getDatasetType() == DatasetType.INTERNAL) {
             String temp = dd.getDatasetDetailsDecl().isTemp() ? "temporary" : "";
             out.print(skip(step) + "create " + temp + datasetSymbol + generateFullName(dd.getDataverse(), dd.getName())
@@ -518,13 +518,13 @@
     }
 
     @Override
-    public Void visit(DataverseDecl dv, Integer step) throws AsterixException {
+    public Void visit(DataverseDecl dv, Integer step) throws CompilationException {
         out.println(skip(step) + "use " + dataverseSymbol + normalize(dv.getDataverseName().getValue()) + ";\n\n");
         return null;
     }
 
     @Override
-    public Void visit(WriteStatement ws, Integer step) throws AsterixException {
+    public Void visit(WriteStatement ws, Integer step) throws CompilationException {
         out.print(skip(step) + "write output to " + ws.getNcName() + ":" + revertStringToQuoted(ws.getFileName()));
         if (ws.getWriterClassName() != null) {
             out.print(" using " + ws.getWriterClassName());
@@ -534,21 +534,21 @@
     }
 
     @Override
-    public Void visit(SetStatement ss, Integer step) throws AsterixException {
+    public Void visit(SetStatement ss, Integer step) throws CompilationException {
         out.println(skip(step) + "set " + revertStringToQuoted(ss.getPropName()) + " "
                 + revertStringToQuoted(ss.getPropValue()) + ";\n");
         return null;
     }
 
     @Override
-    public Void visit(DisconnectFeedStatement ss, Integer step) throws AsterixException {
+    public Void visit(DisconnectFeedStatement ss, Integer step) throws CompilationException {
         out.println(skip(step) + "disconnect " + FEED + generateFullName(ss.getDataverseName(), ss.getFeedName())
                 + " from " + datasetSymbol + generateFullName(ss.getDataverseName(), ss.getDatasetName()) + ";");
         return null;
     }
 
     @Override
-    public Void visit(NodegroupDecl ngd, Integer step) throws AsterixException {
+    public Void visit(NodegroupDecl ngd, Integer step) throws CompilationException {
         out.println(
                 CREATE + " nodegroup " + ngd.getNodegroupName() + generateIfNotExists(ngd.getIfNotExists()) + " on ");
         out.print(skip(step + 2));
@@ -559,7 +559,7 @@
     }
 
     @Override
-    public Void visit(LoadStatement stmtLoad, Integer step) throws AsterixException {
+    public Void visit(LoadStatement stmtLoad, Integer step) throws CompilationException {
         out.print(skip(step) + "load " + datasetSymbol
                 + generateFullName(stmtLoad.getDataverseName(), stmtLoad.getDatasetName()) + " using "
                 + revertStringToQuoted(stmtLoad.getAdapter()) + " ");
@@ -570,7 +570,7 @@
     }
 
     @Override
-    public Void visit(DropDatasetStatement del, Integer step) throws AsterixException {
+    public Void visit(DropDatasetStatement del, Integer step) throws CompilationException {
         out.println(
                 skip(step) + "drop " + datasetSymbol + generateFullName(del.getDataverseName(), del.getDatasetName())
                         + generateIfExists(del.getIfExists()) + SEMICOLON);
@@ -578,7 +578,7 @@
     }
 
     @Override
-    public Void visit(InsertStatement insert, Integer step) throws AsterixException {
+    public Void visit(InsertStatement insert, Integer step) throws CompilationException {
         out.print(skip(step) + "insert into " + datasetSymbol
                 + generateFullName(insert.getDataverseName(), insert.getDatasetName()));
         out.print("(");
@@ -589,7 +589,7 @@
     }
 
     @Override
-    public Void visit(DeleteStatement del, Integer step) throws AsterixException {
+    public Void visit(DeleteStatement del, Integer step) throws CompilationException {
         out.print(skip(step) + "delete ");
         del.getVariableExpr().accept(this, step + 2);
         out.println(
@@ -603,7 +603,7 @@
     }
 
     @Override
-    public Void visit(UpdateStatement update, Integer step) throws AsterixException {
+    public Void visit(UpdateStatement update, Integer step) throws CompilationException {
         out.println(skip(step) + "update ");
         update.getVariableExpr().accept(this, step + 2);
         out.print(" in ");
@@ -623,7 +623,7 @@
     }
 
     @Override
-    public Void visit(UpdateClause del, Integer step) throws AsterixException {
+    public Void visit(UpdateClause del, Integer step) throws CompilationException {
         if (del.hasSet()) {
             out.println(skip(step) + "set ");
             del.getTarget().accept(this, step + 2);
@@ -654,7 +654,7 @@
     }
 
     @Override
-    public Void visit(CreateIndexStatement cis, Integer step) throws AsterixException {
+    public Void visit(CreateIndexStatement cis, Integer step) throws CompilationException {
         out.print(skip(step) + CREATE + " index ");
         out.print(normalize(cis.getIndexName().getValue()) + " ");
         out.print(generateIfNotExists(cis.getIfNotExists()));
@@ -691,7 +691,7 @@
     }
 
     @Override
-    public Void visit(CreateDataverseStatement del, Integer step) throws AsterixException {
+    public Void visit(CreateDataverseStatement del, Integer step) throws CompilationException {
         out.print(CREATE + dataverseSymbol);
         out.print(normalize(del.getDataverseName().getValue()));
         out.print(generateIfNotExists(del.getIfNotExists()));
@@ -706,7 +706,7 @@
     }
 
     @Override
-    public Void visit(IndexDropStatement del, Integer step) throws AsterixException {
+    public Void visit(IndexDropStatement del, Integer step) throws CompilationException {
         out.print(skip(step) + "drop index ");
         out.print(generateFullName(del.getDataverseName(), del.getDatasetName()));
         out.print("." + del.getIndexName());
@@ -715,7 +715,7 @@
     }
 
     @Override
-    public Void visit(NodeGroupDropStatement del, Integer step) throws AsterixException {
+    public Void visit(NodeGroupDropStatement del, Integer step) throws CompilationException {
         out.print(skip(step) + "drop nodegroup ");
         out.print(del.getNodeGroupName());
         out.println(generateIfExists(del.getIfExists()) + SEMICOLON);
@@ -723,7 +723,7 @@
     }
 
     @Override
-    public Void visit(DataverseDropStatement del, Integer step) throws AsterixException {
+    public Void visit(DataverseDropStatement del, Integer step) throws CompilationException {
         out.print(skip(step) + "drop " + dataverseSymbol);
         out.print(normalize(del.getDataverseName().getValue()));
         out.println(generateIfExists(del.getIfExists()) + SEMICOLON);
@@ -731,7 +731,7 @@
     }
 
     @Override
-    public Void visit(TypeDropStatement del, Integer step) throws AsterixException {
+    public Void visit(TypeDropStatement del, Integer step) throws CompilationException {
         out.print(skip(step) + "drop type ");
         out.print(generateFullName(del.getDataverseName(), del.getTypeName()));
         out.println(generateIfExists(del.getIfExists()) + SEMICOLON);
@@ -739,7 +739,7 @@
     }
 
     @Override
-    public Void visit(ConnectFeedStatement connectFeedStmt, Integer step) throws AsterixException {
+    public Void visit(ConnectFeedStatement connectFeedStmt, Integer step) throws CompilationException {
         out.print(skip(step) + "connect " + FEED);
         out.print(generateFullName(connectFeedStmt.getDataverseName(), new Identifier(connectFeedStmt.getFeedName())));
         out.print(" to " + datasetSymbol
@@ -752,7 +752,7 @@
     }
 
     @Override
-    public Void visit(CreatePrimaryFeedStatement cpfs, Integer step) throws AsterixException {
+    public Void visit(CreatePrimaryFeedStatement cpfs, Integer step) throws CompilationException {
         out.print(skip(step) + CREATE + " primary feed ");
         out.print(generateFullName(cpfs.getDataverseName(), cpfs.getFeedName()));
         out.print(generateIfNotExists(cpfs.getIfNotExists()));
@@ -767,7 +767,7 @@
     }
 
     @Override
-    public Void visit(CreateSecondaryFeedStatement csfs, Integer step) throws AsterixException {
+    public Void visit(CreateSecondaryFeedStatement csfs, Integer step) throws CompilationException {
         out.print(skip(step) + CREATE + " secondary feed ");
         out.print(generateFullName(csfs.getDataverseName(), csfs.getFeedName()));
         out.print(generateIfNotExists(csfs.getIfNotExists()));
@@ -781,7 +781,7 @@
     }
 
     @Override
-    public Void visit(FeedDropStatement del, Integer step) throws AsterixException {
+    public Void visit(FeedDropStatement del, Integer step) throws CompilationException {
         out.print(skip(step) + "drop " + FEED);
         out.print(generateFullName(del.getDataverseName(), del.getFeedName()));
         out.println(generateIfExists(del.getIfExists()) + SEMICOLON);
@@ -789,12 +789,12 @@
     }
 
     @Override
-    public Void visit(FeedPolicyDropStatement dfs, Integer step) throws AsterixException {
+    public Void visit(FeedPolicyDropStatement dfs, Integer step) throws CompilationException {
         return null;
     }
 
     @Override
-    public Void visit(CreateFeedPolicyStatement cfps, Integer step) throws AsterixException {
+    public Void visit(CreateFeedPolicyStatement cfps, Integer step) throws CompilationException {
         out.print(skip(step) + CREATE + "ingestion policy ");
         out.print(cfps.getPolicyName());
         out.print(generateIfNotExists(cfps.getIfNotExists()));
@@ -820,7 +820,7 @@
     }
 
     @Override
-    public Void visit(CreateFunctionStatement cfs, Integer step) throws AsterixException {
+    public Void visit(CreateFunctionStatement cfs, Integer step) throws CompilationException {
         out.print(skip(step) + CREATE + " function ");
         out.print(generateIfNotExists(cfs.getIfNotExists()));
         out.print(this.generateFullName(cfs.getSignature().getNamespace(), cfs.getSignature().getName()));
@@ -834,7 +834,7 @@
     }
 
     @Override
-    public Void visit(FunctionDropStatement del, Integer step) throws AsterixException {
+    public Void visit(FunctionDropStatement del, Integer step) throws CompilationException {
         out.print(skip(step) + "drop function ");
         FunctionSignature funcSignature = del.getFunctionSignature();
         out.print(funcSignature.toString());
@@ -843,7 +843,7 @@
     }
 
     @Override
-    public Void visit(CompactStatement del, Integer step) throws AsterixException {
+    public Void visit(CompactStatement del, Integer step) throws CompilationException {
         return null;
     }
 
@@ -883,7 +883,7 @@
     }
 
     protected void printDelimitedGbyExpressions(List<GbyVariableExpressionPair> gbyList, int step)
-            throws AsterixException {
+            throws CompilationException {
         int gbySize = gbyList.size();
         int gbyIndex = 0;
         for (GbyVariableExpressionPair pair : gbyList) {
@@ -899,7 +899,7 @@
     }
 
     protected void printDelimitedExpressions(List<? extends Expression> exprs, String delimiter, int step)
-            throws AsterixException {
+            throws CompilationException {
         int index = 0;
         int size = exprs.size();
         for (Expression expr : exprs) {
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java
index 12c95bb..8842d86 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java
@@ -22,7 +22,7 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
@@ -56,7 +56,7 @@
     protected final Set<FunctionSignature> calls = new HashSet<FunctionSignature>();
 
     @Override
-    public Void visit(CallExpr pf, Void arg) throws AsterixException {
+    public Void visit(CallExpr pf, Void arg) throws CompilationException {
         calls.add(pf.getFunctionSignature());
         for (Expression e : pf.getExprList()) {
             e.accept(this, arg);
@@ -65,13 +65,13 @@
     }
 
     @Override
-    public Void visit(FieldAccessor fa, Void arg) throws AsterixException {
+    public Void visit(FieldAccessor fa, Void arg) throws CompilationException {
         fa.getExpr().accept(this, arg);
         return null;
     }
 
     @Override
-    public Void visit(GroupbyClause gc, Void arg) throws AsterixException {
+    public Void visit(GroupbyClause gc, Void arg) throws CompilationException {
         for (GbyVariableExpressionPair p : gc.getGbyPairList()) {
             p.getExpr().accept(this, arg);
         }
@@ -82,7 +82,7 @@
     }
 
     @Override
-    public Void visit(IfExpr ifexpr, Void arg) throws AsterixException {
+    public Void visit(IfExpr ifexpr, Void arg) throws CompilationException {
         ifexpr.getCondExpr().accept(this, arg);
         ifexpr.getThenExpr().accept(this, arg);
         ifexpr.getElseExpr().accept(this, arg);
@@ -90,19 +90,19 @@
     }
 
     @Override
-    public Void visit(IndexAccessor ia, Void arg) throws AsterixException {
+    public Void visit(IndexAccessor ia, Void arg) throws CompilationException {
         ia.getExpr().accept(this, arg);
         return null;
     }
 
     @Override
-    public Void visit(LetClause lc, Void arg) throws AsterixException {
+    public Void visit(LetClause lc, Void arg) throws CompilationException {
         lc.getBindingExpr().accept(this, arg);
         return null;
     }
 
     @Override
-    public Void visit(LimitClause lc, Void arg) throws AsterixException {
+    public Void visit(LimitClause lc, Void arg) throws CompilationException {
         lc.getLimitExpr().accept(this, arg);
         if (lc.getOffset() != null) {
             lc.getOffset().accept(this, arg);
@@ -111,7 +111,7 @@
     }
 
     @Override
-    public Void visit(ListConstructor lc, Void arg) throws AsterixException {
+    public Void visit(ListConstructor lc, Void arg) throws CompilationException {
         for (Expression e : lc.getExprList()) {
             e.accept(this, arg);
         }
@@ -119,13 +119,13 @@
     }
 
     @Override
-    public Void visit(LiteralExpr l, Void arg) throws AsterixException {
+    public Void visit(LiteralExpr l, Void arg) throws CompilationException {
         // do nothing
         return null;
     }
 
     @Override
-    public Void visit(OperatorExpr op, Void arg) throws AsterixException {
+    public Void visit(OperatorExpr op, Void arg) throws CompilationException {
         for (Expression e : op.getExprList()) {
             e.accept(this, arg);
         }
@@ -133,7 +133,7 @@
     }
 
     @Override
-    public Void visit(OrderbyClause oc, Void arg) throws AsterixException {
+    public Void visit(OrderbyClause oc, Void arg) throws CompilationException {
         for (Expression e : oc.getOrderbyList()) {
             e.accept(this, arg);
         }
@@ -141,12 +141,12 @@
     }
 
     @Override
-    public Void visit(OrderedListTypeDefinition olte, Void arg) throws AsterixException {
+    public Void visit(OrderedListTypeDefinition olte, Void arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public Void visit(QuantifiedExpression qe, Void arg) throws AsterixException {
+    public Void visit(QuantifiedExpression qe, Void arg) throws CompilationException {
         for (QuantifiedPair qp : qe.getQuantifiedList()) {
             qp.getExpr().accept(this, arg);
         }
@@ -155,13 +155,13 @@
     }
 
     @Override
-    public Void visit(Query q, Void arg) throws AsterixException {
+    public Void visit(Query q, Void arg) throws CompilationException {
         q.getBody().accept(this, arg);
         return null;
     }
 
     @Override
-    public Void visit(RecordConstructor rc, Void arg) throws AsterixException {
+    public Void visit(RecordConstructor rc, Void arg) throws CompilationException {
         for (FieldBinding fb : rc.getFbList()) {
             fb.getLeftExpr().accept(this, arg);
             fb.getRightExpr().accept(this, arg);
@@ -170,30 +170,30 @@
     }
 
     @Override
-    public Void visit(TypeReferenceExpression tre, Void arg) throws AsterixException {
+    public Void visit(TypeReferenceExpression tre, Void arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public Void visit(UnaryExpr u, Void arg) throws AsterixException {
+    public Void visit(UnaryExpr u, Void arg) throws CompilationException {
         u.getExpr().accept(this, arg);
         return null;
     }
 
     @Override
-    public Void visit(VariableExpr v, Void arg) throws AsterixException {
+    public Void visit(VariableExpr v, Void arg) throws CompilationException {
         // do nothing
         return null;
     }
 
     @Override
-    public Void visit(WhereClause wc, Void arg) throws AsterixException {
+    public Void visit(WhereClause wc, Void arg) throws CompilationException {
         wc.getWhereExpr().accept(this, arg);
         return null;
     }
 
     @Override
-    public Void visit(InsertStatement wc, Void arg) throws AsterixException {
+    public Void visit(InsertStatement wc, Void arg) throws CompilationException {
         wc.getQuery().accept(this, arg);
         Expression returnExpression = wc.getReturnExpression();
         if (returnExpression != null) {
@@ -207,7 +207,7 @@
     }
 
     @Override
-    public Void visit(FunctionDecl fd, Void arg) throws AsterixException {
+    public Void visit(FunctionDecl fd, Void arg) throws CompilationException {
         return null;
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/QueryPrintVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/QueryPrintVisitor.java
index e7cf43b..5e01321 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/QueryPrintVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/QueryPrintVisitor.java
@@ -24,7 +24,7 @@
 import java.util.Map.Entry;
 
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Literal;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
@@ -85,7 +85,7 @@
     }
 
     @Override
-    public Void visit(Query q, Integer step) throws AsterixException {
+    public Void visit(Query q, Integer step) throws CompilationException {
         if (q.getBody() != null) {
             out.println("Query:");
             q.getBody().accept(this, step);
@@ -115,7 +115,7 @@
     }
 
     @Override
-    public Void visit(ListConstructor lc, Integer step) throws AsterixException {
+    public Void visit(ListConstructor lc, Integer step) throws CompilationException {
         boolean ordered = false;
         if (lc.getType().equals(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR)) {
             ordered = true;
@@ -130,7 +130,7 @@
     }
 
     @Override
-    public Void visit(RecordConstructor rc, Integer step) throws AsterixException {
+    public Void visit(RecordConstructor rc, Integer step) throws CompilationException {
         out.println(skip(step) + "RecordConstructor [");
         // fbList accept visitor
         for (FieldBinding fb : rc.getFbList()) {
@@ -145,7 +145,7 @@
     }
 
     @Override
-    public Void visit(CallExpr pf, Integer step) throws AsterixException {
+    public Void visit(CallExpr pf, Integer step) throws CompilationException {
         out.println(skip(step) + "FunctionCall " + pf.getFunctionSignature().toString() + "[");
         for (Expression expr : pf.getExprList()) {
             expr.accept(this, step + 1);
@@ -155,7 +155,7 @@
     }
 
     @Override
-    public Void visit(OperatorExpr ifbo, Integer step) throws AsterixException {
+    public Void visit(OperatorExpr ifbo, Integer step) throws CompilationException {
         List<Expression> exprList = ifbo.getExprList();
         List<OperatorType> opList = ifbo.getOpList();
         if (ifbo.isCurrentop()) {
@@ -173,7 +173,7 @@
     }
 
     @Override
-    public Void visit(IfExpr ifexpr, Integer step) throws AsterixException {
+    public Void visit(IfExpr ifexpr, Integer step) throws CompilationException {
         out.println(skip(step) + "IfExpr [");
         out.println(skip(step + 1) + "Condition:");
         ifexpr.getCondExpr().accept(this, step + 2);
@@ -186,7 +186,7 @@
     }
 
     @Override
-    public Void visit(QuantifiedExpression qe, Integer step) throws AsterixException {
+    public Void visit(QuantifiedExpression qe, Integer step) throws CompilationException {
         out.println(skip(step) + "QuantifiedExpression " + qe.getQuantifier() + " [");
         // quantifiedList accept visitor
         for (QuantifiedPair pair : qe.getQuantifiedList()) {
@@ -204,7 +204,7 @@
     }
 
     @Override
-    public Void visit(LetClause lc, Integer step) throws AsterixException {
+    public Void visit(LetClause lc, Integer step) throws CompilationException {
         out.print(skip(step) + "Let ");
         lc.getVarExpr().accept(this, 0);
         out.println(skip(step + 1) + ":=");
@@ -213,14 +213,14 @@
     }
 
     @Override
-    public Void visit(WhereClause wc, Integer step) throws AsterixException {
+    public Void visit(WhereClause wc, Integer step) throws CompilationException {
         out.println(skip(step) + "Where");
         wc.getWhereExpr().accept(this, step + 1);
         return null;
     }
 
     @Override
-    public Void visit(OrderbyClause oc, Integer step) throws AsterixException {
+    public Void visit(OrderbyClause oc, Integer step) throws CompilationException {
         out.println(skip(step) + "Orderby");
         List<OrderModifier> mlist = oc.getModifierList();
         List<Expression> list = oc.getOrderbyList();
@@ -233,7 +233,7 @@
     }
 
     @Override
-    public Void visit(GroupbyClause gc, Integer step) throws AsterixException {
+    public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
         out.println(skip(step) + "Groupby");
         for (GbyVariableExpressionPair pair : gc.getGbyPairList()) {
             if (pair.getVar() != null) {
@@ -269,7 +269,7 @@
     }
 
     @Override
-    public Void visit(LimitClause lc, Integer step) throws AsterixException {
+    public Void visit(LimitClause lc, Integer step) throws CompilationException {
         out.println(skip(step) + "Limit");
         lc.getLimitExpr().accept(this, step + 1);
         if (lc.getOffset() != null) {
@@ -280,7 +280,7 @@
     }
 
     @Override
-    public Void visit(FunctionDecl fd, Integer step) throws AsterixException {
+    public Void visit(FunctionDecl fd, Integer step) throws CompilationException {
         out.println(skip(step) + "FunctionDecl " + fd.getSignature().getName() + "(" + fd.getParamList().toString()
                 + ") {");
         fd.getFuncBody().accept(this, step + 1);
@@ -290,7 +290,7 @@
     }
 
     @Override
-    public Void visit(UnaryExpr u, Integer step) throws AsterixException {
+    public Void visit(UnaryExpr u, Integer step) throws CompilationException {
         if (u.getExprType() != null) {
             out.print(skip(step) + u.getExprType() + " ");
             u.getExpr().accept(this, 0);
@@ -301,7 +301,7 @@
     }
 
     @Override
-    public Void visit(FieldAccessor fa, Integer step) throws AsterixException {
+    public Void visit(FieldAccessor fa, Integer step) throws CompilationException {
         out.println(skip(step) + "FieldAccessor [");
         fa.getExpr().accept(this, step + 1);
         out.println(skip(step + 1) + "Field=" + fa.getIdent().getValue());
@@ -310,7 +310,7 @@
     }
 
     @Override
-    public Void visit(IndexAccessor fa, Integer step) throws AsterixException {
+    public Void visit(IndexAccessor fa, Integer step) throws CompilationException {
         out.println(skip(step) + "IndexAccessor [");
         fa.getExpr().accept(this, step + 1);
         out.print(skip(step + 1) + "Index: ");
@@ -324,7 +324,7 @@
     }
 
     @Override
-    public Void visit(TypeDecl t, Integer step) throws AsterixException {
+    public Void visit(TypeDecl t, Integer step) throws CompilationException {
         out.println(skip(step) + "TypeDecl " + t.getIdent() + " [");
         t.getTypeDef().accept(this, step + 1);
         out.println(skip(step) + "]");
@@ -332,7 +332,7 @@
     }
 
     @Override
-    public Void visit(TypeReferenceExpression t, Integer arg) throws AsterixException {
+    public Void visit(TypeReferenceExpression t, Integer arg) throws CompilationException {
         if (t.getIdent().first != null && t.getIdent().first.getValue() != null) {
             out.print(t.getIdent().first.getValue());
             out.print('.');
@@ -342,7 +342,7 @@
     }
 
     @Override
-    public Void visit(RecordTypeDefinition r, Integer step) throws AsterixException {
+    public Void visit(RecordTypeDefinition r, Integer step) throws CompilationException {
         if (r.getRecordKind() == RecordKind.CLOSED) {
             out.print(skip(step) + "closed ");
         } else {
@@ -374,7 +374,7 @@
     }
 
     @Override
-    public Void visit(OrderedListTypeDefinition x, Integer step) throws AsterixException {
+    public Void visit(OrderedListTypeDefinition x, Integer step) throws CompilationException {
         out.print("OrderedList [");
         x.getItemTypeExpression().accept(this, step + 2);
         out.println("]");
@@ -382,7 +382,7 @@
     }
 
     @Override
-    public Void visit(UnorderedListTypeDefinition x, Integer step) throws AsterixException {
+    public Void visit(UnorderedListTypeDefinition x, Integer step) throws CompilationException {
         out.print("UnorderedList <");
         x.getItemTypeExpression().accept(this, step + 2);
         out.println(">");
@@ -390,7 +390,7 @@
     }
 
     @Override
-    public Void visit(DatasetDecl dd, Integer step) throws AsterixException {
+    public Void visit(DatasetDecl dd, Integer step) throws CompilationException {
         if (dd.getDatasetType() == DatasetType.INTERNAL) {
             String line = skip(step) + "DatasetDecl " + dd.getName() + "(" + dd.getItemTypeName() + ")"
                     + " partitioned by " + ((InternalDetailsDecl) dd.getDatasetDetailsDecl()).getPartitioningExprs();
@@ -406,13 +406,13 @@
     }
 
     @Override
-    public Void visit(DataverseDecl dv, Integer step) throws AsterixException {
+    public Void visit(DataverseDecl dv, Integer step) throws CompilationException {
         out.println(skip(step) + "DataverseUse " + dv.getDataverseName());
         return null;
     }
 
     @Override
-    public Void visit(WriteStatement ws, Integer step) throws AsterixException {
+    public Void visit(WriteStatement ws, Integer step) throws CompilationException {
         out.print(skip(step) + "WriteOutputTo " + ws.getNcName() + ":" + ws.getFileName());
         if (ws.getWriterClassName() != null) {
             out.print(" using " + ws.getWriterClassName());
@@ -422,13 +422,13 @@
     }
 
     @Override
-    public Void visit(SetStatement ss, Integer step) throws AsterixException {
+    public Void visit(SetStatement ss, Integer step) throws CompilationException {
         out.println(skip(step) + "Set " + ss.getPropName() + "=" + ss.getPropValue());
         return null;
     }
 
     @Override
-    public Void visit(DisconnectFeedStatement ss, Integer step) throws AsterixException {
+    public Void visit(DisconnectFeedStatement ss, Integer step) throws CompilationException {
         out.println(skip(step) + skip(step) + ss.getFeedName() + skip(step) + ss.getDatasetName());
         return null;
     }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/AbstractAstVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/AbstractAstVisitor.java
index 3f586e9..a422ef1 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/AbstractAstVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/AbstractAstVisitor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.visitor.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.clause.LimitClause;
@@ -41,92 +41,92 @@
 public abstract class AbstractAstVisitor<R, T> extends AbstractQueryExpressionVisitor<R, T> {
 
     @Override
-    public R visit(Query q, T arg) throws AsterixException {
+    public R visit(Query q, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(FunctionDecl fd, T arg) throws AsterixException {
+    public R visit(FunctionDecl fd, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(LiteralExpr l, T arg) throws AsterixException {
+    public R visit(LiteralExpr l, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(VariableExpr v, T arg) throws AsterixException {
+    public R visit(VariableExpr v, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(ListConstructor lc, T arg) throws AsterixException {
+    public R visit(ListConstructor lc, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(RecordConstructor rc, T arg) throws AsterixException {
+    public R visit(RecordConstructor rc, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(OperatorExpr ifbo, T arg) throws AsterixException {
+    public R visit(OperatorExpr ifbo, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(FieldAccessor fa, T arg) throws AsterixException {
+    public R visit(FieldAccessor fa, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(IndexAccessor ia, T arg) throws AsterixException {
+    public R visit(IndexAccessor ia, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(IfExpr ifexpr, T arg) throws AsterixException {
+    public R visit(IfExpr ifexpr, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(QuantifiedExpression qe, T arg) throws AsterixException {
+    public R visit(QuantifiedExpression qe, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(LetClause lc, T arg) throws AsterixException {
+    public R visit(LetClause lc, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(WhereClause wc, T arg) throws AsterixException {
+    public R visit(WhereClause wc, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(OrderbyClause oc, T arg) throws AsterixException {
+    public R visit(OrderbyClause oc, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(GroupbyClause gc, T arg) throws AsterixException {
+    public R visit(GroupbyClause gc, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(LimitClause lc, T arg) throws AsterixException {
+    public R visit(LimitClause lc, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(UnaryExpr u, T arg) throws AsterixException {
+    public R visit(UnaryExpr u, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(CallExpr pf, T arg) throws AsterixException {
+    public R visit(CallExpr pf, T arg) throws CompilationException {
         return null;
     }
 
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/AbstractQueryExpressionVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/AbstractQueryExpressionVisitor.java
index e32615f..a4868d0 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/AbstractQueryExpressionVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/AbstractQueryExpressionVisitor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.visitor.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.clause.UpdateClause;
 import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition;
 import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
@@ -55,162 +55,162 @@
 public abstract class AbstractQueryExpressionVisitor<R, T> implements ILangVisitor<R, T> {
 
     @Override
-    public R visit(CreateIndexStatement cis, T arg) throws AsterixException {
+    public R visit(CreateIndexStatement cis, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(DataverseDecl dv, T arg) throws AsterixException {
+    public R visit(DataverseDecl dv, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(DeleteStatement del, T arg) throws AsterixException {
+    public R visit(DeleteStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(DropDatasetStatement del, T arg) throws AsterixException {
+    public R visit(DropDatasetStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(DatasetDecl dd, T arg) throws AsterixException {
+    public R visit(DatasetDecl dd, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(InsertStatement insert, T arg) throws AsterixException {
+    public R visit(InsertStatement insert, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(LoadStatement stmtLoad, T arg) throws AsterixException {
+    public R visit(LoadStatement stmtLoad, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(NodegroupDecl ngd, T arg) throws AsterixException {
+    public R visit(NodegroupDecl ngd, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(OrderedListTypeDefinition olte, T arg) throws AsterixException {
+    public R visit(OrderedListTypeDefinition olte, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(RecordTypeDefinition tre, T arg) throws AsterixException {
+    public R visit(RecordTypeDefinition tre, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(SetStatement ss, T arg) throws AsterixException {
+    public R visit(SetStatement ss, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(TypeDecl td, T arg) throws AsterixException {
+    public R visit(TypeDecl td, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(TypeReferenceExpression tre, T arg) throws AsterixException {
+    public R visit(TypeReferenceExpression tre, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(UnorderedListTypeDefinition ulte, T arg) throws AsterixException {
+    public R visit(UnorderedListTypeDefinition ulte, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(UpdateClause del, T arg) throws AsterixException {
+    public R visit(UpdateClause del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(UpdateStatement update, T arg) throws AsterixException {
+    public R visit(UpdateStatement update, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(WriteStatement ws, T arg) throws AsterixException {
+    public R visit(WriteStatement ws, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(CreateDataverseStatement del, T arg) throws AsterixException {
+    public R visit(CreateDataverseStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(IndexDropStatement del, T arg) throws AsterixException {
+    public R visit(IndexDropStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(NodeGroupDropStatement del, T arg) throws AsterixException {
+    public R visit(NodeGroupDropStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(DataverseDropStatement del, T arg) throws AsterixException {
+    public R visit(DataverseDropStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(TypeDropStatement del, T arg) throws AsterixException {
+    public R visit(TypeDropStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(DisconnectFeedStatement del, T arg) throws AsterixException {
+    public R visit(DisconnectFeedStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(CreateFunctionStatement cfs, T arg) throws AsterixException {
+    public R visit(CreateFunctionStatement cfs, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(FunctionDropStatement del, T arg) throws AsterixException {
+    public R visit(FunctionDropStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(CreatePrimaryFeedStatement del, T arg) throws AsterixException {
+    public R visit(CreatePrimaryFeedStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(CreateSecondaryFeedStatement del, T arg) throws AsterixException {
+    public R visit(CreateSecondaryFeedStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(ConnectFeedStatement del, T arg) throws AsterixException {
+    public R visit(ConnectFeedStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(FeedDropStatement del, T arg) throws AsterixException {
+    public R visit(FeedDropStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(CompactStatement del, T arg) throws AsterixException {
+    public R visit(CompactStatement del, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(CreateFeedPolicyStatement cfps, T arg) throws AsterixException {
+    public R visit(CreateFeedPolicyStatement cfps, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(FeedPolicyDropStatement dfs, T arg) throws AsterixException {
+    public R visit(FeedPolicyDropStatement dfs, T arg) throws CompilationException {
         return null;
     }
 }
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/ILangVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/ILangVisitor.java
index 4a16025..4a5c5ed 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/ILangVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/base/ILangVisitor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.common.visitor.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.clause.LimitClause;
@@ -72,104 +72,104 @@
 
 public interface ILangVisitor<R, T> {
 
-    R visit(Query q, T arg) throws AsterixException;
+    R visit(Query q, T arg) throws CompilationException;
 
-    R visit(FunctionDecl fd, T arg) throws AsterixException;
+    R visit(FunctionDecl fd, T arg) throws CompilationException;
 
-    R visit(TypeDecl td, T arg) throws AsterixException;
+    R visit(TypeDecl td, T arg) throws CompilationException;
 
-    R visit(NodegroupDecl ngd, T arg) throws AsterixException;
+    R visit(NodegroupDecl ngd, T arg) throws CompilationException;
 
-    R visit(DatasetDecl dd, T arg) throws AsterixException;
+    R visit(DatasetDecl dd, T arg) throws CompilationException;
 
-    R visit(LoadStatement stmtLoad, T arg) throws AsterixException;
+    R visit(LoadStatement stmtLoad, T arg) throws CompilationException;
 
-    R visit(DropDatasetStatement del, T arg) throws AsterixException;
+    R visit(DropDatasetStatement del, T arg) throws CompilationException;
 
-    R visit(InsertStatement insert, T arg) throws AsterixException;
+    R visit(InsertStatement insert, T arg) throws CompilationException;
 
-    R visit(DeleteStatement del, T arg) throws AsterixException;
+    R visit(DeleteStatement del, T arg) throws CompilationException;
 
-    R visit(UpdateStatement update, T arg) throws AsterixException;
+    R visit(UpdateStatement update, T arg) throws CompilationException;
 
-    R visit(UpdateClause del, T arg) throws AsterixException;
+    R visit(UpdateClause del, T arg) throws CompilationException;
 
-    R visit(TypeReferenceExpression tre, T arg) throws AsterixException;
+    R visit(TypeReferenceExpression tre, T arg) throws CompilationException;
 
-    R visit(RecordTypeDefinition tre, T arg) throws AsterixException;
+    R visit(RecordTypeDefinition tre, T arg) throws CompilationException;
 
-    R visit(OrderedListTypeDefinition olte, T arg) throws AsterixException;
+    R visit(OrderedListTypeDefinition olte, T arg) throws CompilationException;
 
-    R visit(UnorderedListTypeDefinition ulte, T arg) throws AsterixException;
+    R visit(UnorderedListTypeDefinition ulte, T arg) throws CompilationException;
 
-    R visit(LiteralExpr l, T arg) throws AsterixException;
+    R visit(LiteralExpr l, T arg) throws CompilationException;
 
-    R visit(VariableExpr v, T arg) throws AsterixException;
+    R visit(VariableExpr v, T arg) throws CompilationException;
 
-    R visit(ListConstructor lc, T arg) throws AsterixException;
+    R visit(ListConstructor lc, T arg) throws CompilationException;
 
-    R visit(RecordConstructor rc, T arg) throws AsterixException;
+    R visit(RecordConstructor rc, T arg) throws CompilationException;
 
-    R visit(OperatorExpr ifbo, T arg) throws AsterixException;
+    R visit(OperatorExpr ifbo, T arg) throws CompilationException;
 
-    R visit(FieldAccessor fa, T arg) throws AsterixException;
+    R visit(FieldAccessor fa, T arg) throws CompilationException;
 
-    R visit(IndexAccessor ia, T arg) throws AsterixException;
+    R visit(IndexAccessor ia, T arg) throws CompilationException;
 
-    R visit(IfExpr ifexpr, T arg) throws AsterixException;
+    R visit(IfExpr ifexpr, T arg) throws CompilationException;
 
-    R visit(QuantifiedExpression qe, T arg) throws AsterixException;
+    R visit(QuantifiedExpression qe, T arg) throws CompilationException;
 
-    R visit(LetClause lc, T arg) throws AsterixException;
+    R visit(LetClause lc, T arg) throws CompilationException;
 
-    R visit(WhereClause wc, T arg) throws AsterixException;
+    R visit(WhereClause wc, T arg) throws CompilationException;
 
-    R visit(OrderbyClause oc, T arg) throws AsterixException;
+    R visit(OrderbyClause oc, T arg) throws CompilationException;
 
-    R visit(GroupbyClause gc, T arg) throws AsterixException;
+    R visit(GroupbyClause gc, T arg) throws CompilationException;
 
-    R visit(LimitClause lc, T arg) throws AsterixException;
+    R visit(LimitClause lc, T arg) throws CompilationException;
 
-    R visit(UnaryExpr u, T arg) throws AsterixException;
+    R visit(UnaryExpr u, T arg) throws CompilationException;
 
-    R visit(CreateIndexStatement cis, T arg) throws AsterixException;
+    R visit(CreateIndexStatement cis, T arg) throws CompilationException;
 
-    R visit(CreateDataverseStatement del, T arg) throws AsterixException;
+    R visit(CreateDataverseStatement del, T arg) throws CompilationException;
 
-    R visit(IndexDropStatement del, T arg) throws AsterixException;
+    R visit(IndexDropStatement del, T arg) throws CompilationException;
 
-    R visit(NodeGroupDropStatement del, T arg) throws AsterixException;
+    R visit(NodeGroupDropStatement del, T arg) throws CompilationException;
 
-    R visit(DataverseDropStatement del, T arg) throws AsterixException;
+    R visit(DataverseDropStatement del, T arg) throws CompilationException;
 
-    R visit(TypeDropStatement del, T arg) throws AsterixException;
+    R visit(TypeDropStatement del, T arg) throws CompilationException;
 
-    R visit(WriteStatement ws, T arg) throws AsterixException;
+    R visit(WriteStatement ws, T arg) throws CompilationException;
 
-    R visit(SetStatement ss, T arg) throws AsterixException;
+    R visit(SetStatement ss, T arg) throws CompilationException;
 
-    R visit(DisconnectFeedStatement del, T arg) throws AsterixException;
+    R visit(DisconnectFeedStatement del, T arg) throws CompilationException;
 
-    R visit(ConnectFeedStatement del, T arg) throws AsterixException;
+    R visit(ConnectFeedStatement del, T arg) throws CompilationException;
 
-    R visit(CreatePrimaryFeedStatement cpfs, T arg) throws AsterixException;
+    R visit(CreatePrimaryFeedStatement cpfs, T arg) throws CompilationException;
 
-    R visit(CreateSecondaryFeedStatement csfs, T arg) throws AsterixException;
+    R visit(CreateSecondaryFeedStatement csfs, T arg) throws CompilationException;
 
-    R visit(FeedDropStatement del, T arg) throws AsterixException;
+    R visit(FeedDropStatement del, T arg) throws CompilationException;
 
-    R visit(FeedPolicyDropStatement dfs, T arg) throws AsterixException;
+    R visit(FeedPolicyDropStatement dfs, T arg) throws CompilationException;
 
-    R visit(CreateFeedPolicyStatement cfps, T arg) throws AsterixException;
+    R visit(CreateFeedPolicyStatement cfps, T arg) throws CompilationException;
 
-    R visit(CallExpr pf, T arg) throws AsterixException;
+    R visit(CallExpr pf, T arg) throws CompilationException;
 
-    R visit(DataverseDecl dv, T arg) throws AsterixException;
+    R visit(DataverseDecl dv, T arg) throws CompilationException;
 
-    R visit(CreateFunctionStatement cfs, T arg) throws AsterixException;
+    R visit(CreateFunctionStatement cfs, T arg) throws CompilationException;
 
-    R visit(FunctionDropStatement del, T arg) throws AsterixException;
+    R visit(FunctionDropStatement del, T arg) throws CompilationException;
 
-    R visit(CompactStatement del, T arg) throws AsterixException;
+    R visit(CompactStatement del, T arg) throws CompilationException;
 
 }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromClause.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromClause.java
index aff731b..65c2f01 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromClause.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromClause.java
@@ -23,7 +23,7 @@
 import java.util.List;
 import java.util.stream.Collectors;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
@@ -37,7 +37,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
index d4e522a..e4390d9 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/FromTerm.java
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.expression.VariableExpr;
@@ -47,7 +47,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/HavingClause.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/HavingClause.java
index 19b7692..aadbe42 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/HavingClause.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/HavingClause.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.sqlpp.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -33,7 +33,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/JoinClause.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/JoinClause.java
index 0da25cd..0b2a346 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/JoinClause.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/JoinClause.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -34,7 +34,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/NestClause.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/NestClause.java
index 297868f..a2c27f0 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/NestClause.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/NestClause.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -34,7 +34,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/Projection.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/Projection.java
index 148cc36..28d447a 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/Projection.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/Projection.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -41,7 +41,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java
index e297335..51e4ab4 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectBlock.java
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
@@ -58,7 +58,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectClause.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectClause.java
index 12e501b..0a272f9 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectClause.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectClause.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
@@ -38,7 +38,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectElement.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectElement.java
index 6a630b5..9c82d5c 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectElement.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectElement.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -34,7 +34,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectRegular.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectRegular.java
index 1df1e7a..a114337 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectRegular.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectRegular.java
@@ -22,7 +22,7 @@
 import java.util.List;
 import java.util.stream.Collectors;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
@@ -36,7 +36,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectSetOperation.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectSetOperation.java
index 6e0fb21..ee622ea 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectSetOperation.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/SelectSetOperation.java
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationInput;
@@ -43,7 +43,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/UnnestClause.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/UnnestClause.java
index b71838b..f1a3964 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/UnnestClause.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/clause/UnnestClause.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.clause;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
@@ -33,7 +33,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/CaseExpression.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/CaseExpression.java
index 45ff082..05300d1 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/CaseExpression.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/CaseExpression.java
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.expression.LiteralExpr;
 import org.apache.asterix.lang.common.literal.NullLiteral;
@@ -48,7 +48,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/IndependentSubquery.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/IndependentSubquery.java
index 3b4c1aa..24a6217 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/IndependentSubquery.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/IndependentSubquery.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.expression;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor;
@@ -33,7 +33,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java
index a940c47..0fb687a 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/expression/SelectExpression.java
@@ -21,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.clause.LimitClause;
@@ -51,7 +51,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return ((ISqlppVisitor<R, T>) visitor).visit(this, arg);
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/parser/FunctionParser.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/parser/FunctionParser.java
index a1ce60d..d59c5df 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/parser/FunctionParser.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/parser/FunctionParser.java
@@ -22,7 +22,7 @@
 import java.io.StringReader;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.IParserFactory;
 import org.apache.asterix.lang.common.base.Statement;
@@ -39,7 +39,7 @@
         this.parserFactory = parserFactory;
     }
 
-    public FunctionDecl getFunctionDecl(Function function) throws AsterixException {
+    public FunctionDecl getFunctionDecl(Function function) throws CompilationException {
         String functionBody = function.getFunctionBody();
         List<String> params = function.getParams();
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java
index 5fee28f..fbf64f7 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppFunctionBodyRewriter.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.IReturningStatement;
 import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
 import org.apache.asterix.lang.common.statement.FunctionDecl;
@@ -31,7 +31,7 @@
     @Override
     public void rewrite(List<FunctionDecl> declaredFunctions, IReturningStatement topStatement,
             MetadataProvider metadataProvider,
-            LangRewritingContext context) throws AsterixException {
+            LangRewritingContext context) throws CompilationException {
         // Sets up parameters.
         setup(declaredFunctions, topStatement, metadataProvider, context);
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
index 1662f85..f303a6c 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppQueryRewriter.java
@@ -22,7 +22,7 @@
 import java.util.List;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.IQueryRewriter;
@@ -86,7 +86,7 @@
 
     @Override
     public void rewrite(List<FunctionDecl> declaredFunctions, IReturningStatement topStatement,
-            MetadataProvider metadataProvider, LangRewritingContext context) throws AsterixException {
+            MetadataProvider metadataProvider, LangRewritingContext context) throws CompilationException {
         if (topStatement == null) {
             return;
         }
@@ -147,22 +147,22 @@
         topStatement.setVarCounter(context.getVarCounter());
     }
 
-    protected void rewriteGlobalAggregations() throws AsterixException {
+    protected void rewriteGlobalAggregations() throws CompilationException {
         SqlppGlobalAggregationSugarVisitor globalAggregationVisitor = new SqlppGlobalAggregationSugarVisitor();
         topExpr.accept(globalAggregationVisitor, null);
     }
 
-    protected void rewriteListInputFunctions() throws AsterixException {
+    protected void rewriteListInputFunctions() throws CompilationException {
         SqlppListInputFunctionRewriteVisitor listInputFunctionVisitor = new SqlppListInputFunctionRewriteVisitor();
         topExpr.accept(listInputFunctionVisitor, null);
     }
 
-    protected void rewriteFunctionNames() throws AsterixException {
+    protected void rewriteFunctionNames() throws CompilationException {
         SqlppBuiltinFunctionRewriteVisitor functionNameMapVisitor = new SqlppBuiltinFunctionRewriteVisitor();
         topExpr.accept(functionNameMapVisitor, null);
     }
 
-    protected void inlineWithExpressions() throws AsterixException {
+    protected void inlineWithExpressions() throws CompilationException {
         String inlineWith = metadataProvider.getConfig().get(INLINE_WITH);
         if (inlineWith != null && inlineWith.equalsIgnoreCase(NOT_INLINE_WITH)) {
             return;
@@ -172,49 +172,49 @@
         topExpr.accept(inlineWithExpressionVisitor, null);
     }
 
-    protected void generateColumnNames() throws AsterixException {
+    protected void generateColumnNames() throws CompilationException {
         // Generate column names if they are missing in the user query.
         GenerateColumnNameVisitor generateColumnNameVisitor = new GenerateColumnNameVisitor(context);
         topExpr.accept(generateColumnNameVisitor, null);
     }
 
-    protected void substituteGroupbyKeyExpression() throws AsterixException {
+    protected void substituteGroupbyKeyExpression() throws CompilationException {
         // Substitute group-by key expressions that appear in the select clause.
         SubstituteGroupbyExpressionWithVariableVisitor substituteGbyExprVisitor =
                 new SubstituteGroupbyExpressionWithVariableVisitor(context);
         topExpr.accept(substituteGbyExprVisitor, null);
     }
 
-    protected void rewriteSetOperations() throws AsterixException {
+    protected void rewriteSetOperations() throws CompilationException {
         // Rewrites set operation queries that contain order-by and limit clauses.
         SetOperationVisitor setOperationVisitor = new SetOperationVisitor(context);
         topExpr.accept(setOperationVisitor, null);
     }
 
-    protected void rewriteOperatorExpression() throws AsterixException {
+    protected void rewriteOperatorExpression() throws CompilationException {
         // Rewrites like/not-like/in/not-in operators into function call expressions.
         OperatorExpressionVisitor operatorExpressionVisitor = new OperatorExpressionVisitor(context);
         topExpr.accept(operatorExpressionVisitor, null);
     }
 
-    protected void inlineColumnAlias() throws AsterixException {
+    protected void inlineColumnAlias() throws CompilationException {
         // Inline column aliases.
         InlineColumnAliasVisitor inlineColumnAliasVisitor = new InlineColumnAliasVisitor(context);
         topExpr.accept(inlineColumnAliasVisitor, null);
     }
 
-    protected void variableCheckAndRewrite(boolean overwrite) throws AsterixException {
+    protected void variableCheckAndRewrite(boolean overwrite) throws CompilationException {
         VariableCheckAndRewriteVisitor variableCheckAndRewriteVisitor =
                 new VariableCheckAndRewriteVisitor(context, overwrite, metadataProvider);
         topExpr.accept(variableCheckAndRewriteVisitor, null);
     }
 
-    protected void rewriteGroupBys() throws AsterixException {
+    protected void rewriteGroupBys() throws CompilationException {
         SqlppGroupByVisitor groupByVisitor = new SqlppGroupByVisitor(context);
         topExpr.accept(groupByVisitor, null);
     }
 
-    protected void inlineDeclaredUdfs() throws AsterixException {
+    protected void inlineDeclaredUdfs() throws CompilationException {
         List<FunctionSignature> funIds = new ArrayList<FunctionSignature>();
         for (FunctionDecl fdecl : declaredFunctions) {
             funIds.add(fdecl.getSignature());
@@ -238,7 +238,7 @@
         declaredFunctions.removeAll(usedStoredFunctionDecls);
     }
 
-    private Set<FunctionSignature> getFunctionCalls(Expression expression) throws AsterixException {
+    private Set<FunctionSignature> getFunctionCalls(Expression expression) throws CompilationException {
         GatherFunctionCalls gfc = new GatherFunctionCalls();
         expression.accept(gfc, null);
         return gfc.getCalls();
@@ -250,7 +250,7 @@
         }
 
         @Override
-        public Void visit(FromClause fromClause, Void arg) throws AsterixException {
+        public Void visit(FromClause fromClause, Void arg) throws CompilationException {
             for (FromTerm fromTerm : fromClause.getFromTerms()) {
                 fromTerm.accept(this, arg);
             }
@@ -258,7 +258,7 @@
         }
 
         @Override
-        public Void visit(FromTerm fromTerm, Void arg) throws AsterixException {
+        public Void visit(FromTerm fromTerm, Void arg) throws CompilationException {
             fromTerm.getLeftExpression().accept(this, arg);
             for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
                 correlateClause.accept(this, arg);
@@ -267,21 +267,21 @@
         }
 
         @Override
-        public Void visit(JoinClause joinClause, Void arg) throws AsterixException {
+        public Void visit(JoinClause joinClause, Void arg) throws CompilationException {
             joinClause.getRightExpression().accept(this, arg);
             joinClause.getConditionExpression().accept(this, arg);
             return null;
         }
 
         @Override
-        public Void visit(NestClause nestClause, Void arg) throws AsterixException {
+        public Void visit(NestClause nestClause, Void arg) throws CompilationException {
             nestClause.getRightExpression().accept(this, arg);
             nestClause.getConditionExpression().accept(this, arg);
             return null;
         }
 
         @Override
-        public Void visit(Projection projection, Void arg) throws AsterixException {
+        public Void visit(Projection projection, Void arg) throws CompilationException {
             if (!projection.star()) {
                 projection.getExpression().accept(this, arg);
             }
@@ -289,7 +289,7 @@
         }
 
         @Override
-        public Void visit(SelectBlock selectBlock, Void arg) throws AsterixException {
+        public Void visit(SelectBlock selectBlock, Void arg) throws CompilationException {
             if (selectBlock.hasFromClause()) {
                 selectBlock.getFromClause().accept(this, arg);
             }
@@ -317,7 +317,7 @@
         }
 
         @Override
-        public Void visit(SelectClause selectClause, Void arg) throws AsterixException {
+        public Void visit(SelectClause selectClause, Void arg) throws CompilationException {
             if (selectClause.selectElement()) {
                 selectClause.getSelectElement().accept(this, arg);
             } else {
@@ -327,13 +327,13 @@
         }
 
         @Override
-        public Void visit(SelectElement selectElement, Void arg) throws AsterixException {
+        public Void visit(SelectElement selectElement, Void arg) throws CompilationException {
             selectElement.getExpression().accept(this, arg);
             return null;
         }
 
         @Override
-        public Void visit(SelectRegular selectRegular, Void arg) throws AsterixException {
+        public Void visit(SelectRegular selectRegular, Void arg) throws CompilationException {
             for (Projection projection : selectRegular.getProjections()) {
                 projection.accept(this, arg);
             }
@@ -341,7 +341,7 @@
         }
 
         @Override
-        public Void visit(SelectSetOperation selectSetOperation, Void arg) throws AsterixException {
+        public Void visit(SelectSetOperation selectSetOperation, Void arg) throws CompilationException {
             selectSetOperation.getLeftInput().accept(this, arg);
             for (SetOperationRight setOperationRight : selectSetOperation.getRightInputs()) {
                 setOperationRight.getSetOperationRightInput().accept(this, arg);
@@ -350,7 +350,7 @@
         }
 
         @Override
-        public Void visit(SelectExpression selectStatement, Void arg) throws AsterixException {
+        public Void visit(SelectExpression selectStatement, Void arg) throws CompilationException {
             selectStatement.getSelectSetOperation().accept(this, arg);
             if (selectStatement.hasOrderby()) {
                 selectStatement.getOrderbyClause().accept(this, arg);
@@ -362,25 +362,25 @@
         }
 
         @Override
-        public Void visit(UnnestClause unnestClause, Void arg) throws AsterixException {
+        public Void visit(UnnestClause unnestClause, Void arg) throws CompilationException {
             unnestClause.getRightExpression().accept(this, arg);
             return null;
         }
 
         @Override
-        public Void visit(HavingClause havingClause, Void arg) throws AsterixException {
+        public Void visit(HavingClause havingClause, Void arg) throws CompilationException {
             havingClause.getFilterExpression().accept(this, arg);
             return null;
         }
 
         @Override
-        public Void visit(IndependentSubquery independentSubquery, Void arg) throws AsterixException {
+        public Void visit(IndependentSubquery independentSubquery, Void arg) throws CompilationException {
             independentSubquery.getExpr().accept(this, arg);
             return null;
         }
 
         @Override
-        public Void visit(CaseExpression caseExpression, Void arg) throws AsterixException {
+        public Void visit(CaseExpression caseExpression, Void arg) throws CompilationException {
             caseExpression.getConditionExpr().accept(this, arg);
             for (Expression expr : caseExpression.getWhenExprs()) {
                 expr.accept(this, arg);
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppStatementRewriter.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppStatementRewriter.java
index 01cb0f1..5667415 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppStatementRewriter.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/SqlppStatementRewriter.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.sqlpp.rewrites;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.IStatementRewriter;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.sqlpp.visitor.SqlppDeleteRewriteVisitor;
@@ -26,11 +26,11 @@
 class SqlppStatementRewriter implements IStatementRewriter {
 
     @Override
-    public void rewrite(Statement stmt) throws AsterixException {
+    public void rewrite(Statement stmt) throws CompilationException {
         rewriteDeleteStatement(stmt);
     }
 
-    private void rewriteDeleteStatement(Statement stmt) throws AsterixException {
+    private void rewriteDeleteStatement(Statement stmt) throws CompilationException {
         if (stmt != null) {
             SqlppDeleteRewriteVisitor visitor = new SqlppDeleteRewriteVisitor();
             stmt.accept(visitor, null);
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/GenerateColumnNameVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/GenerateColumnNameVisitor.java
index e2edb3a..4e1ab1f 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/GenerateColumnNameVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/GenerateColumnNameVisitor.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.rewrites.visitor;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
@@ -39,14 +39,14 @@
     }
 
     @Override
-    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
         // Visit selectBlock first so that column names starts from $1.
         selectBlock.getSelectClause().accept(this, arg);
         return super.visit(selectBlock, arg);
     }
 
     @Override
-    public Expression visit(Projection projection, ILangExpression arg) throws AsterixException {
+    public Expression visit(Projection projection, ILangExpression arg) throws CompilationException {
         if (!projection.star() && projection.getName() == null) {
             projection.setName(SqlppVariableUtil.variableNameToDisplayedFieldName(context.newVariable().getValue()));
         }
@@ -54,7 +54,7 @@
     }
 
     @Override
-    public Expression visit(GroupbyClause groupbyClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(GroupbyClause groupbyClause, ILangExpression arg) throws CompilationException {
         for (GbyVariableExpressionPair gbyKeyPair : groupbyClause.getGbyPairList()) {
             if (gbyKeyPair.getVar() == null) {
                 gbyKeyPair.setVar(new VariableExpr(context.newVariable()));
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java
index 36786cd..628bf57 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineColumnAliasVisitor.java
@@ -23,11 +23,11 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.lang.common.base.Expression.Kind;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.base.Literal;
-import org.apache.asterix.lang.common.base.Expression.Kind;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.expression.FieldBinding;
 import org.apache.asterix.lang.common.expression.LiteralExpr;
@@ -52,7 +52,7 @@
     }
 
     @Override
-    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
         // Gets the map from select clause.
         Map<Expression, Expression> map = getMap(selectBlock.getSelectClause());
 
@@ -93,7 +93,7 @@
         return super.visit(selectBlock, arg);
     }
 
-    private Map<Expression, Expression> getMap(SelectClause selectClause) throws AsterixException {
+    private Map<Expression, Expression> getMap(SelectClause selectClause) throws CompilationException {
         if (selectClause.selectElement()) {
             return getMap(selectClause.getSelectElement());
         }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineWithExpressionVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineWithExpressionVisitor.java
index 7a4f0fe..54ef5ab 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineWithExpressionVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/InlineWithExpressionVisitor.java
@@ -25,7 +25,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.LetClause;
@@ -41,7 +41,7 @@
     }
 
     @Override
-    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws CompilationException {
         if (selectExpression.hasLetClauses()) {
             // Inlines the leading WITH list.
             Map<Expression, Expression> varExprMap = new HashMap<>();
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/OperatorExpressionVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/OperatorExpressionVisitor.java
index 60c4aa0..aa337e3 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/OperatorExpressionVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/OperatorExpressionVisitor.java
@@ -23,15 +23,15 @@
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.common.expression.OperatorExpr;
 import org.apache.asterix.lang.common.expression.QuantifiedExpression;
-import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.expression.QuantifiedExpression.Quantifier;
+import org.apache.asterix.lang.common.expression.VariableExpr;
 import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
 import org.apache.asterix.lang.common.struct.OperatorType;
 import org.apache.asterix.lang.common.struct.QuantifiedPair;
@@ -47,7 +47,7 @@
     }
 
     @Override
-    public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws CompilationException {
         List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : operatorExpr.getExprList()) {
             newExprList.add(expr.accept(this, operatorExpr));
@@ -83,7 +83,7 @@
  new ArrayList<>(Collections.singletonList(likeExpr)));
     }
 
-    private Expression processInOperator(OperatorExpr operatorExpr, OperatorType opType) throws AsterixException {
+    private Expression processInOperator(OperatorExpr operatorExpr, OperatorType opType) throws CompilationException {
         VariableExpr bindingVar = new VariableExpr(context.newVariable());
         Expression itemExpr = operatorExpr.getExprList().get(0);
         Expression collectionExpr = operatorExpr.getExprList().get(1);
@@ -107,7 +107,8 @@
         return new CallExpr(new FunctionSignature(null, CONCAT, 1), operatorExpr.getExprList());
     }
 
-    private Expression processBetweenOperator(OperatorExpr operatorExpr, OperatorType opType) throws AsterixException {
+    private Expression processBetweenOperator(OperatorExpr operatorExpr, OperatorType opType)
+            throws CompilationException {
         // The grammar guarantees that the BETWEEN operator gets exactly three expressions.
         Expression target = operatorExpr.getExprList().get(0);
         Expression left = operatorExpr.getExprList().get(1);
@@ -127,7 +128,7 @@
     }
 
     private Expression createLessThanExpression(Expression lhs, Expression rhs, List<IExpressionAnnotation> hints)
-            throws AsterixException {
+            throws CompilationException {
         OperatorExpr comparison = new OperatorExpr();
         comparison.addOperand(lhs);
         comparison.addOperand(rhs);
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SetOperationVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SetOperationVisitor.java
index 66bfecd..ddf3cd6 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SetOperationVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SetOperationVisitor.java
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.LimitClause;
@@ -72,7 +72,7 @@
     }
 
     @Override
-    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws CompilationException {
         // Recursively visit nested select expressions.
         SelectSetOperation selectSetOperation = selectExpression.getSelectSetOperation();
         if (!selectSetOperation.hasRightInputs() || !(selectExpression.hasOrderby() || selectExpression.hasLimit())) {
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java
index fbf08ee..f168ebd 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppBuiltinFunctionRewriteVisitor.java
@@ -21,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
@@ -39,7 +39,7 @@
 public class SqlppBuiltinFunctionRewriteVisitor extends AbstractSqlppSimpleExpressionVisitor {
 
     @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
         //TODO(buyingyi): rewrite SQL temporal functions
         FunctionSignature functionSignature = callExpr.getFunctionSignature();
         callExpr.setFunctionSignature(FunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature, true));
@@ -52,7 +52,7 @@
     }
 
     @Override
-    public Expression visit(CaseExpression caseExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CaseExpression caseExpr, ILangExpression arg) throws CompilationException {
         Expression expr = super.visit(caseExpr, arg); // Visits it as usual first.
         if (expr != caseExpr) {
             return expr.accept(this, arg);
@@ -79,7 +79,7 @@
 
     // Normalizes WHEN expressions so that it can have correct NULL/MISSING semantics as well
     // as type promotion semantics.
-    private CaseExpression normalizeCaseExpr(CaseExpression caseExpr) throws AsterixException {
+    private CaseExpression normalizeCaseExpr(CaseExpression caseExpr) throws CompilationException {
         LiteralExpr trueLiteral = new LiteralExpr(TrueLiteral.INSTANCE);
         Expression conditionExpr = caseExpr.getConditionExpr();
         if (trueLiteral.equals(conditionExpr)) {
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java
index 9430e4f..16ae05c 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGlobalAggregationSugarVisitor.java
@@ -22,13 +22,11 @@
 import java.util.HashMap;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
-import org.apache.asterix.lang.common.expression.LiteralExpr;
-import org.apache.asterix.lang.common.literal.IntegerLiteral;
 import org.apache.asterix.lang.sqlpp.clause.SelectBlock;
 import org.apache.asterix.lang.sqlpp.clause.SelectClause;
 import org.apache.asterix.lang.sqlpp.visitor.CheckSql92AggregateVisitor;
@@ -37,7 +35,7 @@
 public class SqlppGlobalAggregationSugarVisitor extends AbstractSqlppSimpleExpressionVisitor {
 
     @Override
-    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
         SelectClause selectClause = selectBlock.getSelectClause();
         if (!selectBlock.hasGroupbyClause() && selectBlock.hasFromClause()) {
             boolean addImplicitGby;
@@ -58,7 +56,7 @@
         return super.visit(selectBlock, arg);
     }
 
-    private boolean isSql92Aggregate(ILangExpression expr, SelectBlock selectBlock) throws AsterixException {
+    private boolean isSql92Aggregate(ILangExpression expr, SelectBlock selectBlock) throws CompilationException {
         CheckSql92AggregateVisitor visitor = new CheckSql92AggregateVisitor();
         return expr.accept(visitor, selectBlock);
     }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
index 996a2ec..a1c17fc 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupBySugarVisitor.java
@@ -26,7 +26,7 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
@@ -90,7 +90,7 @@
     }
 
     @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
         List<Expression> newExprList = new ArrayList<>();
         FunctionSignature signature = callExpr.getFunctionSignature();
         boolean aggregate = FunctionMapUtil.isSql92AggregateFunction(signature);
@@ -109,7 +109,7 @@
         return callExpr;
     }
 
-    private Expression wrapAggregationArgument(Expression argExpr) throws AsterixException {
+    private Expression wrapAggregationArgument(Expression argExpr) throws CompilationException {
         Expression expr = argExpr;
         Set<VariableExpr> freeVars = SqlppRewriteUtil.getFreeVariable(expr);
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
index 0170709..b928285 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppGroupByVisitor.java
@@ -26,7 +26,7 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
@@ -91,7 +91,7 @@
     }
 
     @Override
-    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
         // Traverses the select block in the order of "from", "let"s, "where",
         // "group by", "let"s, "having" and "select".
         FromClause fromClause = selectBlock.getFromClause();
@@ -219,7 +219,7 @@
     }
 
     @Override
-    public Expression visit(GroupbyClause gc, ILangExpression arg) throws AsterixException {
+    public Expression visit(GroupbyClause gc, ILangExpression arg) throws CompilationException {
         // Puts all FROM binding variables into withVarList.
         FromClause fromClause = (FromClause) arg;
         Collection<VariableExpr> fromBindingVars =
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
index 56cbb18..b2f56a5 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppInlineUdfsVisitor.java
@@ -22,7 +22,7 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.IRewriterFactory;
 import org.apache.asterix.lang.common.clause.LetClause;
@@ -73,13 +73,13 @@
 
     @Override
     protected Expression generateQueryExpression(List<LetClause> letClauses, Expression returnExpr)
-            throws AsterixException {
+            throws CompilationException {
         Map<Expression, Expression> varExprMap = extractLetBindingVariableExpressionMappings(letClauses);
-        return (Expression) SqlppRewriteUtil.substituteExpression(returnExpr, varExprMap, context);
+        return SqlppRewriteUtil.substituteExpression(returnExpr, varExprMap, context);
     }
 
     @Override
-    public Boolean visit(FromClause fromClause, List<FunctionDecl> func) throws AsterixException {
+    public Boolean visit(FromClause fromClause, List<FunctionDecl> func) throws CompilationException {
         boolean changed = false;
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
             changed |= fromTerm.accept(this, func);
@@ -88,7 +88,7 @@
     }
 
     @Override
-    public Boolean visit(FromTerm fromTerm, List<FunctionDecl> func) throws AsterixException {
+    public Boolean visit(FromTerm fromTerm, List<FunctionDecl> func) throws CompilationException {
         boolean changed = false;
         Pair<Boolean, Expression> p = inlineUdfsInExpr(fromTerm.getLeftExpression(), func);
         fromTerm.setLeftExpression(p.second);
@@ -100,7 +100,7 @@
     }
 
     @Override
-    public Boolean visit(JoinClause joinClause, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(JoinClause joinClause, List<FunctionDecl> funcs) throws CompilationException {
         Pair<Boolean, Expression> p1 = inlineUdfsInExpr(joinClause.getRightExpression(), funcs);
         joinClause.setRightExpression(p1.second);
         Pair<Boolean, Expression> p2 = inlineUdfsInExpr(joinClause.getConditionExpression(), funcs);
@@ -109,7 +109,7 @@
     }
 
     @Override
-    public Boolean visit(NestClause nestClause, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(NestClause nestClause, List<FunctionDecl> funcs) throws CompilationException {
         Pair<Boolean, Expression> p1 = inlineUdfsInExpr(nestClause.getRightExpression(), funcs);
         nestClause.setRightExpression(p1.second);
         Pair<Boolean, Expression> p2 = inlineUdfsInExpr(nestClause.getConditionExpression(), funcs);
@@ -118,14 +118,14 @@
     }
 
     @Override
-    public Boolean visit(Projection projection, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(Projection projection, List<FunctionDecl> funcs) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(projection.getExpression(), funcs);
         projection.setExpression(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(SelectBlock selectBlock, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(SelectBlock selectBlock, List<FunctionDecl> funcs) throws CompilationException {
         boolean changed = false;
         if (selectBlock.hasFromClause()) {
             changed |= selectBlock.getFromClause().accept(this, funcs);
@@ -154,7 +154,7 @@
     }
 
     @Override
-    public Boolean visit(SelectClause selectClause, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(SelectClause selectClause, List<FunctionDecl> funcs) throws CompilationException {
         boolean changed = false;
         if (selectClause.selectElement()) {
             changed |= selectClause.getSelectElement().accept(this, funcs);
@@ -165,14 +165,14 @@
     }
 
     @Override
-    public Boolean visit(SelectElement selectElement, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(SelectElement selectElement, List<FunctionDecl> funcs) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(selectElement.getExpression(), funcs);
         selectElement.setExpression(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(SelectRegular selectRegular, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(SelectRegular selectRegular, List<FunctionDecl> funcs) throws CompilationException {
         boolean changed = false;
         for (Projection projection : selectRegular.getProjections()) {
             changed |= projection.accept(this, funcs);
@@ -181,7 +181,7 @@
     }
 
     @Override
-    public Boolean visit(SelectSetOperation selectSetOperation, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(SelectSetOperation selectSetOperation, List<FunctionDecl> funcs) throws CompilationException {
         boolean changed = false;
         changed |= selectSetOperation.getLeftInput().accept(this, funcs);
         for (SetOperationRight right : selectSetOperation.getRightInputs()) {
@@ -191,7 +191,7 @@
     }
 
     @Override
-    public Boolean visit(SelectExpression selectExpression, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(SelectExpression selectExpression, List<FunctionDecl> funcs) throws CompilationException {
         boolean changed = false;
         if (selectExpression.hasLetClauses()) {
             for (LetClause letClause : selectExpression.getLetList()) {
@@ -209,28 +209,29 @@
     }
 
     @Override
-    public Boolean visit(UnnestClause unnestClause, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(UnnestClause unnestClause, List<FunctionDecl> funcs) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(unnestClause.getRightExpression(), funcs);
         unnestClause.setRightExpression(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(HavingClause havingClause, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(HavingClause havingClause, List<FunctionDecl> funcs) throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(havingClause.getFilterExpression(), funcs);
         havingClause.setFilterExpression(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(IndependentSubquery independentSubquery, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(IndependentSubquery independentSubquery, List<FunctionDecl> funcs)
+            throws CompilationException {
         Pair<Boolean, Expression> p = inlineUdfsInExpr(independentSubquery.getExpr(), funcs);
         independentSubquery.setExpr(p.second);
         return p.first;
     }
 
     @Override
-    public Boolean visit(CaseExpression caseExpr, List<FunctionDecl> funcs) throws AsterixException {
+    public Boolean visit(CaseExpression caseExpr, List<FunctionDecl> funcs) throws CompilationException {
         Pair<Boolean, Expression> result = inlineUdfsInExpr(caseExpr.getConditionExpr(), funcs);
         caseExpr.setConditionExpr(result.second);
         boolean inlined = result.first;
@@ -249,11 +250,11 @@
     }
 
     private Map<Expression, Expression> extractLetBindingVariableExpressionMappings(List<LetClause> letClauses)
-            throws AsterixException {
+            throws CompilationException {
         Map<Expression, Expression> varExprMap = new HashMap<>();
         for (LetClause lc : letClauses) {
             // inline let variables one by one iteratively.
-            lc.setBindingExpr((Expression) SqlppRewriteUtil.substituteExpression(lc.getBindingExpr(),
+            lc.setBindingExpr(SqlppRewriteUtil.substituteExpression(lc.getBindingExpr(),
                     varExprMap, context));
             varExprMap.put(lc.getVarExpr(), lc.getBindingExpr());
         }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppListInputFunctionRewriteVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppListInputFunctionRewriteVisitor.java
index 847076b..2e65292 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppListInputFunctionRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlppListInputFunctionRewriteVisitor.java
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.expression.CallExpr;
@@ -36,7 +36,7 @@
 public class SqlppListInputFunctionRewriteVisitor extends AbstractSqlppSimpleExpressionVisitor {
 
     @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
         List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : callExpr.getExprList()) {
             newExprList.add(expr.accept(this, arg));
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SubstituteGroupbyExpressionWithVariableVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SubstituteGroupbyExpressionWithVariableVisitor.java
index eb2f463..6d4816b 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SubstituteGroupbyExpressionWithVariableVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SubstituteGroupbyExpressionWithVariableVisitor.java
@@ -22,11 +22,11 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.base.Expression.Kind;
+import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
@@ -46,7 +46,7 @@
     }
 
     @Override
-    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
         if (selectBlock.hasGroupbyClause()) {
             Map<Expression, Expression> map = new HashMap<>();
             for (GbyVariableExpressionPair gbyKeyPair : selectBlock.getGroupbyClause().getGbyPairList()) {
@@ -93,7 +93,7 @@
     }
 
     @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
         FunctionSignature signature = callExpr.getFunctionSignature();
         if (FunctionMapUtil.isSql92AggregateFunction(signature)) {
             return callExpr;
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
index 311a4ea..c271365 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/VariableCheckAndRewriteVisitor.java
@@ -22,11 +22,11 @@
 import java.util.List;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.base.Expression.Kind;
+import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.expression.CallExpr;
 import org.apache.asterix.lang.common.expression.FieldAccessor;
 import org.apache.asterix.lang.common.expression.LiteralExpr;
@@ -65,7 +65,7 @@
     }
 
     @Override
-    public Expression visit(FieldAccessor fa, ILangExpression parent) throws AsterixException {
+    public Expression visit(FieldAccessor fa, ILangExpression parent) throws CompilationException {
         Expression leadingExpr = fa.getExpr();
         if (leadingExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
             fa.setExpr(leadingExpr.accept(this, fa));
@@ -90,7 +90,7 @@
     }
 
     @Override
-    public Expression visit(VariableExpr varExpr, ILangExpression parent) throws AsterixException {
+    public Expression visit(VariableExpr varExpr, ILangExpression parent) throws CompilationException {
         return resolve(varExpr, null /** Resolves within the default dataverse. */
                 , SqlppVariableUtil.toUserDefinedVariableName(varExpr.getVar().getValue()).getValue(), varExpr, parent);
     }
@@ -98,7 +98,7 @@
     // Resolve a variable expression with dataverse name and dataset name.
     private Expression resolve(VariableExpr varExpr, String dataverseName, String datasetName,
             Expression originalExprWithUndefinedIdentifier, ILangExpression parent)
-            throws AsterixException {
+            throws CompilationException {
         String varName = varExpr.getVar().getValue();
         checkError(varName);
         if (!rewriteNeeded(varExpr)) {
@@ -123,23 +123,23 @@
         return wrapWithResolveFunction(varExpr, liveVars);
     }
 
-    private void throwUnresolvableError(String dataverseName, String datasetName) throws AsterixException {
+    private void throwUnresolvableError(String dataverseName, String datasetName) throws CompilationException {
         String defaultDataverseName = metadataProvider.getDefaultDataverseName();
         if (dataverseName == null && defaultDataverseName == null) {
-            throw new AsterixException("Cannot find dataset " + datasetName
+            throw new CompilationException("Cannot find dataset " + datasetName
                     + " because there is no dataverse declared, nor an alias with name " + datasetName + "!");
         }
         //If no available dataset nor in-scope variable to resolve to, we throw an error.
-        throw new AsterixException("Cannot find dataset " + datasetName + " in dataverse "
+        throw new CompilationException("Cannot find dataset " + datasetName + " in dataverse "
                 + (dataverseName == null ? defaultDataverseName : dataverseName) + " nor an alias with name "
                 + datasetName + "!");
     }
 
     // Checks whether we need to error the variable reference, e.g., the variable is referred
     // in a LIMIT clause.
-    private void checkError(String varName) throws AsterixException {
+    private void checkError(String varName) throws CompilationException {
         if (scopeChecker.isInForbiddenScopes(varName)) {
-            throw new AsterixException(
+            throw new CompilationException(
                     "Inside limit clauses, it is disallowed to reference a variable having the same name"
                             + " as any variable bound in the same scope as the limit clause.");
         }
@@ -148,13 +148,13 @@
     // For a From/Join/UNNEST/Quantifiers binding expression, we resolve the undefined identifier reference as
     // a dataset access only.
     private boolean resolveToDatasetOnly(Expression originalExpressionWithUndefinedIdentifier, ILangExpression parent)
-            throws AsterixException {
+            throws CompilationException {
         CheckDatasetOnlyResolutionVisitor visitor = new CheckDatasetOnlyResolutionVisitor();
         return parent.accept(visitor, originalExpressionWithUndefinedIdentifier);
     }
 
     // Whether a rewrite is needed for a variable reference expression.
-    private boolean rewriteNeeded(VariableExpr varExpr) throws AsterixException {
+    private boolean rewriteNeeded(VariableExpr varExpr) throws CompilationException {
         String varName = varExpr.getVar().getValue();
         Identifier ident = scopeChecker.lookupSymbol(varName);
         if (ident != null) {
@@ -168,21 +168,21 @@
         }
     }
 
-    private Expression wrapWithDatasetFunction(String dataverseName, String datasetName) throws AsterixException {
+    private Expression wrapWithDatasetFunction(String dataverseName, String datasetName) throws CompilationException {
         String fullyQualifiedName = dataverseName == null ? datasetName : dataverseName + "." + datasetName;
         List<Expression> argList = new ArrayList<>();
         argList.add(new LiteralExpr(new StringLiteral(fullyQualifiedName)));
         return new CallExpr(datasetFunction, argList);
     }
 
-    private boolean datasetExists(String dataverseName, String datasetName) throws AsterixException {
+    private boolean datasetExists(String dataverseName, String datasetName) throws CompilationException {
         try {
             if (metadataProvider.findDataset(dataverseName, datasetName) != null) {
                 return true;
             }
             return fullyQualifiedDatasetNameExists(datasetName);
         } catch (AlgebricksException e) {
-            throw new AsterixException(e);
+            throw new CompilationException(e);
         }
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/struct/SetOperationInput.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/struct/SetOperationInput.java
index 55245fe..0c4b65b 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/struct/SetOperationInput.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/struct/SetOperationInput.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.sqlpp.struct;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.asterix.lang.sqlpp.clause.SelectBlock;
 import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
@@ -51,7 +51,7 @@
         return subquery != null;
     }
 
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         if (selectBlock != null) {
             return ((ISqlppVisitor<R, T>) visitor).visit(selectBlock, arg);
         } else {
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/ExpressionToVariableUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/ExpressionToVariableUtil.java
index 93e1828..cd805a1 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/ExpressionToVariableUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/ExpressionToVariableUtil.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.util;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Expression.Kind;
 import org.apache.asterix.lang.common.expression.FieldAccessor;
@@ -46,7 +46,7 @@
             try {
                 throw new ParseException(
                         "Need an alias for the enclosed expression:\n" + SqlppFormatPrintUtil.toString(expr));
-            } catch (AsterixException e) {
+            } catch (CompilationException e) {
                 LOGGER.error(e.getLocalizedMessage(), e);
                 throw new ParseException(e.getLocalizedMessage());
             }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
index b7d3d62..8f04980 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/FunctionMapUtil.java
@@ -23,7 +23,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.expression.CallExpr;
@@ -58,7 +58,7 @@
      * @return true if the function signature is a SQL-92 core aggregate,
      *         false otherwise.
      */
-    public static boolean isSql92AggregateFunction(FunctionSignature signature) throws AsterixException {
+    public static boolean isSql92AggregateFunction(FunctionSignature signature) throws CompilationException {
         IFunctionInfo finfo = FunctionUtil.getFunctionInfo(new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
                 signature.getName().toLowerCase(), signature.getArity()));
         if (finfo == null) {
@@ -98,9 +98,9 @@
      * @param fs,
      *            the SQL-92 aggregate function signature.
      * @return the SQL++ aggregate function signature.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static FunctionSignature sql92ToCoreAggregateFunction(FunctionSignature fs) throws AsterixException {
+    public static FunctionSignature sql92ToCoreAggregateFunction(FunctionSignature fs) throws CompilationException {
         if (!isSql92AggregateFunction(fs)) {
             return fs;
         }
@@ -116,11 +116,11 @@
      * @return the system internal function.
      */
     public static FunctionSignature normalizeBuiltinFunctionSignature(FunctionSignature fs, boolean checkSql92Aggregate)
-            throws AsterixException {
+            throws CompilationException {
         if (isCoreAggregateFunction(fs)) {
             return internalizeCoreAggregateFunctionName(fs);
         } else if (checkSql92Aggregate && isSql92AggregateFunction(fs)) {
-            throw new AsterixException(fs.getName()
+            throw new CompilationException(fs.getName()
                     + " is a SQL-92 aggregate function. The SQL++ core aggregate function " + CORE_SQL_AGGREGATE_PREFIX
                     + fs.getName().toLowerCase() + " could potentially express the intent.");
         }
@@ -153,10 +153,10 @@
      * @param fs,
      *            a user-facing SQL++ core aggregate function signature.
      * @return the AsterixDB internal function signature for the aggregate function.
-     * @throws AsterixException
+     * @throws CompilationException
      */
     private static FunctionSignature internalizeCoreAggregateFunctionName(FunctionSignature fs)
-            throws AsterixException {
+            throws CompilationException {
         String name = fs.getName().toLowerCase();
         boolean coreAgg = name.startsWith(CORE_AGGREGATE_PREFIX);
         String lowerCaseName = coreAgg ? name.substring(CORE_AGGREGATE_PREFIX.length())
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppAstPrintUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppAstPrintUtil.java
index 0d840cd..ef8c4f5 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppAstPrintUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppAstPrintUtil.java
@@ -23,7 +23,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.IAstPrintVisitorFactory;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.base.Statement;
@@ -45,9 +45,9 @@
      *            the language expression.
      * @param output
      *            a writer for printing strings.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static void print(ILangExpression expr, PrintWriter output) throws AsterixException {
+    public static void print(ILangExpression expr, PrintWriter output) throws CompilationException {
         QueryPrintVisitor visitor = astPrintVisitorFactory.createLangVisitor(output);
         expr.accept(visitor, 0);
         output.flush();
@@ -60,9 +60,9 @@
      *            a list of statements of a query
      * @param output
      *            a writer for printing strings.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static void print(List<Statement> statements, PrintWriter output) throws AsterixException {
+    public static void print(List<Statement> statements, PrintWriter output) throws CompilationException {
         QueryPrintVisitor visitor = astPrintVisitorFactory.createLangVisitor(output);
         for (Statement statement : statements) {
             statement.accept(visitor, 0);
@@ -74,9 +74,9 @@
      * @param expr
      *            a language expression.
      * @return the AST of a language expression.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static String toString(ILangExpression expr) throws AsterixException {
+    public static String toString(ILangExpression expr) throws CompilationException {
         List<ILangExpression> exprs = new ArrayList<>();
         exprs.add(expr);
         return toString(exprs);
@@ -86,9 +86,9 @@
      * @param exprs
      *            a list of language expression.
      * @return an AST of the input language expressions.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static String toString(List<ILangExpression> exprs) throws AsterixException {
+    public static String toString(List<ILangExpression> exprs) throws CompilationException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         PrintWriter output = new PrintWriter(bos);
         QueryPrintVisitor visitor = astPrintVisitorFactory.createLangVisitor(output);
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppFormatPrintUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppFormatPrintUtil.java
index 2c8f582..6cfaeef 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppFormatPrintUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppFormatPrintUtil.java
@@ -23,7 +23,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.sqlpp.visitor.SqlppFormatPrintVisitor;
@@ -41,9 +41,9 @@
      *            the language expression.
      * @param output
      *            a writer for printing strings.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static void print(ILangExpression expr, PrintWriter output) throws AsterixException {
+    public static void print(ILangExpression expr, PrintWriter output) throws CompilationException {
         SqlppFormatPrintVisitor visitor = new SqlppFormatPrintVisitor(output);
         expr.accept(visitor, 0);
     }
@@ -55,9 +55,9 @@
      *            a list of statements of a query
      * @param output
      *            a writer for printing strings.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static void print(List<Statement> statements, PrintWriter output) throws AsterixException {
+    public static void print(List<Statement> statements, PrintWriter output) throws CompilationException {
         SqlppFormatPrintVisitor visitor = new SqlppFormatPrintVisitor(output);
         for (Statement statement : statements) {
             statement.accept(visitor, 0);
@@ -68,9 +68,9 @@
      * @param expr
      *            a language expression.
      * @return a formatted string of a language expression.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static String toString(ILangExpression expr) throws AsterixException {
+    public static String toString(ILangExpression expr) throws CompilationException {
         List<ILangExpression> exprs = new ArrayList<>();
         exprs.add(expr);
         return toString(exprs);
@@ -80,9 +80,9 @@
      * @param exprs
      *            a list of language expression.
      * @return a formatted string of the input language expressions.
-     * @throws AsterixException
+     * @throws CompilationException
      */
-    public static String toString(List<ILangExpression> exprs) throws AsterixException {
+    public static String toString(List<ILangExpression> exprs) throws CompilationException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         PrintWriter output = new PrintWriter(bos);
         SqlppFormatPrintVisitor visitor = new SqlppFormatPrintVisitor(output);
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java
index 519963a..a066110 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppRewriteUtil.java
@@ -23,7 +23,7 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.expression.VariableExpr;
@@ -43,19 +43,19 @@
     // Applying sugar rewriting for group-by.
     public static Expression rewriteExpressionUsingGroupVariable(VariableExpr groupVar,
             Collection<VariableExpr> fieldVars, ILangExpression expr,
-            LangRewritingContext context) throws AsterixException {
+            LangRewritingContext context) throws CompilationException {
         SqlppGroupBySugarVisitor visitor = new SqlppGroupBySugarVisitor(context, groupVar, fieldVars);
         return expr.accept(visitor, null);
     }
 
-    public static Set<VariableExpr> getFreeVariable(Expression expr) throws AsterixException {
+    public static Set<VariableExpr> getFreeVariable(Expression expr) throws CompilationException {
         Set<VariableExpr> vars = new HashSet<>();
         FreeVariableVisitor visitor = new FreeVariableVisitor();
         expr.accept(visitor, vars);
         return vars;
     }
 
-    public static ILangExpression deepCopy(ILangExpression expr) throws AsterixException {
+    public static ILangExpression deepCopy(ILangExpression expr) throws CompilationException {
         if (expr == null) {
             return expr;
         }
@@ -64,7 +64,7 @@
     }
 
     // Checks if an ILangExpression contains a subquery.
-    public static boolean constainsSubquery(ILangExpression expr) throws AsterixException {
+    public static boolean constainsSubquery(ILangExpression expr) throws CompilationException {
         if (expr == null) {
             return false;
         }
@@ -83,10 +83,10 @@
      * @return an expression, where sub-expressions of the input expression (including the input expression itself)
      *         are replaced with deep copies with their mapped replacements in the exprMap if there exists such a
      *         replacement expression.
-     * @throws AsterixException
+     * @throws CompilationException
      */
     public static Expression substituteExpression(Expression expression, Map<Expression, Expression> exprMap,
-            LangRewritingContext context) throws AsterixException {
+            LangRewritingContext context) throws CompilationException {
         if (exprMap.isEmpty()) {
             return expression;
         }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java
index 5352804..2d6ac53 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/util/SqlppVariableUtil.java
@@ -26,7 +26,7 @@
 import java.util.List;
 import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
@@ -101,7 +101,7 @@
         return new VarIdentifier(USER_VAR_PREFIX + idName);
     }
 
-    public static Collection<VariableExpr> getFreeVariables(ILangExpression langExpr) throws AsterixException {
+    public static Collection<VariableExpr> getFreeVariables(ILangExpression langExpr) throws CompilationException {
         Collection<VariableExpr> freeVars = new HashSet<>();
         FreeVariableVisitor visitor = new FreeVariableVisitor();
         langExpr.accept(visitor, freeVars);
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java
index 05b1018..cab7b5b 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckDatasetOnlyResolutionVisitor.java
@@ -19,7 +19,7 @@
 
 package org.apache.asterix.lang.sqlpp.visitor;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
@@ -64,57 +64,57 @@
 public class CheckDatasetOnlyResolutionVisitor extends AbstractSqlppQueryExpressionVisitor<Boolean, ILangExpression> {
 
     @Override
-    public Boolean visit(Query q, ILangExpression expr) throws AsterixException {
+    public Boolean visit(Query q, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(FunctionDecl fd, ILangExpression expr) throws AsterixException {
+    public Boolean visit(FunctionDecl fd, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(LiteralExpr l, ILangExpression expr) throws AsterixException {
+    public Boolean visit(LiteralExpr l, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(VariableExpr v, ILangExpression expr) throws AsterixException {
+    public Boolean visit(VariableExpr v, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(ListConstructor lc, ILangExpression expr) throws AsterixException {
+    public Boolean visit(ListConstructor lc, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(RecordConstructor rc, ILangExpression expr) throws AsterixException {
+    public Boolean visit(RecordConstructor rc, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(OperatorExpr ifbo, ILangExpression expr) throws AsterixException {
+    public Boolean visit(OperatorExpr ifbo, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(FieldAccessor fa, ILangExpression expr) throws AsterixException {
+    public Boolean visit(FieldAccessor fa, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(IndexAccessor ia, ILangExpression expr) throws AsterixException {
+    public Boolean visit(IndexAccessor ia, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(IfExpr ifexpr, ILangExpression expr) throws AsterixException {
+    public Boolean visit(IfExpr ifexpr, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(QuantifiedExpression qe, ILangExpression expr) throws AsterixException {
+    public Boolean visit(QuantifiedExpression qe, ILangExpression expr) throws CompilationException {
         for (QuantifiedPair qp : qe.getQuantifiedList()) {
             // If the target reference of undefined variable is a binding expression in a quantified pair,
             // then we only resolve it to dataset.
@@ -126,112 +126,112 @@
     }
 
     @Override
-    public Boolean visit(UnaryExpr u, ILangExpression expr) throws AsterixException {
+    public Boolean visit(UnaryExpr u, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(CallExpr pf, ILangExpression expr) throws AsterixException {
+    public Boolean visit(CallExpr pf, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(LetClause lc, ILangExpression expr) throws AsterixException {
+    public Boolean visit(LetClause lc, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(WhereClause wc, ILangExpression expr) throws AsterixException {
+    public Boolean visit(WhereClause wc, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(OrderbyClause oc, ILangExpression expr) throws AsterixException {
+    public Boolean visit(OrderbyClause oc, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(GroupbyClause gc, ILangExpression expr) throws AsterixException {
+    public Boolean visit(GroupbyClause gc, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(LimitClause lc, ILangExpression expr) throws AsterixException {
+    public Boolean visit(LimitClause lc, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(FromClause fromClause, ILangExpression expr) throws AsterixException {
+    public Boolean visit(FromClause fromClause, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(FromTerm fromTerm, ILangExpression expr) throws AsterixException {
+    public Boolean visit(FromTerm fromTerm, ILangExpression expr) throws CompilationException {
         return expr == fromTerm.getLeftExpression();
     }
 
     @Override
-    public Boolean visit(JoinClause joinClause, ILangExpression expr) throws AsterixException {
+    public Boolean visit(JoinClause joinClause, ILangExpression expr) throws CompilationException {
         return expr == joinClause.getRightExpression();
     }
 
     @Override
-    public Boolean visit(NestClause nestClause, ILangExpression expr) throws AsterixException {
+    public Boolean visit(NestClause nestClause, ILangExpression expr) throws CompilationException {
         return expr == nestClause.getRightExpression();
     }
 
     @Override
-    public Boolean visit(Projection projection, ILangExpression expr) throws AsterixException {
+    public Boolean visit(Projection projection, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(SelectBlock selectBlock, ILangExpression expr) throws AsterixException {
+    public Boolean visit(SelectBlock selectBlock, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(SelectClause selectClause, ILangExpression expr) throws AsterixException {
+    public Boolean visit(SelectClause selectClause, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(SelectElement selectElement, ILangExpression expr) throws AsterixException {
+    public Boolean visit(SelectElement selectElement, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(SelectRegular selectRegular, ILangExpression expr) throws AsterixException {
+    public Boolean visit(SelectRegular selectRegular, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(SelectSetOperation selectSetOperation, ILangExpression expr) throws AsterixException {
+    public Boolean visit(SelectSetOperation selectSetOperation, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(SelectExpression selectStatement, ILangExpression expr) throws AsterixException {
+    public Boolean visit(SelectExpression selectStatement, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(UnnestClause unnestClause, ILangExpression expr) throws AsterixException {
+    public Boolean visit(UnnestClause unnestClause, ILangExpression expr) throws CompilationException {
         return expr == unnestClause.getRightExpression();
     }
 
     @Override
-    public Boolean visit(HavingClause havingClause, ILangExpression expr) throws AsterixException {
+    public Boolean visit(HavingClause havingClause, ILangExpression expr) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(IndependentSubquery independentSubquery, ILangExpression arg) throws AsterixException {
+    public Boolean visit(IndependentSubquery independentSubquery, ILangExpression arg) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(CaseExpression caseExpr, ILangExpression arg) throws AsterixException {
+    public Boolean visit(CaseExpression caseExpr, ILangExpression arg) throws CompilationException {
         return false;
     }
 }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
index ca25775..1fd110c 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
@@ -20,7 +20,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
@@ -67,32 +67,32 @@
 public class CheckSql92AggregateVisitor extends AbstractSqlppQueryExpressionVisitor<Boolean, ILangExpression> {
 
     @Override
-    public Boolean visit(Query q, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(Query q, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(FunctionDecl fd, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(FunctionDecl fd, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(LiteralExpr l, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(LiteralExpr l, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(VariableExpr v, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(VariableExpr v, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(ListConstructor lc, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(ListConstructor lc, ILangExpression parentSelectBlock) throws CompilationException {
         return visitExprList(lc.getExprList(), parentSelectBlock);
     }
 
     @Override
-    public Boolean visit(RecordConstructor rc, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(RecordConstructor rc, ILangExpression parentSelectBlock) throws CompilationException {
         for (FieldBinding fieldBinding : rc.getFbList()) {
             ILangExpression leftExpr = fieldBinding.getLeftExpr();
             ILangExpression rightExpr = fieldBinding.getRightExpr();
@@ -107,22 +107,22 @@
     }
 
     @Override
-    public Boolean visit(OperatorExpr ifbo, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(OperatorExpr ifbo, ILangExpression parentSelectBlock) throws CompilationException {
         return visitExprList(ifbo.getExprList(), parentSelectBlock);
     }
 
     @Override
-    public Boolean visit(FieldAccessor fa, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(FieldAccessor fa, ILangExpression parentSelectBlock) throws CompilationException {
         return fa.getExpr().accept(this, parentSelectBlock);
     }
 
     @Override
-    public Boolean visit(IndexAccessor ia, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(IndexAccessor ia, ILangExpression parentSelectBlock) throws CompilationException {
         return ia.getExpr().accept(this, parentSelectBlock);
     }
 
     @Override
-    public Boolean visit(IfExpr ifexpr, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(IfExpr ifexpr, ILangExpression parentSelectBlock) throws CompilationException {
         if (ifexpr.getCondExpr().accept(this, parentSelectBlock)) {
             return true;
         } else {
@@ -132,17 +132,17 @@
     }
 
     @Override
-    public Boolean visit(QuantifiedExpression qe, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(QuantifiedExpression qe, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(UnaryExpr u, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(UnaryExpr u, ILangExpression parentSelectBlock) throws CompilationException {
         return u.getExpr().accept(this, parentSelectBlock);
     }
 
     @Override
-    public Boolean visit(CallExpr pf, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(CallExpr pf, ILangExpression parentSelectBlock) throws CompilationException {
         FunctionSignature fs = pf.getFunctionSignature();
         if (FunctionMapUtil.isSql92AggregateFunction(fs)) {
             return true;
@@ -156,52 +156,52 @@
     }
 
     @Override
-    public Boolean visit(LetClause lc, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(LetClause lc, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(WhereClause wc, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(WhereClause wc, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(OrderbyClause oc, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(OrderbyClause oc, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(GroupbyClause gc, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(GroupbyClause gc, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(LimitClause lc, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(LimitClause lc, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(FromClause fromClause, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(FromClause fromClause, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(FromTerm fromTerm, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(FromTerm fromTerm, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(JoinClause joinClause, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(JoinClause joinClause, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(NestClause nestClause, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(NestClause nestClause, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(Projection projection, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(Projection projection, ILangExpression parentSelectBlock) throws CompilationException {
         if (projection.star()) {
             return false;
         }
@@ -209,12 +209,12 @@
     }
 
     @Override
-    public Boolean visit(SelectBlock selectBlock, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(SelectBlock selectBlock, ILangExpression parentSelectBlock) throws CompilationException {
         return selectBlock.getSelectClause().accept(this, selectBlock);
     }
 
     @Override
-    public Boolean visit(SelectClause selectClause, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(SelectClause selectClause, ILangExpression parentSelectBlock) throws CompilationException {
         if (selectClause.selectElement()) {
             return selectClause.getSelectElement().accept(this, parentSelectBlock);
         } else {
@@ -223,12 +223,12 @@
     }
 
     @Override
-    public Boolean visit(SelectElement selectElement, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(SelectElement selectElement, ILangExpression parentSelectBlock) throws CompilationException {
         return selectElement.getExpression().accept(this, parentSelectBlock);
     }
 
     @Override
-    public Boolean visit(SelectRegular selectRegular, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(SelectRegular selectRegular, ILangExpression parentSelectBlock) throws CompilationException {
         for (Projection projection : selectRegular.getProjections()) {
             if (projection.accept(this, parentSelectBlock)) {
                 return true;
@@ -239,26 +239,28 @@
 
     @Override
     public Boolean visit(SelectSetOperation selectSetOperation, ILangExpression parentSelectBlock)
-            throws AsterixException {
+            throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(SelectExpression selectStatement, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(SelectExpression selectStatement, ILangExpression parentSelectBlock)
+            throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(UnnestClause unnestClause, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(UnnestClause unnestClause, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(HavingClause havingClause, ILangExpression parentSelectBlock) throws AsterixException {
+    public Boolean visit(HavingClause havingClause, ILangExpression parentSelectBlock) throws CompilationException {
         return false;
     }
 
-    private Boolean visitExprList(List<Expression> exprs, ILangExpression parentSelectBlock) throws AsterixException {
+    private Boolean visitExprList(List<Expression> exprs, ILangExpression parentSelectBlock)
+            throws CompilationException {
         for (Expression item : exprs) {
             if (item.accept(this, parentSelectBlock)) {
                 return true;
@@ -268,12 +270,12 @@
     }
 
     @Override
-    public Boolean visit(IndependentSubquery independentSubquery, ILangExpression arg) throws AsterixException {
+    public Boolean visit(IndependentSubquery independentSubquery, ILangExpression arg) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(CaseExpression caseExpr, ILangExpression arg) throws AsterixException {
+    public Boolean visit(CaseExpression caseExpr, ILangExpression arg) throws CompilationException {
         return caseExpr.getConditionExpr().accept(this, arg) || visitExprList(caseExpr.getWhenExprs(), arg)
                 || visitExprList(caseExpr.getThenExprs(), arg) || caseExpr.getElseExpr().accept(this, arg);
     }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java
index e772df5..7f93b2f 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSubqueryVisitor.java
@@ -21,7 +21,7 @@
 
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
@@ -72,7 +72,7 @@
 public class CheckSubqueryVisitor extends AbstractSqlppQueryExpressionVisitor<Boolean, ILangExpression> {
 
     @Override
-    public Boolean visit(FromClause fromClause, ILangExpression arg) throws AsterixException {
+    public Boolean visit(FromClause fromClause, ILangExpression arg) throws CompilationException {
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
             if (fromTerm.accept(this, arg)) {
                 return false;
@@ -82,7 +82,7 @@
     }
 
     @Override
-    public Boolean visit(FromTerm fromTerm, ILangExpression arg) throws AsterixException {
+    public Boolean visit(FromTerm fromTerm, ILangExpression arg) throws CompilationException {
         if (visit(fromTerm.getLeftExpression(), arg)) {
             return true;
         }
@@ -95,17 +95,17 @@
     }
 
     @Override
-    public Boolean visit(JoinClause joinClause, ILangExpression arg) throws AsterixException {
+    public Boolean visit(JoinClause joinClause, ILangExpression arg) throws CompilationException {
         return visit(joinClause.getRightExpression(), arg) || visit(joinClause.getConditionExpression(), arg);
     }
 
     @Override
-    public Boolean visit(NestClause nestClause, ILangExpression arg) throws AsterixException {
+    public Boolean visit(NestClause nestClause, ILangExpression arg) throws CompilationException {
         return nestClause.accept(this, arg);
     }
 
     @Override
-    public Boolean visit(Projection projection, ILangExpression arg) throws AsterixException {
+    public Boolean visit(Projection projection, ILangExpression arg) throws CompilationException {
         if (projection.star()) {
             return false;
         }
@@ -113,7 +113,7 @@
     }
 
     @Override
-    public Boolean visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
+    public Boolean visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
         boolean hasSubquery = visit(selectBlock.getFromClause(), arg) || visit(selectBlock.getGroupbyClause(), arg)
                 || visit(selectBlock.getHavingClause(), arg) || visit(selectBlock.getWhereClause(), arg);
         return hasSubquery || visit(selectBlock.getSelectClause(), arg) || visit(selectBlock.getLetList(), arg)
@@ -121,22 +121,22 @@
     }
 
     @Override
-    public Boolean visit(SelectClause selectClause, ILangExpression arg) throws AsterixException {
+    public Boolean visit(SelectClause selectClause, ILangExpression arg) throws CompilationException {
         return visit(selectClause.getSelectElement(), arg) || visit(selectClause.getSelectRegular(), arg);
     }
 
     @Override
-    public Boolean visit(SelectElement selectElement, ILangExpression arg) throws AsterixException {
+    public Boolean visit(SelectElement selectElement, ILangExpression arg) throws CompilationException {
         return visit(selectElement.getExpression(), arg);
     }
 
     @Override
-    public Boolean visit(SelectRegular selectRegular, ILangExpression arg) throws AsterixException {
+    public Boolean visit(SelectRegular selectRegular, ILangExpression arg) throws CompilationException {
         return visit(selectRegular.getProjections(), arg);
     }
 
     @Override
-    public Boolean visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws AsterixException {
+    public Boolean visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws CompilationException {
         if (selectSetOperation.getLeftInput().accept(this, arg)) {
             return true;
         }
@@ -149,7 +149,7 @@
     }
 
     @Override
-    public Boolean visit(SelectExpression selectStatement, ILangExpression arg) throws AsterixException {
+    public Boolean visit(SelectExpression selectStatement, ILangExpression arg) throws CompilationException {
         if (selectStatement.isSubquery()) {
             return true;
         }
@@ -159,53 +159,53 @@
     }
 
     @Override
-    public Boolean visit(UnnestClause unnestClause, ILangExpression arg) throws AsterixException {
+    public Boolean visit(UnnestClause unnestClause, ILangExpression arg) throws CompilationException {
         return visit(unnestClause.getRightExpression(), arg);
     }
 
     @Override
-    public Boolean visit(HavingClause havingClause, ILangExpression arg) throws AsterixException {
+    public Boolean visit(HavingClause havingClause, ILangExpression arg) throws CompilationException {
         return visit(havingClause.getFilterExpression(), arg);
     }
 
     @Override
-    public Boolean visit(IndependentSubquery independentSubquery, ILangExpression arg) throws AsterixException {
+    public Boolean visit(IndependentSubquery independentSubquery, ILangExpression arg) throws CompilationException {
         return visit(independentSubquery.getExpr(), arg);
     }
 
     @Override
-    public Boolean visit(CaseExpression caseExpression, ILangExpression arg) throws AsterixException {
+    public Boolean visit(CaseExpression caseExpression, ILangExpression arg) throws CompilationException {
         return visit(caseExpression.getConditionExpr(), arg) || visit(caseExpression.getWhenExprs(), arg)
                 || visit(caseExpression.getThenExprs(), arg) || visit(caseExpression.getElseExpr(), arg);
     }
 
     @Override
-    public Boolean visit(Query q, ILangExpression arg) throws AsterixException {
+    public Boolean visit(Query q, ILangExpression arg) throws CompilationException {
         return visit(q.getBody(), arg);
     }
 
     @Override
-    public Boolean visit(FunctionDecl fd, ILangExpression arg) throws AsterixException {
+    public Boolean visit(FunctionDecl fd, ILangExpression arg) throws CompilationException {
         return fd.getFuncBody().accept(this, arg);
     }
 
     @Override
-    public Boolean visit(LiteralExpr l, ILangExpression arg) throws AsterixException {
+    public Boolean visit(LiteralExpr l, ILangExpression arg) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(VariableExpr v, ILangExpression arg) throws AsterixException {
+    public Boolean visit(VariableExpr v, ILangExpression arg) throws CompilationException {
         return false;
     }
 
     @Override
-    public Boolean visit(ListConstructor lc, ILangExpression arg) throws AsterixException {
+    public Boolean visit(ListConstructor lc, ILangExpression arg) throws CompilationException {
         return visit(lc.getExprList(), arg);
     }
 
     @Override
-    public Boolean visit(RecordConstructor rc, ILangExpression arg) throws AsterixException {
+    public Boolean visit(RecordConstructor rc, ILangExpression arg) throws CompilationException {
         for (FieldBinding fb : rc.getFbList()) {
             if (visit(fb.getLeftExpr(), arg)) {
                 return true;
@@ -218,27 +218,27 @@
     }
 
     @Override
-    public Boolean visit(OperatorExpr operatorExpr, ILangExpression arg) throws AsterixException {
+    public Boolean visit(OperatorExpr operatorExpr, ILangExpression arg) throws CompilationException {
         return visit(operatorExpr.getExprList(), arg);
     }
 
     @Override
-    public Boolean visit(FieldAccessor fa, ILangExpression arg) throws AsterixException {
+    public Boolean visit(FieldAccessor fa, ILangExpression arg) throws CompilationException {
         return visit(fa.getExpr(), arg);
     }
 
     @Override
-    public Boolean visit(IndexAccessor ia, ILangExpression arg) throws AsterixException {
+    public Boolean visit(IndexAccessor ia, ILangExpression arg) throws CompilationException {
         return visit(ia.getExpr(), arg) || visit(ia.getIndexExpr(), arg);
     }
 
     @Override
-    public Boolean visit(IfExpr ifexpr, ILangExpression arg) throws AsterixException {
+    public Boolean visit(IfExpr ifexpr, ILangExpression arg) throws CompilationException {
         return visit(ifexpr.getCondExpr(), arg) || visit(ifexpr.getThenExpr(), arg) || visit(ifexpr.getElseExpr(), arg);
     }
 
     @Override
-    public Boolean visit(QuantifiedExpression qe, ILangExpression arg) throws AsterixException {
+    public Boolean visit(QuantifiedExpression qe, ILangExpression arg) throws CompilationException {
         for (QuantifiedPair qf : qe.getQuantifiedList()) {
             if (visit(qf.getExpr(), arg)) {
                 return true;
@@ -248,22 +248,22 @@
     }
 
     @Override
-    public Boolean visit(LetClause lc, ILangExpression arg) throws AsterixException {
+    public Boolean visit(LetClause lc, ILangExpression arg) throws CompilationException {
         return visit(lc.getBindingExpr(), arg);
     }
 
     @Override
-    public Boolean visit(WhereClause wc, ILangExpression arg) throws AsterixException {
+    public Boolean visit(WhereClause wc, ILangExpression arg) throws CompilationException {
         return visit(wc.getWhereExpr(), arg);
     }
 
     @Override
-    public Boolean visit(OrderbyClause oc, ILangExpression arg) throws AsterixException {
+    public Boolean visit(OrderbyClause oc, ILangExpression arg) throws CompilationException {
         return visit(oc.getOrderbyList(), arg);
     }
 
     @Override
-    public Boolean visit(GroupbyClause gc, ILangExpression arg) throws AsterixException {
+    public Boolean visit(GroupbyClause gc, ILangExpression arg) throws CompilationException {
         for (GbyVariableExpressionPair key : gc.getGbyPairList()) {
             if (visit(key.getExpr(), arg)) {
                 return true;
@@ -283,21 +283,21 @@
     }
 
     @Override
-    public Boolean visit(LimitClause lc, ILangExpression arg) throws AsterixException {
+    public Boolean visit(LimitClause lc, ILangExpression arg) throws CompilationException {
         return visit(lc.getLimitExpr(), arg) || visit(lc.getOffset(), arg);
     }
 
     @Override
-    public Boolean visit(UnaryExpr u, ILangExpression arg) throws AsterixException {
+    public Boolean visit(UnaryExpr u, ILangExpression arg) throws CompilationException {
         return visit(u.getExpr(), arg);
     }
 
     @Override
-    public Boolean visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+    public Boolean visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
         return visit(callExpr.getExprList(), arg);
     }
 
-    private boolean visit(List<?> langExprs, ILangExpression arg) throws AsterixException {
+    private boolean visit(List<?> langExprs, ILangExpression arg) throws CompilationException {
         for (Object o : langExprs) {
             ILangExpression langExpr = (ILangExpression) o;
             if (langExpr.accept(this, arg)) {
@@ -307,7 +307,7 @@
         return false;
     }
 
-    private boolean visit(ILangExpression langExpr, ILangExpression arg) throws AsterixException {
+    private boolean visit(ILangExpression langExpr, ILangExpression arg) throws CompilationException {
         if (langExpr == null) {
             return false;
         }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
index f6d3e7f..7c2a1747 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/DeepCopyVisitor.java
@@ -24,7 +24,7 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
@@ -74,7 +74,7 @@
 public class DeepCopyVisitor extends AbstractSqlppQueryExpressionVisitor<ILangExpression, Void> {
 
     @Override
-    public FromClause visit(FromClause fromClause, Void arg) throws AsterixException {
+    public FromClause visit(FromClause fromClause, Void arg) throws CompilationException {
         List<FromTerm> fromTerms = new ArrayList<>();
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
             fromTerms.add((FromTerm) fromTerm.accept(this, arg));
@@ -83,7 +83,7 @@
     }
 
     @Override
-    public FromTerm visit(FromTerm fromTerm, Void arg) throws AsterixException {
+    public FromTerm visit(FromTerm fromTerm, Void arg) throws CompilationException {
         // Visit the left expression of a from term.
         Expression fromExpr = (Expression) fromTerm.getLeftExpression().accept(this, arg);
         VariableExpr fromVar = (VariableExpr) fromTerm.getLeftVariable().accept(this, arg);
@@ -99,7 +99,7 @@
     }
 
     @Override
-    public JoinClause visit(JoinClause joinClause, Void arg) throws AsterixException {
+    public JoinClause visit(JoinClause joinClause, Void arg) throws CompilationException {
         Expression rightExpression = (Expression) joinClause.getRightExpression().accept(this, arg);
         VariableExpr rightVar = (VariableExpr) joinClause.getRightVariable().accept(this, arg);
         VariableExpr rightPositionVar = joinClause.getPositionalVariable() == null ? null
@@ -110,7 +110,7 @@
     }
 
     @Override
-    public NestClause visit(NestClause nestClause, Void arg) throws AsterixException {
+    public NestClause visit(NestClause nestClause, Void arg) throws CompilationException {
         Expression rightExpression = (Expression) nestClause.getRightExpression().accept(this, arg);
         VariableExpr rightVar = (VariableExpr) nestClause.getRightVariable().accept(this, arg);
         VariableExpr rightPositionVar = nestClause.getPositionalVariable() == null ? null
@@ -121,7 +121,7 @@
     }
 
     @Override
-    public UnnestClause visit(UnnestClause unnestClause, Void arg) throws AsterixException {
+    public UnnestClause visit(UnnestClause unnestClause, Void arg) throws CompilationException {
         Expression rightExpression = (Expression) unnestClause.getRightExpression().accept(this, arg);
         VariableExpr rightVar = (VariableExpr) unnestClause.getRightVariable().accept(this, arg);
         VariableExpr rightPositionVar = unnestClause.getPositionalVariable() == null ? null
@@ -130,14 +130,14 @@
     }
 
     @Override
-    public Projection visit(Projection projection, Void arg) throws AsterixException {
+    public Projection visit(Projection projection, Void arg) throws CompilationException {
         return new Projection(projection.star() ? null : (Expression) projection.getExpression().accept(this, arg),
                 projection.getName(),
                 projection.star(), projection.exprStar());
     }
 
     @Override
-    public SelectBlock visit(SelectBlock selectBlock, Void arg) throws AsterixException {
+    public SelectBlock visit(SelectBlock selectBlock, Void arg) throws CompilationException {
         FromClause fromClause = null;
         List<LetClause> letClauses = new ArrayList<>();
         WhereClause whereClause = null;
@@ -177,7 +177,7 @@
     }
 
     @Override
-    public SelectClause visit(SelectClause selectClause, Void arg) throws AsterixException {
+    public SelectClause visit(SelectClause selectClause, Void arg) throws CompilationException {
         SelectElement selectElement = null;
         SelectRegular selectRegular = null;
         if (selectClause.selectElement()) {
@@ -190,12 +190,12 @@
     }
 
     @Override
-    public SelectElement visit(SelectElement selectElement, Void arg) throws AsterixException {
+    public SelectElement visit(SelectElement selectElement, Void arg) throws CompilationException {
         return new SelectElement((Expression) selectElement.getExpression().accept(this, arg));
     }
 
     @Override
-    public SelectRegular visit(SelectRegular selectRegular, Void arg) throws AsterixException {
+    public SelectRegular visit(SelectRegular selectRegular, Void arg) throws CompilationException {
         List<Projection> projections = new ArrayList<>();
         for (Projection projection : selectRegular.getProjections()) {
             projections.add((Projection) projection.accept(this, arg));
@@ -204,7 +204,7 @@
     }
 
     @Override
-    public SelectSetOperation visit(SelectSetOperation selectSetOperation, Void arg) throws AsterixException {
+    public SelectSetOperation visit(SelectSetOperation selectSetOperation, Void arg) throws CompilationException {
         SetOperationInput leftInput = selectSetOperation.getLeftInput();
         SetOperationInput newLeftInput;
         if (leftInput.selectBlock()) {
@@ -227,28 +227,28 @@
     }
 
     @Override
-    public HavingClause visit(HavingClause havingClause, Void arg) throws AsterixException {
+    public HavingClause visit(HavingClause havingClause, Void arg) throws CompilationException {
         return new HavingClause((Expression) havingClause.getFilterExpression().accept(this, arg));
     }
 
     @Override
-    public Query visit(Query q, Void arg) throws AsterixException {
+    public Query visit(Query q, Void arg) throws CompilationException {
         return new Query(q.isExplain(), q.isTopLevel(), (Expression) q.getBody().accept(this, arg), q.getVarCounter(),
                 q.getDataverses(), q.getDatasets());
     }
 
     @Override
-    public FunctionDecl visit(FunctionDecl fd, Void arg) throws AsterixException {
+    public FunctionDecl visit(FunctionDecl fd, Void arg) throws CompilationException {
         return new FunctionDecl(fd.getSignature(), fd.getParamList(), (Expression) fd.getFuncBody().accept(this, arg));
     }
 
     @Override
-    public WhereClause visit(WhereClause whereClause, Void arg) throws AsterixException {
+    public WhereClause visit(WhereClause whereClause, Void arg) throws CompilationException {
         return new WhereClause((Expression) whereClause.getWhereExpr().accept(this, arg));
     }
 
     @Override
-    public OrderbyClause visit(OrderbyClause oc, Void arg) throws AsterixException {
+    public OrderbyClause visit(OrderbyClause oc, Void arg) throws CompilationException {
         List<Expression> newOrderbyList = new ArrayList<>();
         for (Expression orderExpr : oc.getOrderbyList()) {
             newOrderbyList.add((Expression) orderExpr.accept(this, arg));
@@ -257,7 +257,7 @@
     }
 
     @Override
-    public GroupbyClause visit(GroupbyClause gc, Void arg) throws AsterixException {
+    public GroupbyClause visit(GroupbyClause gc, Void arg) throws CompilationException {
         List<GbyVariableExpressionPair> gbyPairList = new ArrayList<>();
         List<GbyVariableExpressionPair> decorPairList = new ArrayList<>();
         Map<Expression, VariableExpr> withVarMap = new HashMap<>();
@@ -288,20 +288,20 @@
     }
 
     @Override
-    public LimitClause visit(LimitClause limitClause, Void arg) throws AsterixException {
+    public LimitClause visit(LimitClause limitClause, Void arg) throws CompilationException {
         Expression limitExpr = (Expression) limitClause.getLimitExpr().accept(this, arg);
         Expression offsetExpr = limitClause.hasOffset() ? (Expression) limitClause.getOffset().accept(this, arg) : null;
         return new LimitClause(limitExpr, offsetExpr);
     }
 
     @Override
-    public LetClause visit(LetClause letClause, Void arg) throws AsterixException {
+    public LetClause visit(LetClause letClause, Void arg) throws CompilationException {
         return new LetClause((VariableExpr) letClause.getVarExpr().accept(this, arg),
                 (Expression) letClause.getBindingExpr().accept(this, arg));
     }
 
     @Override
-    public SelectExpression visit(SelectExpression selectExpression, Void arg) throws AsterixException {
+    public SelectExpression visit(SelectExpression selectExpression, Void arg) throws CompilationException {
         List<LetClause> lets = new ArrayList<>();
         SelectSetOperation select;
         OrderbyClause orderby = null;
@@ -334,17 +334,17 @@
     }
 
     @Override
-    public LiteralExpr visit(LiteralExpr l, Void arg) throws AsterixException {
+    public LiteralExpr visit(LiteralExpr l, Void arg) throws CompilationException {
         return l;
     }
 
     @Override
-    public ListConstructor visit(ListConstructor lc, Void arg) throws AsterixException {
+    public ListConstructor visit(ListConstructor lc, Void arg) throws CompilationException {
         return new ListConstructor(lc.getType(), copyExprList(lc.getExprList(), arg));
     }
 
     @Override
-    public RecordConstructor visit(RecordConstructor rc, Void arg) throws AsterixException {
+    public RecordConstructor visit(RecordConstructor rc, Void arg) throws CompilationException {
         List<FieldBinding> bindings = new ArrayList<>();
         for (FieldBinding binding : rc.getFbList()) {
             FieldBinding fb = new FieldBinding((Expression) binding.getLeftExpr().accept(this, arg),
@@ -355,13 +355,13 @@
     }
 
     @Override
-    public OperatorExpr visit(OperatorExpr operatorExpr, Void arg) throws AsterixException {
+    public OperatorExpr visit(OperatorExpr operatorExpr, Void arg) throws CompilationException {
         return new OperatorExpr(copyExprList(operatorExpr.getExprList(), arg), operatorExpr.getExprBroadcastIdx(),
                 operatorExpr.getOpList(), operatorExpr.isCurrentop());
     }
 
     @Override
-    public IfExpr visit(IfExpr ifExpr, Void arg) throws AsterixException {
+    public IfExpr visit(IfExpr ifExpr, Void arg) throws CompilationException {
         Expression conditionExpr = (Expression) ifExpr.getCondExpr().accept(this, arg);
         Expression thenExpr = (Expression) ifExpr.getThenExpr().accept(this, arg);
         Expression elseExpr = (Expression) ifExpr.getElseExpr().accept(this, arg);
@@ -369,7 +369,7 @@
     }
 
     @Override
-    public QuantifiedExpression visit(QuantifiedExpression qe, Void arg) throws AsterixException {
+    public QuantifiedExpression visit(QuantifiedExpression qe, Void arg) throws CompilationException {
         List<QuantifiedPair> quantifiedPairs = new ArrayList<>();
         for (QuantifiedPair pair : qe.getQuantifiedList()) {
             Expression expr = (Expression) pair.getExpr().accept(this, arg);
@@ -381,7 +381,7 @@
     }
 
     @Override
-    public CallExpr visit(CallExpr callExpr, Void arg) throws AsterixException {
+    public CallExpr visit(CallExpr callExpr, Void arg) throws CompilationException {
         List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : callExpr.getExprList()) {
             newExprList.add((Expression) expr.accept(this, arg));
@@ -390,24 +390,24 @@
     }
 
     @Override
-    public VariableExpr visit(VariableExpr varExpr, Void arg) throws AsterixException {
+    public VariableExpr visit(VariableExpr varExpr, Void arg) throws CompilationException {
         VariableExpr clonedVar = new VariableExpr(new VarIdentifier(varExpr.getVar()));
         clonedVar.setIsNewVar(varExpr.getIsNewVar());
         return clonedVar;
     }
 
     @Override
-    public UnaryExpr visit(UnaryExpr u, Void arg) throws AsterixException {
+    public UnaryExpr visit(UnaryExpr u, Void arg) throws CompilationException {
         return new UnaryExpr(u.getExprType(), (Expression) u.getExpr().accept(this, arg));
     }
 
     @Override
-    public FieldAccessor visit(FieldAccessor fa, Void arg) throws AsterixException {
+    public FieldAccessor visit(FieldAccessor fa, Void arg) throws CompilationException {
         return new FieldAccessor((Expression) fa.getExpr().accept(this, arg), fa.getIdent());
     }
 
     @Override
-    public Expression visit(IndexAccessor ia, Void arg) throws AsterixException {
+    public Expression visit(IndexAccessor ia, Void arg) throws CompilationException {
         Expression expr = (Expression) ia.getExpr().accept(this, arg);
         Expression indexExpr = null;
         if (ia.getIndexExpr() != null) {
@@ -417,12 +417,12 @@
     }
 
     @Override
-    public ILangExpression visit(IndependentSubquery independentSubquery, Void arg) throws AsterixException {
+    public ILangExpression visit(IndependentSubquery independentSubquery, Void arg) throws CompilationException {
         return new IndependentSubquery((Expression) independentSubquery.getExpr().accept(this, arg));
     }
 
     @Override
-    public ILangExpression visit(CaseExpression caseExpr, Void arg) throws AsterixException {
+    public ILangExpression visit(CaseExpression caseExpr, Void arg) throws CompilationException {
         Expression conditionExpr = (Expression) caseExpr.getConditionExpr().accept(this, arg);
         List<Expression> whenExprList = copyExprList(caseExpr.getWhenExprs(), arg);
         List<Expression> thenExprList = copyExprList(caseExpr.getThenExprs(), arg);
@@ -430,7 +430,7 @@
         return new CaseExpression(conditionExpr, whenExprList, thenExprList, elseExpr);
     }
 
-    private List<Expression> copyExprList(List<Expression> exprs, Void arg) throws AsterixException {
+    private List<Expression> copyExprList(List<Expression> exprs, Void arg) throws CompilationException {
         List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : exprs) {
             newExprList.add((Expression) expr.accept(this, arg));
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/FreeVariableVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/FreeVariableVisitor.java
index 3a9bebf..e152b9b 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/FreeVariableVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/FreeVariableVisitor.java
@@ -22,9 +22,9 @@
 import java.util.HashSet;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.lang.common.base.Expression;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Clause.ClauseType;
+import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.clause.LimitClause;
@@ -71,7 +71,7 @@
 public class FreeVariableVisitor extends AbstractSqlppQueryExpressionVisitor<Void, Collection<VariableExpr>> {
 
     @Override
-    public Void visit(FromClause fromClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(FromClause fromClause, Collection<VariableExpr> freeVars) throws CompilationException {
         Collection<VariableExpr> bindingVars = new HashSet<>();
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
             Collection<VariableExpr> fromTermFreeVars = new HashSet<>();
@@ -91,7 +91,7 @@
     }
 
     @Override
-    public Void visit(FromTerm fromTerm, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(FromTerm fromTerm, Collection<VariableExpr> freeVars) throws CompilationException {
         // The encountered binding variables so far in the fromterm.
         Collection<VariableExpr> bindingVariables = new HashSet<>();
 
@@ -125,25 +125,25 @@
     }
 
     @Override
-    public Void visit(JoinClause joinClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(JoinClause joinClause, Collection<VariableExpr> freeVars) throws CompilationException {
         visitJoinAndNest(joinClause, joinClause.getConditionExpression(), freeVars);
         return null;
     }
 
     @Override
-    public Void visit(NestClause nestClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(NestClause nestClause, Collection<VariableExpr> freeVars) throws CompilationException {
         visitJoinAndNest(nestClause, nestClause.getConditionExpression(), freeVars);
         return null;
     }
 
     @Override
-    public Void visit(UnnestClause unnestClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(UnnestClause unnestClause, Collection<VariableExpr> freeVars) throws CompilationException {
         unnestClause.getRightExpression().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(Projection projection, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(Projection projection, Collection<VariableExpr> freeVars) throws CompilationException {
         if (!projection.star()) {
             projection.getExpression().accept(this, freeVars);
         }
@@ -151,7 +151,7 @@
     }
 
     @Override
-    public Void visit(SelectBlock selectBlock, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(SelectBlock selectBlock, Collection<VariableExpr> freeVars) throws CompilationException {
         Collection<VariableExpr> selectFreeVars = new HashSet<>();
         Collection<VariableExpr> fromFreeVars = new HashSet<>();
         Collection<VariableExpr> letsFreeVars = new HashSet<>();
@@ -213,7 +213,7 @@
     }
 
     @Override
-    public Void visit(SelectClause selectClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(SelectClause selectClause, Collection<VariableExpr> freeVars) throws CompilationException {
         if (selectClause.selectElement()) {
             selectClause.getSelectElement().accept(this, freeVars);
         }
@@ -224,13 +224,13 @@
     }
 
     @Override
-    public Void visit(SelectElement selectElement, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(SelectElement selectElement, Collection<VariableExpr> freeVars) throws CompilationException {
         selectElement.getExpression().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(SelectRegular selectRegular, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(SelectRegular selectRegular, Collection<VariableExpr> freeVars) throws CompilationException {
         for (Projection projection : selectRegular.getProjections()) {
             projection.accept(this, freeVars);
         }
@@ -239,7 +239,7 @@
 
     @Override
     public Void visit(SelectSetOperation selectSetOperation, Collection<VariableExpr> freeVars)
-            throws AsterixException {
+            throws CompilationException {
         selectSetOperation.getLeftInput().accept(this, freeVars);
         for (SetOperationRight right : selectSetOperation.getRightInputs()) {
             right.getSetOperationRightInput().accept(this, freeVars);
@@ -248,37 +248,37 @@
     }
 
     @Override
-    public Void visit(HavingClause havingClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(HavingClause havingClause, Collection<VariableExpr> freeVars) throws CompilationException {
         havingClause.getFilterExpression().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(Query q, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(Query q, Collection<VariableExpr> freeVars) throws CompilationException {
         q.getBody().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(FunctionDecl fd, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(FunctionDecl fd, Collection<VariableExpr> freeVars) throws CompilationException {
         fd.getFuncBody().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(WhereClause whereClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(WhereClause whereClause, Collection<VariableExpr> freeVars) throws CompilationException {
         whereClause.getWhereExpr().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(OrderbyClause oc, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(OrderbyClause oc, Collection<VariableExpr> freeVars) throws CompilationException {
         visit(oc.getOrderbyList(), freeVars);
         return null;
     }
 
     @Override
-    public Void visit(GroupbyClause gc, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(GroupbyClause gc, Collection<VariableExpr> freeVars) throws CompilationException {
         // Puts all group-by variables into the symbol set of the new scope.
         for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
             gbyVarExpr.getExpr().accept(this, freeVars);
@@ -295,19 +295,20 @@
     }
 
     @Override
-    public Void visit(LimitClause limitClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(LimitClause limitClause, Collection<VariableExpr> freeVars) throws CompilationException {
         limitClause.getLimitExpr().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(LetClause letClause, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(LetClause letClause, Collection<VariableExpr> freeVars) throws CompilationException {
         letClause.getBindingExpr().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(SelectExpression selectExpression, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(SelectExpression selectExpression, Collection<VariableExpr> freeVars)
+            throws CompilationException {
         Collection<VariableExpr> letsFreeVars = new HashSet<>();
         Collection<VariableExpr> selectFreeVars = new HashSet<>();
         visitLetClauses(selectExpression.getLetList(), letsFreeVars);
@@ -335,18 +336,18 @@
     }
 
     @Override
-    public Void visit(LiteralExpr l, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(LiteralExpr l, Collection<VariableExpr> freeVars) throws CompilationException {
         return null;
     }
 
     @Override
-    public Void visit(ListConstructor lc, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(ListConstructor lc, Collection<VariableExpr> freeVars) throws CompilationException {
         visit(lc.getExprList(), freeVars);
         return null;
     }
 
     @Override
-    public Void visit(RecordConstructor rc, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(RecordConstructor rc, Collection<VariableExpr> freeVars) throws CompilationException {
         for (FieldBinding binding : rc.getFbList()) {
             binding.getLeftExpr().accept(this, freeVars);
             binding.getRightExpr().accept(this, freeVars);
@@ -355,13 +356,13 @@
     }
 
     @Override
-    public Void visit(OperatorExpr operatorExpr, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(OperatorExpr operatorExpr, Collection<VariableExpr> freeVars) throws CompilationException {
         visit(operatorExpr.getExprList(), freeVars);
         return null;
     }
 
     @Override
-    public Void visit(IfExpr ifExpr, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(IfExpr ifExpr, Collection<VariableExpr> freeVars) throws CompilationException {
         ifExpr.getCondExpr().accept(this, freeVars);
         ifExpr.getThenExpr().accept(this, freeVars);
         ifExpr.getElseExpr().accept(this, freeVars);
@@ -369,7 +370,7 @@
     }
 
     @Override
-    public Void visit(QuantifiedExpression qe, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(QuantifiedExpression qe, Collection<VariableExpr> freeVars) throws CompilationException {
         for (QuantifiedPair pair : qe.getQuantifiedList()) {
             pair.getExpr().accept(this, freeVars);
         }
@@ -378,7 +379,7 @@
     }
 
     @Override
-    public Void visit(CallExpr callExpr, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(CallExpr callExpr, Collection<VariableExpr> freeVars) throws CompilationException {
         for (Expression expr : callExpr.getExprList()) {
             expr.accept(this, freeVars);
         }
@@ -386,25 +387,25 @@
     }
 
     @Override
-    public Void visit(VariableExpr varExpr, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(VariableExpr varExpr, Collection<VariableExpr> freeVars) throws CompilationException {
         freeVars.add(varExpr);
         return null;
     }
 
     @Override
-    public Void visit(UnaryExpr u, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(UnaryExpr u, Collection<VariableExpr> freeVars) throws CompilationException {
         u.getExpr().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(FieldAccessor fa, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(FieldAccessor fa, Collection<VariableExpr> freeVars) throws CompilationException {
         fa.getExpr().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(IndexAccessor ia, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(IndexAccessor ia, Collection<VariableExpr> freeVars) throws CompilationException {
         ia.getExpr().accept(this, freeVars);
         if (ia.getIndexExpr() != null) {
             ia.getIndexExpr();
@@ -414,13 +415,13 @@
 
     @Override
     public Void visit(IndependentSubquery independentSubquery, Collection<VariableExpr> freeVars)
-            throws AsterixException {
+            throws CompilationException {
         independentSubquery.getExpr().accept(this, freeVars);
         return null;
     }
 
     @Override
-    public Void visit(CaseExpression caseExpr, Collection<VariableExpr> freeVars) throws AsterixException {
+    public Void visit(CaseExpression caseExpr, Collection<VariableExpr> freeVars) throws CompilationException {
         caseExpr.getConditionExpr().accept(this, freeVars);
         visit(caseExpr.getWhenExprs(), freeVars);
         visit(caseExpr.getThenExprs(), freeVars);
@@ -429,7 +430,7 @@
     }
 
     private void visitLetClauses(List<LetClause> letClauses, Collection<VariableExpr> freeVars)
-            throws AsterixException {
+            throws CompilationException {
         if (letClauses == null || letClauses.isEmpty()) {
             return;
         }
@@ -448,7 +449,7 @@
     }
 
     private void visitJoinAndNest(AbstractBinaryCorrelateClause clause, Expression condition,
-            Collection<VariableExpr> freeVars) throws AsterixException {
+            Collection<VariableExpr> freeVars) throws CompilationException {
         clause.getRightExpression().accept(this, freeVars);
         Collection<VariableExpr> conditionFreeVars = new HashSet<>();
         condition.accept(this, freeVars);
@@ -461,7 +462,7 @@
         freeVars.addAll(conditionFreeVars);
     }
 
-    private void visit(List<Expression> exprs, Collection<VariableExpr> arg) throws AsterixException {
+    private void visit(List<Expression> exprs, Collection<VariableExpr> arg) throws CompilationException {
         for (Expression expr : exprs) {
             expr.accept(this, arg);
         }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
index 30caa4b..e52bee3 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppAstPrintVisitor.java
@@ -21,7 +21,7 @@
 import java.io.PrintWriter;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
@@ -67,7 +67,7 @@
     }
 
     @Override
-    public Void visit(FromClause fromClause, Integer step) throws AsterixException {
+    public Void visit(FromClause fromClause, Integer step) throws CompilationException {
         out.print(skip(step) + "FROM [");
         int index = 0;
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
@@ -82,7 +82,7 @@
     }
 
     @Override
-    public Void visit(FromTerm fromTerm, Integer step) throws AsterixException {
+    public Void visit(FromTerm fromTerm, Integer step) throws CompilationException {
         fromTerm.getLeftExpression().accept(this, step);
         out.print(skip(step) + "AS ");
         fromTerm.getLeftVariable().accept(this, 0);
@@ -99,7 +99,7 @@
     }
 
     @Override
-    public Void visit(JoinClause joinClause, Integer step) throws AsterixException {
+    public Void visit(JoinClause joinClause, Integer step) throws CompilationException {
         out.println(skip(step) + joinClause.getJoinType() + " JOIN");
         joinClause.getRightExpression().accept(this, step + 1);
         out.print(skip(step + 1) + "AS ");
@@ -114,7 +114,7 @@
     }
 
     @Override
-    public Void visit(NestClause nestClause, Integer step) throws AsterixException {
+    public Void visit(NestClause nestClause, Integer step) throws CompilationException {
         out.println(skip(step) + nestClause.getJoinType() + " NEST");
         nestClause.getRightExpression().accept(this, step + 1);
         out.print(skip(step + 1) + "AS ");
@@ -129,7 +129,7 @@
     }
 
     @Override
-    public Void visit(Projection projection, Integer step) throws AsterixException {
+    public Void visit(Projection projection, Integer step) throws CompilationException {
         if (projection.star()) {
             out.println(skip(step) + "*");
         } else {
@@ -140,7 +140,7 @@
     }
 
     @Override
-    public Void visit(SelectBlock selectBlock, Integer step) throws AsterixException {
+    public Void visit(SelectBlock selectBlock, Integer step) throws CompilationException {
         selectBlock.getSelectClause().accept(this, step);
         if (selectBlock.hasFromClause()) {
             selectBlock.getFromClause().accept(this, step);
@@ -168,7 +168,7 @@
     }
 
     @Override
-    public Void visit(SelectClause selectClause, Integer step) throws AsterixException {
+    public Void visit(SelectClause selectClause, Integer step) throws CompilationException {
         if (selectClause.selectRegular()) {
             selectClause.getSelectRegular().accept(this, step);
         }
@@ -179,7 +179,7 @@
     }
 
     @Override
-    public Void visit(SelectElement selectElement, Integer step) throws AsterixException {
+    public Void visit(SelectElement selectElement, Integer step) throws CompilationException {
         out.println(skip(step) + "SELECT ELEMENT [");
         selectElement.getExpression().accept(this, step);
         out.println(skip(step) + "]");
@@ -187,7 +187,7 @@
     }
 
     @Override
-    public Void visit(SelectRegular selectRegular, Integer step) throws AsterixException {
+    public Void visit(SelectRegular selectRegular, Integer step) throws CompilationException {
         out.println(skip(step) + "SELECT [");
         for (Projection projection : selectRegular.getProjections()) {
             projection.accept(this, step);
@@ -197,7 +197,7 @@
     }
 
     @Override
-    public Void visit(SelectSetOperation selectSetOperation, Integer step) throws AsterixException {
+    public Void visit(SelectSetOperation selectSetOperation, Integer step) throws CompilationException {
         selectSetOperation.getLeftInput().accept(this, step);
         if (selectSetOperation.hasRightInputs()) {
             for (SetOperationRight right : selectSetOperation.getRightInputs()) {
@@ -210,7 +210,7 @@
     }
 
     @Override
-    public Void visit(SelectExpression selectStatement, Integer step) throws AsterixException {
+    public Void visit(SelectExpression selectStatement, Integer step) throws CompilationException {
         if (selectStatement.isSubquery()) {
             out.println(skip(step) + "(");
         }
@@ -234,7 +234,7 @@
     }
 
     @Override
-    public Void visit(UnnestClause unnestClause, Integer step) throws AsterixException {
+    public Void visit(UnnestClause unnestClause, Integer step) throws CompilationException {
         out.println(skip(step) + unnestClause.getJoinType() + " UNNEST");
         unnestClause.getRightExpression().accept(this, step + 1);
         out.print(skip(step + 1) + " AS ");
@@ -247,14 +247,14 @@
     }
 
     @Override
-    public Void visit(HavingClause havingClause, Integer step) throws AsterixException {
+    public Void visit(HavingClause havingClause, Integer step) throws CompilationException {
         out.println(skip(step) + " HAVING");
         havingClause.getFilterExpression().accept(this, step + 1);
         return null;
     }
 
     @Override
-    public Void visit(CallExpr pf, Integer step) throws AsterixException {
+    public Void visit(CallExpr pf, Integer step) throws CompilationException {
         FunctionSignature functionSignature = pf.getFunctionSignature();
         FunctionSignature normalizedFunctionSignature =
                 FunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature, false);
@@ -270,7 +270,7 @@
     }
 
     @Override
-    public Void visit(GroupbyClause gc, Integer step) throws AsterixException {
+    public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
         if (gc.isGroupAll()) {
             out.println(skip(step) + "Group All");
             return null;
@@ -300,13 +300,13 @@
     }
 
     @Override
-    public Void visit(IndependentSubquery independentSubquery, Integer arg) throws AsterixException {
+    public Void visit(IndependentSubquery independentSubquery, Integer arg) throws CompilationException {
         independentSubquery.getExpr().accept(this, arg);
         return null;
     }
 
     @Override
-    public Void visit(CaseExpression caseExpr, Integer step) throws AsterixException {
+    public Void visit(CaseExpression caseExpr, Integer step) throws CompilationException {
         out.print(skip(step) + "CASE");
         caseExpr.getConditionExpr().accept(this, step + 2);
         out.println();
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppCloneAndSubstituteVariablesVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppCloneAndSubstituteVariablesVisitor.java
index 81aba54..9579741 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppCloneAndSubstituteVariablesVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppCloneAndSubstituteVariablesVisitor.java
@@ -21,10 +21,10 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.lang.common.base.Clause.ClauseType;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
-import org.apache.asterix.lang.common.base.Clause.ClauseType;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
 import org.apache.asterix.lang.common.clause.LimitClause;
@@ -68,7 +68,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FromClause fromClause,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
         List<FromTerm> newFromTerms = new ArrayList<>();
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
@@ -83,7 +83,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FromTerm fromTerm,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         VariableExpr leftVar = fromTerm.getLeftVariable();
         VariableExpr newLeftVar = generateNewVariable(context, leftVar);
         VariableExpr newLeftPosVar = fromTerm.hasPositionalVariable() ? generateNewVariable(context,
@@ -120,7 +120,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(JoinClause joinClause,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         VariableExpr rightVar = joinClause.getRightVariable();
         VariableExpr newRightVar = generateNewVariable(context, rightVar);
         VariableExpr newRightPosVar = joinClause.hasPositionalVariable() ? generateNewVariable(context,
@@ -145,7 +145,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(NestClause nestClause,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         VariableExpr rightVar = nestClause.getRightVariable();
         VariableExpr newRightVar = generateNewVariable(context, rightVar);
         VariableExpr newRightPosVar = nestClause.hasPositionalVariable() ? generateNewVariable(context,
@@ -170,7 +170,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(UnnestClause unnestClause,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         VariableExpr rightVar = unnestClause.getRightVariable();
         VariableExpr newRightVar = generateNewVariable(context, rightVar);
         VariableExpr newRightPosVar = unnestClause.hasPositionalVariable() ? generateNewVariable(context,
@@ -193,7 +193,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(Projection projection,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         if (projection.star()) {
             return new Pair<>(projection, env);
         }
@@ -204,7 +204,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectBlock selectBlock,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> newFrom = null;
         Pair<ILangExpression, VariableSubstitutionEnvironment> newLet;
         Pair<ILangExpression, VariableSubstitutionEnvironment> newWhere = null;
@@ -262,7 +262,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectClause selectClause,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         boolean distinct = selectClause.distinct();
         if (selectClause.selectElement()) {
             Pair<ILangExpression, VariableSubstitutionEnvironment> newSelectElement = selectClause.getSelectElement()
@@ -279,7 +279,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectElement selectElement,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> newExpr = selectElement.getExpression()
                 .accept(this, env);
         return new Pair<>(new SelectElement((Expression) newExpr.first), newExpr.second);
@@ -287,7 +287,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectRegular selectRegular,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         List<Projection> newProjections = new ArrayList<>();
         for (Projection projection : selectRegular.getProjections()) {
             newProjections.add((Projection) projection.accept(this, env).first);
@@ -297,7 +297,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectSetOperation selectSetOperation,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         SetOperationInput leftInput = selectSetOperation.getLeftInput();
         SetOperationInput newLeftInput;
 
@@ -335,7 +335,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectExpression selectExpression,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         boolean subquery = selectExpression.isSubquery();
         List<LetClause> newLetList = new ArrayList<>();
         SelectSetOperation newSelectSetOperation;
@@ -374,7 +374,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(HavingClause havingClause,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p = havingClause.getFilterExpression().accept(this, env);
         HavingClause newHavingClause = new HavingClause((Expression) p.first);
         return new Pair<>(newHavingClause, p.second);
@@ -382,7 +382,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(IndependentSubquery independentSubquery,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Pair<ILangExpression, VariableSubstitutionEnvironment> p = independentSubquery.getExpr().accept(this, env);
         IndependentSubquery newSubquery = new IndependentSubquery((Expression) p.first);
         return new Pair<>(newSubquery, p.second);
@@ -390,7 +390,7 @@
 
     @Override
     public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(CaseExpression caseExpr,
-            VariableSubstitutionEnvironment env) throws AsterixException {
+            VariableSubstitutionEnvironment env) throws CompilationException {
         Expression conditionExpr = (Expression) caseExpr.getConditionExpr().accept(this, env).first;
         List<Expression> whenExprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(caseExpr.getWhenExprs(),
                 env, this);
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java
index 1beba9b..a62a1cc 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppFormatPrintVisitor.java
@@ -21,7 +21,7 @@
 import java.io.PrintWriter;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
@@ -68,7 +68,7 @@
     }
 
     @Override
-    public Void visit(FromClause fromClause, Integer step) throws AsterixException {
+    public Void visit(FromClause fromClause, Integer step) throws CompilationException {
         out.print(skip(step) + "from ");
         int index = 0;
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
@@ -83,7 +83,7 @@
     }
 
     @Override
-    public Void visit(FromTerm fromTerm, Integer step) throws AsterixException {
+    public Void visit(FromTerm fromTerm, Integer step) throws CompilationException {
         fromTerm.getLeftExpression().accept(this, step + 2);
         out.print(" as ");
         fromTerm.getLeftVariable().accept(this, step + 2);
@@ -100,7 +100,7 @@
     }
 
     @Override
-    public Void visit(JoinClause joinClause, Integer step) throws AsterixException {
+    public Void visit(JoinClause joinClause, Integer step) throws CompilationException {
         out.print(joinClause.getJoinType());
         joinClause.getRightExpression().accept(this, step + 2);
         out.print(" as ");
@@ -114,7 +114,7 @@
     }
 
     @Override
-    public Void visit(NestClause nestClause, Integer step) throws AsterixException {
+    public Void visit(NestClause nestClause, Integer step) throws CompilationException {
         out.print(nestClause.getJoinType());
         nestClause.getRightExpression().accept(this, step + 2);
         out.println(skip(step + 1) + " as ");
@@ -128,7 +128,7 @@
     }
 
     @Override
-    public Void visit(Projection projection, Integer step) throws AsterixException {
+    public Void visit(Projection projection, Integer step) throws CompilationException {
         if (projection.star()) {
             out.print(" * ");
             return null;
@@ -142,7 +142,7 @@
     }
 
     @Override
-    public Void visit(SelectBlock selectBlock, Integer step) throws AsterixException {
+    public Void visit(SelectBlock selectBlock, Integer step) throws CompilationException {
         selectBlock.getSelectClause().accept(this, step);
         if (selectBlock.hasFromClause()) {
             selectBlock.getFromClause().accept(this, step);
@@ -170,7 +170,7 @@
     }
 
     @Override
-    public Void visit(SelectClause selectClause, Integer step) throws AsterixException {
+    public Void visit(SelectClause selectClause, Integer step) throws CompilationException {
         if (selectClause.selectRegular()) {
             selectClause.getSelectRegular().accept(this, step);
         }
@@ -182,14 +182,14 @@
     }
 
     @Override
-    public Void visit(SelectElement selectElement, Integer step) throws AsterixException {
+    public Void visit(SelectElement selectElement, Integer step) throws CompilationException {
         out.print("select element ");
         selectElement.getExpression().accept(this, step);
         return null;
     }
 
     @Override
-    public Void visit(SelectRegular selectRegular, Integer step) throws AsterixException {
+    public Void visit(SelectRegular selectRegular, Integer step) throws CompilationException {
         out.print("select ");
         int index = 0;
         for (Projection projection : selectRegular.getProjections()) {
@@ -203,7 +203,7 @@
     }
 
     @Override
-    public Void visit(SelectSetOperation selectSetOperation, Integer step) throws AsterixException {
+    public Void visit(SelectSetOperation selectSetOperation, Integer step) throws CompilationException {
         selectSetOperation.getLeftInput().accept(this, step);
         if (selectSetOperation.hasRightInputs()) {
             for (SetOperationRight right : selectSetOperation.getRightInputs()) {
@@ -216,7 +216,7 @@
     }
 
     @Override
-    public Void visit(SelectExpression selectStatement, Integer step) throws AsterixException {
+    public Void visit(SelectExpression selectStatement, Integer step) throws CompilationException {
         if (selectStatement.isSubquery()) {
             out.print("(");
         }
@@ -240,7 +240,7 @@
     }
 
     @Override
-    public Void visit(UnnestClause unnestClause, Integer step) throws AsterixException {
+    public Void visit(UnnestClause unnestClause, Integer step) throws CompilationException {
         out.print(unnestClause.getJoinType());
         unnestClause.getRightExpression().accept(this, step + 2);
         out.print(" as ");
@@ -253,7 +253,7 @@
     }
 
     @Override
-    public Void visit(HavingClause havingClause, Integer step) throws AsterixException {
+    public Void visit(HavingClause havingClause, Integer step) throws CompilationException {
         out.print(skip(step) + " having ");
         havingClause.getFilterExpression().accept(this, step + 2);
         out.println();
@@ -261,7 +261,7 @@
     }
 
     @Override
-    public Void visit(GroupbyClause gc, Integer step) throws AsterixException {
+    public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
         if (gc.hasHashGroupByHint()) {
             out.println(skip(step) + "/* +hash */");
         }
@@ -272,7 +272,7 @@
     }
 
     @Override
-    public Void visit(InsertStatement insert, Integer step) throws AsterixException {
+    public Void visit(InsertStatement insert, Integer step) throws CompilationException {
         out.print(skip(step) + "insert into " + datasetSymbol
                 + generateFullName(insert.getDataverseName(), insert.getDatasetName()) + "\n");
         insert.getQuery().accept(this, step);
@@ -281,7 +281,7 @@
     }
 
     @Override
-    public Void visit(LetClause lc, Integer step) throws AsterixException {
+    public Void visit(LetClause lc, Integer step) throws CompilationException {
         out.print(skip(step) + "with ");
         Expression bindingExpr = lc.getBindingExpr();
         bindingExpr.accept(this, step + 2);
@@ -293,7 +293,7 @@
 
     @Override
     protected void printDelimitedGbyExpressions(List<GbyVariableExpressionPair> gbyList, int step)
-            throws AsterixException {
+            throws CompilationException {
         int gbySize = gbyList.size();
         int gbyIndex = 0;
         for (GbyVariableExpressionPair pair : gbyList) {
@@ -309,13 +309,13 @@
     }
 
     @Override
-    public Void visit(IndependentSubquery independentSubquery, Integer step) throws AsterixException {
+    public Void visit(IndependentSubquery independentSubquery, Integer step) throws CompilationException {
         independentSubquery.getExpr().accept(this, step);
         return null;
     }
 
     @Override
-    public Void visit(CaseExpression caseExpr, Integer step) throws AsterixException {
+    public Void visit(CaseExpression caseExpr, Integer step) throws CompilationException {
         out.print(skip(step) + "case ");
         caseExpr.getConditionExpr().accept(this, step + 2);
         out.println();
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppSubstituteExpressionVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppSubstituteExpressionVisitor.java
index 9b19d7c..39229e2 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppSubstituteExpressionVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/SqlppSubstituteExpressionVisitor.java
@@ -22,7 +22,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.context.Scope;
 import org.apache.asterix.lang.common.expression.VariableExpr;
@@ -49,7 +49,7 @@
     // An example is:
     // asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/gby-expr-3/gby-expr-3.3.query.sqlpp
     @Override
-    protected Expression preVisit(Expression expr) throws AsterixException {
+    protected Expression preVisit(Expression expr) throws CompilationException {
         Expression mappedExpr = exprMap.get(expr);
         if (mappedExpr == null) {
             return expr;
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppAstVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppAstVisitor.java
index c0947f3..ec17484 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppAstVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppAstVisitor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.sqlpp.visitor.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.visitor.base.AbstractAstVisitor;
 import org.apache.asterix.lang.sqlpp.clause.FromClause;
 import org.apache.asterix.lang.sqlpp.clause.FromTerm;
@@ -42,77 +42,77 @@
 public abstract class AbstractSqlppAstVisitor<R, T> extends AbstractAstVisitor<R, T> implements ISqlppVisitor<R, T> {
 
     @Override
-    public R visit(FromClause fromClause, T arg) throws AsterixException {
+    public R visit(FromClause fromClause, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(FromTerm fromTerm, T arg) throws AsterixException {
+    public R visit(FromTerm fromTerm, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(JoinClause joinClause, T arg) throws AsterixException {
+    public R visit(JoinClause joinClause, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(NestClause nestClause, T arg) throws AsterixException {
+    public R visit(NestClause nestClause, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(Projection projection, T arg) throws AsterixException {
+    public R visit(Projection projection, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(SelectBlock selectBlock, T arg) throws AsterixException {
+    public R visit(SelectBlock selectBlock, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(SelectClause selectClause, T arg) throws AsterixException {
+    public R visit(SelectClause selectClause, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(SelectElement selectElement, T arg) throws AsterixException {
+    public R visit(SelectElement selectElement, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(SelectRegular selectRegular, T arg) throws AsterixException {
+    public R visit(SelectRegular selectRegular, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(SelectSetOperation selectSetOperation, T arg) throws AsterixException {
+    public R visit(SelectSetOperation selectSetOperation, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(SelectExpression selectStatement, T arg) throws AsterixException {
+    public R visit(SelectExpression selectStatement, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(UnnestClause unnestClause, T arg) throws AsterixException {
+    public R visit(UnnestClause unnestClause, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(HavingClause havingClause, T arg) throws AsterixException {
+    public R visit(HavingClause havingClause, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(IndependentSubquery independentSubquery, T arg) throws AsterixException {
+    public R visit(IndependentSubquery independentSubquery, T arg) throws CompilationException {
         return null;
     }
 
     @Override
-    public R visit(CaseExpression caseExpr, T arg) throws AsterixException {
+    public R visit(CaseExpression caseExpr, T arg) throws CompilationException {
         return null;
     }
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
index c289ebe..96c5987 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppExpressionScopingVisitor.java
@@ -22,10 +22,10 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.Map.Entry;
+import java.util.Set;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
@@ -58,8 +58,8 @@
 import org.apache.asterix.lang.sqlpp.expression.SelectExpression;
 import org.apache.asterix.lang.sqlpp.struct.SetOperationRight;
 import org.apache.asterix.lang.sqlpp.util.SqlppVariableUtil;
-import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.asterix.metadata.utils.MetadataConstants;
+import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.core.algebra.base.Counter;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 
@@ -80,7 +80,7 @@
     }
 
     @Override
-    public Expression visit(FromClause fromClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(FromClause fromClause, ILangExpression arg) throws CompilationException {
         Scope scopeForFromClause = scopeChecker.extendCurrentScope();
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
             fromTerm.accept(this, fromClause);
@@ -93,7 +93,7 @@
     }
 
     @Override
-    public Expression visit(FromTerm fromTerm, ILangExpression arg) throws AsterixException {
+    public Expression visit(FromTerm fromTerm, ILangExpression arg) throws CompilationException {
         scopeChecker.createNewScope();
         // Visit the left expression of a from term.
         fromTerm.setLeftExpression(visit(fromTerm.getLeftExpression(), fromTerm));
@@ -115,7 +115,7 @@
     }
 
     @Override
-    public Expression visit(JoinClause joinClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(JoinClause joinClause, ILangExpression arg) throws CompilationException {
         Scope leftScope = scopeChecker.removeCurrentScope();
         scopeChecker.createNewScope();
         // NOTE: the two join branches cannot be correlated, instead of checking
@@ -143,7 +143,7 @@
     }
 
     @Override
-    public Expression visit(NestClause nestClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(NestClause nestClause, ILangExpression arg) throws CompilationException {
         // NOTE: the two branches of a NEST cannot be correlated, instead of
         // checking the correlation here, we defer the check to the query
         // optimizer.
@@ -166,7 +166,7 @@
     }
 
     @Override
-    public Expression visit(UnnestClause unnestClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(UnnestClause unnestClause, ILangExpression arg) throws CompilationException {
         unnestClause.setRightExpression(visit(unnestClause.getRightExpression(), unnestClause));
 
         // register the data item variable
@@ -182,7 +182,7 @@
     }
 
     @Override
-    public Expression visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws CompilationException {
         Scope scopeBeforeCurrentBranch = scopeChecker.getCurrentScope();
         scopeChecker.createNewScope();
         selectSetOperation.getLeftInput().accept(this, arg);
@@ -204,7 +204,7 @@
     }
 
     @Override
-    public Expression visit(Query q, ILangExpression arg) throws AsterixException {
+    public Expression visit(Query q, ILangExpression arg) throws CompilationException {
         q.setBody(visit(q.getBody(), q));
         q.setVarCounter(scopeChecker.getVarCounter());
         context.setVarCounter(scopeChecker.getVarCounter());
@@ -212,7 +212,7 @@
     }
 
     @Override
-    public Expression visit(FunctionDecl fd, ILangExpression arg) throws AsterixException {
+    public Expression visit(FunctionDecl fd, ILangExpression arg) throws CompilationException {
         scopeChecker.createNewScope();
         fd.setFuncBody(visit(fd.getFuncBody(), fd));
         scopeChecker.removeCurrentScope();
@@ -220,7 +220,7 @@
     }
 
     @Override
-    public Expression visit(GroupbyClause gc, ILangExpression arg) throws AsterixException {
+    public Expression visit(GroupbyClause gc, ILangExpression arg) throws CompilationException {
         // After a GROUP BY, variables defined before the current SELECT BLOCK (e.g., in a WITH clause
         // or an outer scope query) should still be visible.
         Scope newScope = new Scope(scopeChecker, scopeChecker.getCurrentScope().getParentScope());
@@ -266,7 +266,7 @@
     }
 
     @Override
-    public Expression visit(LimitClause limitClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(LimitClause limitClause, ILangExpression arg) throws CompilationException {
         scopeChecker.pushForbiddenScope(scopeChecker.getCurrentScope());
         limitClause.setLimitExpr(visit(limitClause.getLimitExpr(), limitClause));
         if(limitClause.hasOffset()) {
@@ -277,7 +277,7 @@
     }
 
     @Override
-    public Expression visit(LetClause letClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(LetClause letClause, ILangExpression arg) throws CompilationException {
         scopeChecker.extendCurrentScope();
         letClause.setBindingExpr(visit(letClause.getBindingExpr(), letClause));
         addNewVarSymbolToScope(scopeChecker.getCurrentScope(), letClause.getVarExpr().getVar());
@@ -285,7 +285,7 @@
     }
 
     @Override
-    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws CompilationException {
         Scope scopeBeforeSelectExpression = scopeChecker.getCurrentScope();
         scopeChecker.createNewScope();
 
@@ -320,7 +320,7 @@
     }
 
     @Override
-    public Expression visit(IndependentSubquery independentSubquery, ILangExpression arg) throws AsterixException {
+    public Expression visit(IndependentSubquery independentSubquery, ILangExpression arg) throws CompilationException {
         // Masks parent scopes so as that the subquery is independent of the environment.
         // In this way, free variables defined in the subquery will not be resolved using
         // variables defined in the parent scope.
@@ -332,7 +332,7 @@
     }
 
     @Override
-    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws AsterixException {
+    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws CompilationException {
         scopeChecker.createNewScope();
         for (QuantifiedPair pair : qe.getQuantifiedList()) {
             pair.setExpr(visit(pair.getExpr(), qe));
@@ -344,10 +344,10 @@
     }
 
     @Override
-    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws CompilationException {
         String varName = varExpr.getVar().getValue();
         if (scopeChecker.isInForbiddenScopes(varName)) {
-            throw new AsterixException(
+            throw new CompilationException(
                     "Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.");
         }
         Identifier ident = scopeChecker.lookupSymbol(varName);
@@ -361,7 +361,7 @@
     }
 
     @Override
-    public Expression visit(InsertStatement insertStatement, ILangExpression arg) throws AsterixException {
+    public Expression visit(InsertStatement insertStatement, ILangExpression arg) throws CompilationException {
         scopeChecker.createNewScope();
 
         // Visits the body query.
@@ -383,7 +383,7 @@
 
     // Rewrites for an undefined variable reference, which potentially could be a syntatic sugar.
     protected Expression wrapWithResolveFunction(VariableExpr expr, Set<VariableExpr> liveVars)
-            throws AsterixException {
+            throws CompilationException {
         List<Expression> argList = new ArrayList<>();
         //Ignore the parser-generated prefix "$" for a dataset.
         String varName = SqlppVariableUtil.toUserDefinedVariableName(expr.getVar().getValue()).getValue();
@@ -393,20 +393,21 @@
     }
 
     // Adds a new encountered alias identifier into a scope
-    private void addNewVarSymbolToScope(Scope scope, VarIdentifier var) throws AsterixException {
+    private void addNewVarSymbolToScope(Scope scope, VarIdentifier var) throws CompilationException {
         if (scope.findLocalSymbol(var.getValue()) != null) {
-            throw new AsterixException("Duplicate alias definitions: "
+            throw new CompilationException("Duplicate alias definitions: "
                     + SqlppVariableUtil.toUserDefinedName(var.getValue()));
         }
         scope.addNewVarSymbolToScope(var);
     }
 
     // Merges <code>scopeToBeMerged</code> into <code>hostScope</code>.
-    private void mergeScopes(Scope hostScope, Scope scopeToBeMerged) throws AsterixException {
+    private void mergeScopes(Scope hostScope, Scope scopeToBeMerged) throws CompilationException {
         Set<String> symbolsToBeMerged = scopeToBeMerged.getLocalSymbols();
         for (String symbolToBeMerged : symbolsToBeMerged) {
             if (hostScope.findLocalSymbol(symbolToBeMerged) != null) {
-                throw new AsterixException("Duplicate alias definitions: "
+                throw new CompilationException(
+                        "Duplicate alias definitions: "
                         + SqlppVariableUtil.toUserDefinedName(symbolToBeMerged));
             }
         }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
index f788aea..d754702 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/AbstractSqlppSimpleExpressionVisitor.java
@@ -21,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
@@ -68,7 +68,7 @@
         extends AbstractSqlppQueryExpressionVisitor<Expression, ILangExpression> {
 
     @Override
-    public Expression visit(FromClause fromClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(FromClause fromClause, ILangExpression arg) throws CompilationException {
         for (FromTerm fromTerm : fromClause.getFromTerms()) {
             visit(fromTerm, arg);
         }
@@ -76,7 +76,7 @@
     }
 
     @Override
-    public Expression visit(FromTerm fromTerm, ILangExpression arg) throws AsterixException {
+    public Expression visit(FromTerm fromTerm, ILangExpression arg) throws CompilationException {
         // Visit the left expression of a from term.
         fromTerm.setLeftExpression(visit(fromTerm.getLeftExpression(), arg));
 
@@ -88,27 +88,27 @@
     }
 
     @Override
-    public Expression visit(JoinClause joinClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(JoinClause joinClause, ILangExpression arg) throws CompilationException {
         joinClause.setRightExpression(visit(joinClause.getRightExpression(), arg));
         joinClause.setConditionExpression(visit(joinClause.getConditionExpression(), arg));
         return null;
     }
 
     @Override
-    public Expression visit(NestClause nestClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(NestClause nestClause, ILangExpression arg) throws CompilationException {
         nestClause.setRightExpression(visit(nestClause.getRightExpression(), arg));
         nestClause.setConditionExpression(visit(nestClause.getConditionExpression(), arg));
         return null;
     }
 
     @Override
-    public Expression visit(UnnestClause unnestClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(UnnestClause unnestClause, ILangExpression arg) throws CompilationException {
         unnestClause.setRightExpression(visit(unnestClause.getRightExpression(), arg));
         return null;
     }
 
     @Override
-    public Expression visit(Projection projection, ILangExpression arg) throws AsterixException {
+    public Expression visit(Projection projection, ILangExpression arg) throws CompilationException {
         if (!projection.star()) {
             projection.setExpression(visit(projection.getExpression(), arg));
         }
@@ -116,7 +116,7 @@
     }
 
     @Override
-    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
         // Traverses the select block in the order of "from", "let"s, "where",
         // "group by", "let"s, "having" and "select".
         if (selectBlock.hasFromClause()) {
@@ -148,7 +148,7 @@
     }
 
     @Override
-    public Expression visit(SelectClause selectClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectClause selectClause, ILangExpression arg) throws CompilationException {
         if (selectClause.selectElement()) {
             selectClause.getSelectElement().accept(this, selectClause);
         }
@@ -159,13 +159,13 @@
     }
 
     @Override
-    public Expression visit(SelectElement selectElement, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectElement selectElement, ILangExpression arg) throws CompilationException {
         selectElement.setExpression(visit(selectElement.getExpression(), selectElement));
         return null;
     }
 
     @Override
-    public Expression visit(SelectRegular selectRegular, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectRegular selectRegular, ILangExpression arg) throws CompilationException {
         for (Projection projection : selectRegular.getProjections()) {
             projection.accept(this, arg);
         }
@@ -173,7 +173,7 @@
     }
 
     @Override
-    public Expression visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws CompilationException {
         selectSetOperation.getLeftInput().accept(this, arg);
         for (SetOperationRight right : selectSetOperation.getRightInputs()) {
             right.getSetOperationRightInput().accept(this, arg);
@@ -182,37 +182,37 @@
     }
 
     @Override
-    public Expression visit(HavingClause havingClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(HavingClause havingClause, ILangExpression arg) throws CompilationException {
         havingClause.setFilterExpression(visit(havingClause.getFilterExpression(), havingClause));
         return null;
     }
 
     @Override
-    public Expression visit(Query q, ILangExpression arg) throws AsterixException {
+    public Expression visit(Query q, ILangExpression arg) throws CompilationException {
         q.setBody(visit(q.getBody(), q));
         return null;
     }
 
     @Override
-    public Expression visit(FunctionDecl fd, ILangExpression arg) throws AsterixException {
+    public Expression visit(FunctionDecl fd, ILangExpression arg) throws CompilationException {
         fd.setFuncBody(visit(fd.getFuncBody(), fd));
         return null;
     }
 
     @Override
-    public Expression visit(WhereClause whereClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(WhereClause whereClause, ILangExpression arg) throws CompilationException {
         whereClause.setWhereExpr(visit(whereClause.getWhereExpr(), whereClause));
         return null;
     }
 
     @Override
-    public Expression visit(OrderbyClause oc, ILangExpression arg) throws AsterixException {
+    public Expression visit(OrderbyClause oc, ILangExpression arg) throws CompilationException {
         oc.setOrderbyList(visit(oc.getOrderbyList(), arg));
         return null;
     }
 
     @Override
-    public Expression visit(GroupbyClause gc, ILangExpression arg) throws AsterixException {
+    public Expression visit(GroupbyClause gc, ILangExpression arg) throws CompilationException {
         for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
             gbyVarExpr.setExpr(visit(gbyVarExpr.getExpr(), gc));
         }
@@ -220,7 +220,7 @@
     }
 
     @Override
-    public Expression visit(LimitClause limitClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(LimitClause limitClause, ILangExpression arg) throws CompilationException {
         limitClause.setLimitExpr(visit(limitClause.getLimitExpr(), limitClause));
         if (limitClause.hasOffset()) {
             limitClause.setOffset(visit(limitClause.getOffset(), limitClause));
@@ -229,13 +229,13 @@
     }
 
     @Override
-    public Expression visit(LetClause letClause, ILangExpression arg) throws AsterixException {
+    public Expression visit(LetClause letClause, ILangExpression arg) throws CompilationException {
         letClause.setBindingExpr(visit(letClause.getBindingExpr(), letClause));
         return null;
     }
 
     @Override
-    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws AsterixException {
+    public Expression visit(SelectExpression selectExpression, ILangExpression arg) throws CompilationException {
         // visit let list
         if (selectExpression.hasLetClauses()) {
             for (LetClause letClause : selectExpression.getLetList()) {
@@ -259,18 +259,18 @@
     }
 
     @Override
-    public Expression visit(LiteralExpr l, ILangExpression arg) throws AsterixException {
+    public Expression visit(LiteralExpr l, ILangExpression arg) throws CompilationException {
         return l;
     }
 
     @Override
-    public Expression visit(ListConstructor lc, ILangExpression arg) throws AsterixException {
+    public Expression visit(ListConstructor lc, ILangExpression arg) throws CompilationException {
         lc.setExprList(visit(lc.getExprList(), arg));
         return lc;
     }
 
     @Override
-    public Expression visit(RecordConstructor rc, ILangExpression arg) throws AsterixException {
+    public Expression visit(RecordConstructor rc, ILangExpression arg) throws CompilationException {
         for (FieldBinding binding : rc.getFbList()) {
             binding.setLeftExpr(visit(binding.getLeftExpr(), rc));
             binding.setRightExpr(visit(binding.getRightExpr(), rc));
@@ -279,13 +279,13 @@
     }
 
     @Override
-    public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws CompilationException {
         operatorExpr.setExprList(visit(operatorExpr.getExprList(), arg));
         return operatorExpr;
     }
 
     @Override
-    public Expression visit(IfExpr ifExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(IfExpr ifExpr, ILangExpression arg) throws CompilationException {
         ifExpr.setCondExpr(visit(ifExpr.getCondExpr(), ifExpr));
         ifExpr.setThenExpr(visit(ifExpr.getThenExpr(), ifExpr));
         ifExpr.setElseExpr(visit(ifExpr.getElseExpr(), ifExpr));
@@ -293,7 +293,7 @@
     }
 
     @Override
-    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws AsterixException {
+    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws CompilationException {
         for (QuantifiedPair pair : qe.getQuantifiedList()) {
             pair.setExpr(visit(pair.getExpr(), qe));
         }
@@ -302,30 +302,30 @@
     }
 
     @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
         callExpr.setExprList(visit(callExpr.getExprList(), arg));
         return callExpr;
     }
 
     @Override
-    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws CompilationException {
         return varExpr;
     }
 
     @Override
-    public Expression visit(UnaryExpr u, ILangExpression arg) throws AsterixException {
+    public Expression visit(UnaryExpr u, ILangExpression arg) throws CompilationException {
         u.setExpr(visit(u.getExpr(), u));
         return u;
     }
 
     @Override
-    public Expression visit(FieldAccessor fa, ILangExpression arg) throws AsterixException {
+    public Expression visit(FieldAccessor fa, ILangExpression arg) throws CompilationException {
         fa.setExpr(visit(fa.getExpr(), fa));
         return fa;
     }
 
     @Override
-    public Expression visit(IndexAccessor ia, ILangExpression arg) throws AsterixException {
+    public Expression visit(IndexAccessor ia, ILangExpression arg) throws CompilationException {
         ia.setExpr(visit(ia.getExpr(), ia));
         if (ia.getIndexExpr() != null) {
             ia.setIndexExpr(visit(ia.getIndexExpr(), arg));
@@ -334,13 +334,13 @@
     }
 
     @Override
-    public Expression visit(IndependentSubquery independentSubquery, ILangExpression arg) throws AsterixException {
+    public Expression visit(IndependentSubquery independentSubquery, ILangExpression arg) throws CompilationException {
         independentSubquery.setExpr(visit(independentSubquery.getExpr(), arg));
         return independentSubquery;
     }
 
     @Override
-    public Expression visit(CaseExpression caseExpr, ILangExpression arg) throws AsterixException {
+    public Expression visit(CaseExpression caseExpr, ILangExpression arg) throws CompilationException {
         caseExpr.setConditionExpr(visit(caseExpr.getConditionExpr(), arg));
         caseExpr.setWhenExprs(visit(caseExpr.getWhenExprs(), arg));
         caseExpr.setThenExprs(visit(caseExpr.getThenExprs(), arg));
@@ -349,7 +349,7 @@
     }
 
     @Override
-    public Expression visit(InsertStatement insertStatement, ILangExpression arg) throws AsterixException {
+    public Expression visit(InsertStatement insertStatement, ILangExpression arg) throws CompilationException {
         Expression returnExpr = insertStatement.getReturnExpression();
         if (returnExpr != null) {
             insertStatement.setReturnExpression(visit(returnExpr, arg));
@@ -359,19 +359,19 @@
         return null;
     }
 
-    protected Expression visit(Expression expr, ILangExpression arg) throws AsterixException{
+    protected Expression visit(Expression expr, ILangExpression arg) throws CompilationException {
         return postVisit(preVisit(expr).accept(this, arg));
     }
 
-    protected Expression preVisit(Expression expr) throws AsterixException{
+    protected Expression preVisit(Expression expr) throws CompilationException {
         return expr;
     }
 
-    protected Expression postVisit(Expression expr) throws AsterixException {
+    protected Expression postVisit(Expression expr) throws CompilationException {
         return expr;
     }
 
-    private List<Expression> visit(List<Expression> exprs, ILangExpression arg) throws AsterixException {
+    private List<Expression> visit(List<Expression> exprs, ILangExpression arg) throws CompilationException {
         List<Expression> newExprList = new ArrayList<>();
         for (Expression expr : exprs) {
             newExprList.add(visit(expr, arg));
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java
index 2827e37..639f3b5 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/base/ISqlppVisitor.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.sqlpp.visitor.base;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 import org.apache.asterix.lang.sqlpp.clause.FromClause;
 import org.apache.asterix.lang.sqlpp.clause.FromTerm;
@@ -38,33 +38,33 @@
 
 public interface ISqlppVisitor<R, T> extends ILangVisitor<R, T> {
 
-    R visit(FromClause fromClause, T arg) throws AsterixException;
+    R visit(FromClause fromClause, T arg) throws CompilationException;
 
-    R visit(FromTerm fromTerm, T arg) throws AsterixException;
+    R visit(FromTerm fromTerm, T arg) throws CompilationException;
 
-    R visit(JoinClause joinClause, T arg) throws AsterixException;
+    R visit(JoinClause joinClause, T arg) throws CompilationException;
 
-    R visit(NestClause nestClause, T arg) throws AsterixException;
+    R visit(NestClause nestClause, T arg) throws CompilationException;
 
-    R visit(Projection projection, T arg) throws AsterixException;
+    R visit(Projection projection, T arg) throws CompilationException;
 
-    R visit(SelectBlock selectBlock, T arg) throws AsterixException;
+    R visit(SelectBlock selectBlock, T arg) throws CompilationException;
 
-    R visit(SelectClause selectClause, T arg) throws AsterixException;
+    R visit(SelectClause selectClause, T arg) throws CompilationException;
 
-    R visit(SelectElement selectElement, T arg) throws AsterixException;
+    R visit(SelectElement selectElement, T arg) throws CompilationException;
 
-    R visit(SelectRegular selectRegular, T arg) throws AsterixException;
+    R visit(SelectRegular selectRegular, T arg) throws CompilationException;
 
-    R visit(SelectSetOperation selectSetOperation, T arg) throws AsterixException;
+    R visit(SelectSetOperation selectSetOperation, T arg) throws CompilationException;
 
-    R visit(SelectExpression selectStatement, T arg) throws AsterixException;
+    R visit(SelectExpression selectStatement, T arg) throws CompilationException;
 
-    R visit(UnnestClause unnestClause, T arg) throws AsterixException;
+    R visit(UnnestClause unnestClause, T arg) throws CompilationException;
 
-    R visit(HavingClause havingClause, T arg) throws AsterixException;
+    R visit(HavingClause havingClause, T arg) throws CompilationException;
 
-    R visit(IndependentSubquery independentSubquery, T arg) throws AsterixException;
+    R visit(IndependentSubquery independentSubquery, T arg) throws CompilationException;
 
-    R visit(CaseExpression caseExpression, T arg) throws AsterixException;
+    R visit(CaseExpression caseExpression, T arg) throws CompilationException;
 }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index e08f758..047fcc4 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -45,7 +45,7 @@
 import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
 import org.apache.asterix.common.config.DatasetConfig.IndexType;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Literal;
@@ -258,7 +258,7 @@
         super.setInput(s);
     }
 
-    public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
+    public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, CompilationException {
         File file = new File(args[0]);
         Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
         SQLPPParser parser = new SQLPPParser(fis);
@@ -266,15 +266,15 @@
         //st.accept(new SQLPPPrintVisitor(), 0);
     }
 
-    public List<Statement> parse() throws AsterixException {
+    public List<Statement> parse() throws CompilationException {
         try {
             return Statement();
         } catch (Error e) {
             // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
             // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
-            throw new AsterixException(new ParseException(e.getMessage()));
+            throw new CompilationException(new ParseException(e.getMessage()));
         } catch (ParseException e) {
-            throw new AsterixException("Syntax error: " + getMessage(e));
+            throw new CompilationException("Syntax error: " + getMessage(e));
         }
     }
 
@@ -1782,7 +1782,7 @@
         }
         try{
            op.addOperator(token.image.toLowerCase());
-        } catch (AsterixException e){
+        } catch (CompilationException e){
            throw new ParseException(e.getMessage());
         }
     }
@@ -1855,7 +1855,7 @@
           }
           try{
             op.addOperator(operator);
-          } catch (AsterixException e){
+          } catch (CompilationException e){
             throw new ParseException(e.getMessage());
           }
         }
@@ -1906,7 +1906,7 @@
           }
           try{
             op.addOperator(operator);
-          } catch (AsterixException e){
+          } catch (CompilationException e){
             throw new ParseException(e.getMessage());
           }
         }
@@ -2100,7 +2100,7 @@
         uexpr = new UnaryExpr();
         try{
             uexpr.setExprType(exprType);
-        } catch (AsterixException e){
+        } catch (CompilationException e){
             throw new ParseException(e.getMessage());
         }
     }
diff --git a/asterixdb/asterix-lang-sqlpp/src/test/java/org/apache/asterix/lang/sqlpp/parser/ParserTest.java b/asterixdb/asterix-lang-sqlpp/src/test/java/org/apache/asterix/lang/sqlpp/parser/ParserTest.java
index 27679a9..dbb72c7 100644
--- a/asterixdb/asterix-lang-sqlpp/src/test/java/org/apache/asterix/lang/sqlpp/parser/ParserTest.java
+++ b/asterixdb/asterix-lang-sqlpp/src/test/java/org/apache/asterix/lang/sqlpp/parser/ParserTest.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.sqlpp.parser;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.IParserFactory;
 import org.junit.Test;
@@ -30,7 +30,7 @@
         IParser parser = factory.createParser(query);
         try {
             parser.parse();
-        } catch (AsterixException e) {
+        } catch (CompilationException e) {
             if (!e.getMessage().contains("Syntax error: In line 3")) {
                 throw new Exception("Unexpected error", e);
             }
diff --git a/asterixdb/asterix-maven-plugins/asterix-grammar-extension-maven-plugin/src/test/java/org/apache/asterix/lang/extension/EchoStatement.java b/asterixdb/asterix-maven-plugins/asterix-grammar-extension-maven-plugin/src/test/java/org/apache/asterix/lang/extension/EchoStatement.java
index 3d98299..1121287 100644
--- a/asterixdb/asterix-maven-plugins/asterix-grammar-extension-maven-plugin/src/test/java/org/apache/asterix/lang/extension/EchoStatement.java
+++ b/asterixdb/asterix-maven-plugins/asterix-grammar-extension-maven-plugin/src/test/java/org/apache/asterix/lang/extension/EchoStatement.java
@@ -18,7 +18,7 @@
  */
 package org.apache.asterix.lang.extension;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 
@@ -31,7 +31,7 @@
     }
 
     @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws AsterixException {
+    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
         return null;
     }
 
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java
index 84c908f..0501d48 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataException.java
@@ -19,9 +19,9 @@
 
 package org.apache.asterix.metadata;
 
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 
-public class MetadataException extends AsterixException {
+public class MetadataException extends CompilationException {
     private static final long serialVersionUID = 1L;
 
     public MetadataException(String message) {
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
index 61c1aff..26706c6 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
@@ -25,19 +25,20 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.asterix.common.config.StorageProperties;
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
 import org.apache.asterix.common.config.DatasetConfig.ExternalFilePendingOp;
 import org.apache.asterix.common.config.DatasetConfig.IndexType;
 import org.apache.asterix.common.config.GlobalConfig;
+import org.apache.asterix.common.config.StorageProperties;
 import org.apache.asterix.common.context.AsterixVirtualBufferCacheProvider;
 import org.apache.asterix.common.context.ITransactionSubsystemProvider;
 import org.apache.asterix.common.context.TransactionSubsystemProvider;
+import org.apache.asterix.common.dataflow.IApplicationContextInfo;
 import org.apache.asterix.common.dataflow.LSMIndexUtil;
 import org.apache.asterix.common.dataflow.LSMInvertedIndexInsertDeleteOperatorDescriptor;
 import org.apache.asterix.common.dataflow.LSMTreeInsertDeleteOperatorDescriptor;
-import org.apache.asterix.common.dataflow.IApplicationContextInfo;
 import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.ioopcallbacks.LSMBTreeIOOperationCallbackFactory;
 import org.apache.asterix.common.ioopcallbacks.LSMBTreeWithBuddyIOOperationCallbackFactory;
 import org.apache.asterix.common.ioopcallbacks.LSMInvertedIndexIOOperationCallbackFactory;
@@ -93,8 +94,8 @@
 import org.apache.asterix.runtime.operators.LSMInvertedIndexUpsertOperatorDescriptor;
 import org.apache.asterix.runtime.operators.LSMTreeUpsertOperatorDescriptor;
 import org.apache.asterix.runtime.util.AppContextInfo;
-import org.apache.asterix.runtime.util.RuntimeComponentsProvider;
 import org.apache.asterix.runtime.util.ClusterStateManager;
+import org.apache.asterix.runtime.util.RuntimeComponentsProvider;
 import org.apache.asterix.transaction.management.opcallbacks.LockThenSearchOperationCallbackFactory;
 import org.apache.asterix.transaction.management.opcallbacks.PrimaryIndexInstantSearchOperationCallbackFactory;
 import org.apache.asterix.transaction.management.opcallbacks.PrimaryIndexModificationOperationCallbackFactory;
@@ -409,18 +410,18 @@
         return new Pair<>(dataScanner, constraint);
     }
 
-    public IDataFormat getDataFormat(String dataverseName) throws AsterixException {
+    public IDataFormat getDataFormat(String dataverseName) throws CompilationException {
         Dataverse dataverse = MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dataverseName);
         IDataFormat format;
         try {
             format = (IDataFormat) Class.forName(dataverse.getDataFormat()).newInstance();
         } catch (Exception e) {
-            throw new AsterixException(e);
+            throw new CompilationException(e);
         }
         return format;
     }
 
-    public Dataverse findDataverse(String dataverseName) throws AsterixException {
+    public Dataverse findDataverse(String dataverseName) throws CompilationException {
         return MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dataverseName);
     }
 
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/feeds/FeedMetadataUtil.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/feeds/FeedMetadataUtil.java
index 12e854d..21db749 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/feeds/FeedMetadataUtil.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/feeds/FeedMetadataUtil.java
@@ -32,6 +32,7 @@
 import org.apache.asterix.common.dataflow.LSMTreeInsertDeleteOperatorDescriptor;
 import org.apache.asterix.common.exceptions.ACIDException;
 import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.common.library.ILibraryManager;
 import org.apache.asterix.external.api.IAdapterFactory;
@@ -93,36 +94,37 @@
     private static final Logger LOGGER = Logger.getLogger(FeedMetadataUtil.class.getName());
 
     public static Dataset validateIfDatasetExists(String dataverse, String datasetName, MetadataTransactionContext ctx)
-            throws AsterixException {
+            throws CompilationException {
         Dataset dataset = MetadataManager.INSTANCE.getDataset(ctx, dataverse, datasetName);
         if (dataset == null) {
-            throw new AsterixException("Unknown target dataset :" + datasetName);
+            throw new CompilationException("Unknown target dataset :" + datasetName);
         }
 
         if (!dataset.getDatasetType().equals(DatasetType.INTERNAL)) {
-            throw new AsterixException("Statement not applicable. Dataset " + datasetName + " is not of required type "
+            throw new CompilationException("Statement not applicable. Dataset " + datasetName
+                    + " is not of required type "
                     + DatasetType.INTERNAL);
         }
         return dataset;
     }
 
     public static Feed validateIfFeedExists(String dataverse, String feedName, MetadataTransactionContext ctx)
-            throws AsterixException {
+            throws CompilationException {
         Feed feed = MetadataManager.INSTANCE.getFeed(ctx, dataverse, feedName);
         if (feed == null) {
-            throw new AsterixException("Unknown source feed: " + feedName);
+            throw new CompilationException("Unknown source feed: " + feedName);
         }
         return feed;
     }
 
     public static FeedPolicyEntity validateIfPolicyExists(String dataverse, String policyName,
-            MetadataTransactionContext ctx) throws AsterixException {
+            MetadataTransactionContext ctx) throws CompilationException {
         FeedPolicyEntity feedPolicy = MetadataManager.INSTANCE.getFeedPolicy(ctx, dataverse, policyName);
         if (feedPolicy == null) {
             feedPolicy = MetadataManager.INSTANCE.getFeedPolicy(ctx, MetadataConstants.METADATA_DATAVERSE_NAME,
                     policyName);
             if (feedPolicy == null) {
-                throw new AsterixException("Unknown feed policy" + policyName);
+                throw new CompilationException("Unknown feed policy" + policyName);
             }
         }
         return feedPolicy;