[ASTERIXDB-2785][AQL] Remove AQL Support

- user model changes: Yes, AQL is no longer supported.
- storage format changes: no
- interface changes: no

Details:

- Remove AQL Support.
- Remove AQL based AdmGenTests.
- Convert feed-stats API to SQL++.

Change-Id: Ia73de4b6552a7da10427506ac9605a000aab21d8
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/8285
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/base/ILangExtension.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/base/ILangExtension.java
index fb74475..bf812b3 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/base/ILangExtension.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/base/ILangExtension.java
@@ -29,7 +29,6 @@
 public interface ILangExtension extends IExtension {
 
     public enum Language {
-        AQL,
         SQLPP
     }
 
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/AqlCompilationProvider.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/AqlCompilationProvider.java
deleted file mode 100644
index 4a6735a..0000000
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/AqlCompilationProvider.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.compiler.provider;
-
-import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory;
-import org.apache.asterix.algebra.base.ILangExtension;
-import org.apache.asterix.lang.aql.parser.AQLParserFactory;
-import org.apache.asterix.lang.aql.rewrites.AqlRewriterFactory;
-import org.apache.asterix.lang.aql.visitor.AQLAstPrintVisitorFactory;
-import org.apache.asterix.lang.common.base.IAstPrintVisitorFactory;
-import org.apache.asterix.lang.common.base.IParserFactory;
-import org.apache.asterix.lang.common.base.IRewriterFactory;
-import org.apache.asterix.translator.AqlExpressionToPlanTranslatorFactory;
-
-public class AqlCompilationProvider implements ILangCompilationProvider {
-
-    @Override
-    public ILangExtension.Language getLanguage() {
-        return ILangExtension.Language.AQL;
-    }
-
-    @Override
-    public IParserFactory getParserFactory() {
-        return new AQLParserFactory();
-    }
-
-    @Override
-    public IRewriterFactory getRewriterFactory() {
-        return new AqlRewriterFactory(getParserFactory());
-    }
-
-    @Override
-    public IAstPrintVisitorFactory getAstPrintVisitorFactory() {
-        return new AQLAstPrintVisitorFactory();
-    }
-
-    @Override
-    public ILangExpressionToPlanTranslatorFactory getExpressionToPlanTranslatorFactory() {
-        return new AqlExpressionToPlanTranslatorFactory();
-    }
-
-    @Override
-    public IRuleSetFactory getRuleSetFactory() {
-        return new DefaultRuleSetFactory();
-    }
-}
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
deleted file mode 100644
index c82029b..0000000
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlExpressionToPlanTranslator.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.translator;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
-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;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-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.Expression.Kind;
-import org.apache.asterix.lang.common.base.ILangExpression;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.statement.Query;
-import org.apache.asterix.metadata.declared.MetadataProvider;
-import org.apache.asterix.om.types.BuiltinType;
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.common.utils.Pair;
-import org.apache.hyracks.algebricks.core.algebra.base.Counter;
-import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
-import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
-import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
-import org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable;
-import org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
-import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
-import org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator;
-import org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
-import org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator;
-import org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator;
-import org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
-
-/**
- * Each visit returns a pair of an operator and a variable. The variable
- * corresponds to the new column, if any, added to the tuple flow. E.g., for
- * Unnest, the column is the variable bound to the elements in the list, for
- * Subplan it is null. The first argument of a visit method is the expression
- * which is translated. The second argument of a visit method is the tuple
- * source for the current subtree.
- */
-
-class AqlExpressionToPlanTranslator extends LangExpressionToPlanTranslator implements ILangExpressionToPlanTranslator,
-        IAQLVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
-
-    public AqlExpressionToPlanTranslator(MetadataProvider metadataProvider, int currentVarCounterValue)
-            throws AlgebricksException {
-        super(metadataProvider, currentVarCounterValue);
-    }
-
-    // Keeps the given Counter if one is provided instead of a value.
-    public AqlExpressionToPlanTranslator(MetadataProvider metadataProvider, Counter currentVarCounter)
-            throws AlgebricksException {
-        super(metadataProvider, currentVarCounter);
-    }
-
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visit(ForClause fc, Mutable<ILogicalOperator> tupSource)
-            throws CompilationException {
-        LogicalVariable v = context.newVarFromExpression(fc.getVarExpr());
-        Expression inExpr = fc.getInExpr();
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(inExpr, tupSource);
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> pUnnestExpr = makeUnnestExpression(eo.first, eo.second);
-        ILogicalOperator returnedOp;
-        if (fc.getPosVarExpr() == null) {
-            returnedOp = new UnnestOperator(v, new MutableObject<>(pUnnestExpr.first));
-        } else {
-            LogicalVariable pVar = context.newVarFromExpression(fc.getPosVarExpr());
-            // We set the positional variable type as INT64 type.
-            returnedOp = new UnnestOperator(v, new MutableObject<>(pUnnestExpr.first), pVar, BuiltinType.AINT64);
-        }
-        returnedOp.getInputs().add(pUnnestExpr.second);
-        return new Pair<>(returnedOp, v);
-    }
-
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visit(FLWOGRExpression flwor, Mutable<ILogicalOperator> tupSource)
-            throws CompilationException {
-        Mutable<ILogicalOperator> flworPlan = tupSource;
-        boolean isTop = context.isTopFlwor();
-        if (!isTop) {
-            context.enterSubplan();
-        }
-        if (isTop) {
-            context.setTopFlwor(false);
-        }
-        for (Clause c : flwor.getClauseList()) {
-            Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this, flworPlan);
-            flworPlan = new MutableObject<>(pC.first);
-        }
-
-        Expression r = flwor.getReturnExpr();
-        boolean noForClause = flwor.noForClause();
-
-        Pair<ILogicalOperator, LogicalVariable> result;
-        if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
-            VariableExpr v = (VariableExpr) r;
-            LogicalVariable var = context.getVar(v.getVar().getId());
-            result = produceFlworPlan(noForClause, isTop, flworPlan, var);
-        } else {
-            Mutable<ILogicalOperator> baseOp = new MutableObject<>(flworPlan.getValue());
-            Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this, baseOp);
-            ILogicalOperator rOp = rRes.first;
-            ILogicalOperator resOp;
-            if (expressionNeedsNoNesting(r)) {
-                baseOp.setValue(flworPlan.getValue());
-                resOp = rOp;
-            } else {
-                SubplanOperator s = new SubplanOperator(rOp);
-                s.getInputs().add(flworPlan);
-                resOp = s;
-                baseOp.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
-            }
-            Mutable<ILogicalOperator> resOpRef = new MutableObject<>(resOp);
-            result = produceFlworPlan(noForClause, isTop, resOpRef, rRes.second);
-        }
-        if (!isTop) {
-            context.exitSubplan();
-        }
-
-        return result;
-    }
-
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visit(Query q, Mutable<ILogicalOperator> tupSource)
-            throws CompilationException {
-        return q.getBody().accept(this, tupSource);
-    }
-
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visit(DistinctClause dc, Mutable<ILogicalOperator> tupSource)
-            throws CompilationException {
-        List<Mutable<ILogicalExpression>> exprList = new ArrayList<>();
-        Mutable<ILogicalOperator> input = null;
-        for (Expression expr : dc.getDistinctByExpr()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(expr, tupSource);
-            exprList.add(new MutableObject<ILogicalExpression>(p.first));
-            input = p.second;
-        }
-        DistinctOperator opDistinct = new DistinctOperator(exprList);
-        opDistinct.getInputs().add(input);
-        return new Pair<>(opDistinct, null);
-    }
-
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visit(UnionExpr unionExpr, Mutable<ILogicalOperator> tupSource)
-            throws CompilationException {
-        List<ILangExpression> inputExprs = new ArrayList<>();
-        inputExprs.addAll(unionExpr.getExprs());
-        Pair<ILogicalOperator, LogicalVariable> result = translateUnionAllFromInputExprs(inputExprs, tupSource, null);
-        return aggListifyForSubquery(result.second, new MutableObject<>(result.first), false);
-    }
-
-    @Override
-    protected boolean expressionNeedsNoNesting(Expression expr) throws CompilationException {
-        boolean isFLWOGR = expr.getKind() == Kind.FLWOGR_EXPRESSION;
-        boolean letOnly = true;
-        // No nesting is needed for a FLWOR expression that only has LETs and RETURN.
-        if (isFLWOGR) {
-            FLWOGRExpression flwor = (FLWOGRExpression) expr;
-            for (Clause clause : flwor.getClauseList()) {
-                letOnly &= clause.getClauseType() == Clause.ClauseType.LET_CLAUSE;
-            }
-        }
-        return (isFLWOGR && letOnly) || super.expressionNeedsNoNesting(expr);
-    }
-
-    private Pair<ILogicalOperator, LogicalVariable> produceFlworPlan(boolean noForClause, boolean isTop,
-            Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
-        if (isTop) {
-            ProjectOperator pr = new ProjectOperator(resVar);
-            pr.getInputs().add(resOpRef);
-            return new Pair<>(pr, resVar);
-        } else if (noForClause) {
-            ILogicalOperator resOp = resOpRef.getValue();
-            if (resOp.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
-                return new Pair<>(resOp, resVar);
-            }
-            LogicalVariable newResVar = context.newVar();
-            ILogicalOperator assign =
-                    new AssignOperator(newResVar, new MutableObject<>(new VariableReferenceExpression(resVar)));
-            assign.getInputs().add(resOpRef);
-            return new Pair<>(assign, newResVar);
-        } else {
-            return aggListifyForSubquery(resVar, resOpRef, false);
-        }
-    }
-
-}
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlExpressionToPlanTranslatorFactory.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlExpressionToPlanTranslatorFactory.java
deleted file mode 100644
index 911c443..0000000
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AqlExpressionToPlanTranslatorFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.translator;
-
-import java.util.Map;
-
-import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
-import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory;
-import org.apache.asterix.lang.common.struct.VarIdentifier;
-import org.apache.asterix.metadata.declared.MetadataProvider;
-import org.apache.asterix.om.base.IAObject;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-
-public class AqlExpressionToPlanTranslatorFactory implements ILangExpressionToPlanTranslatorFactory {
-
-    @Override
-    public ILangExpressionToPlanTranslator createExpressionToPlanTranslator(MetadataProvider metadataProvider,
-            int currentVarCounter, Map<VarIdentifier, IAObject> externalVars) throws AlgebricksException {
-        return new AqlExpressionToPlanTranslator(metadataProvider, currentVarCounter);
-    }
-
-}
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
index cbae6e8..c5eb69d 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
@@ -41,7 +41,6 @@
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
-import org.apache.asterix.lang.aql.parser.TokenMgrError;
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.IParserFactory;
 import org.apache.asterix.lang.common.base.Statement;
@@ -73,17 +72,15 @@
     public static final String HTML_STATEMENT_SEPARATOR = "<!-- BEGIN -->";
 
     private final ICcApplicationContext appCtx;
-    private final ILangCompilationProvider aqlCompilationProvider;
     private final ILangCompilationProvider sqlppCompilationProvider;
     private final IStatementExecutorFactory statementExectorFactory;
     private final IStorageComponentProvider componentProvider;
 
     public ApiServlet(ConcurrentMap<String, Object> ctx, String[] paths, ICcApplicationContext appCtx,
-            ILangCompilationProvider aqlCompilationProvider, ILangCompilationProvider sqlppCompilationProvider,
-            IStatementExecutorFactory statementExecutorFactory, IStorageComponentProvider componentProvider) {
+            ILangCompilationProvider sqlppCompilationProvider, IStatementExecutorFactory statementExecutorFactory,
+            IStorageComponentProvider componentProvider) {
         super(ctx, paths);
         this.appCtx = appCtx;
-        this.aqlCompilationProvider = aqlCompilationProvider;
         this.sqlppCompilationProvider = sqlppCompilationProvider;
         this.statementExectorFactory = statementExecutorFactory;
         this.componentProvider = componentProvider;
@@ -93,8 +90,7 @@
     protected void post(IServletRequest request, IServletResponse response) {
         final IRequestReference requestReference = appCtx.getReceptionist().welcome(request);
         // Query language
-        ILangCompilationProvider compilationProvider = "AQL".equals(request.getParameter("query-language"))
-                ? aqlCompilationProvider : sqlppCompilationProvider;
+        ILangCompilationProvider compilationProvider = sqlppCompilationProvider;
         IParserFactory parserFactory = compilationProvider.getParserFactory();
 
         try {
@@ -161,7 +157,7 @@
             duration = (endTime - startTime) / 1000.00;
             out.println(HTML_STATEMENT_SEPARATOR);
             out.println("<PRE>Duration of all jobs: " + duration + " sec</PRE>");
-        } catch (AsterixException | TokenMgrError | org.apache.asterix.lang.sqlpp.parser.TokenMgrError pe) {
+        } catch (AsterixException | org.apache.asterix.lang.sqlpp.parser.TokenMgrError pe) {
             GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, pe.toString(), pe);
             ResultUtil.webUIParseExceptionHandler(out, pe, query);
         } catch (Exception e) {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index c8062ac..d43e611 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -69,7 +69,6 @@
 import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
-import org.apache.asterix.lang.aql.parser.TokenMgrError;
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.IParserFactory;
 import org.apache.asterix.lang.common.base.Statement;
@@ -307,7 +306,7 @@
                 executionState.setStatus(ResultStatus.SUCCESS, HttpResponseStatus.OK);
             }
             errorCount = 0;
-        } catch (Exception | TokenMgrError | org.apache.asterix.lang.sqlpp.parser.TokenMgrError e) {
+        } catch (Exception | org.apache.asterix.lang.sqlpp.parser.TokenMgrError e) {
             handleExecuteStatementException(e, executionState, param);
             response.setStatus(executionState.getHttpStatus());
             requestFailed(e, responsePrinter);
@@ -424,8 +423,7 @@
 
     protected void handleExecuteStatementException(Throwable t, RequestExecutionState executionState,
             QueryServiceRequestParameters param) {
-        if (t instanceof org.apache.asterix.lang.sqlpp.parser.TokenMgrError || t instanceof TokenMgrError
-                || t instanceof AlgebricksException) {
+        if (t instanceof org.apache.asterix.lang.sqlpp.parser.TokenMgrError || t instanceof AlgebricksException) {
             if (LOGGER.isDebugEnabled()) {
                 LOGGER.debug("handleException: {}: {}", t.getMessage(), LogRedactionUtil.statement(param.toString()),
                         t);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/FeedEventsListener.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/FeedEventsListener.java
index c4db4eb..fe4cdc5 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/FeedEventsListener.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/active/FeedEventsListener.java
@@ -98,8 +98,8 @@
     @Override
     protected JobId compileAndStartJob(MetadataProvider mdProvider) throws HyracksDataException {
         try {
-            Pair<JobSpecification, AlgebricksAbsolutePartitionConstraint> jobInfo = FeedOperations
-                    .buildStartFeedJob(mdProvider, feed, feedConnections, statementExecutor, hcc, translatorLang);
+            Pair<JobSpecification, AlgebricksAbsolutePartitionConstraint> jobInfo =
+                    FeedOperations.buildStartFeedJob(mdProvider, feed, feedConnections, statementExecutor, hcc);
             JobSpecification feedJob = jobInfo.getLeft();
             feedJob.setProperty(ActiveNotificationHandler.ACTIVE_ENTITY_PROPERTY_NAME, entityId);
             // TODO(Yingyi): currently we do not check IFrameWriter protocol violations for Feed jobs.
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
index e3c177e..f208c0f 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
@@ -35,7 +35,6 @@
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.common.exceptions.RuntimeDataException;
-import org.apache.asterix.compiler.provider.AqlCompilationProvider;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.compiler.provider.SqlppCompilationProvider;
 import org.apache.asterix.hyracks.bootstrap.GlobalRecoveryManager;
@@ -59,7 +58,6 @@
 public class CCExtensionManager implements ICCExtensionManager {
 
     private final IStatementExecutorExtension statementExecutorExtension;
-    private final ILangCompilationProvider aqlCompilationProvider;
     private final ILangCompilationProvider sqlppCompilationProvider;
     private final IFunctionManager functionManager;
     private final IGlobalRecoveryExtension globalRecoveryExtension;
@@ -78,7 +76,6 @@
      */
     public CCExtensionManager(List<AsterixExtension> list)
             throws InstantiationException, IllegalAccessException, ClassNotFoundException, HyracksDataException {
-        Pair<ExtensionId, ILangCompilationProvider> aqlcp = null;
         Pair<ExtensionId, ILangCompilationProvider> sqlppcp = null;
         Pair<ExtensionId, IFunctionManager> fm = null;
         IStatementExecutorExtension see = null;
@@ -98,7 +95,6 @@
                         break;
                     case LANG:
                         ILangExtension le = (ILangExtension) extension;
-                        aqlcp = ExtensionUtil.extendLangCompilationProvider(Language.AQL, aqlcp, le);
                         sqlppcp = ExtensionUtil.extendLangCompilationProvider(Language.SQLPP, sqlppcp, le);
                         fm = ExtensionUtil.extendFunctionManager(fm, le);
                         break;
@@ -113,7 +109,6 @@
             }
         }
         this.statementExecutorExtension = see;
-        this.aqlCompilationProvider = aqlcp == null ? new AqlCompilationProvider() : aqlcp.second;
         this.sqlppCompilationProvider = sqlppcp == null ? new SqlppCompilationProvider() : sqlppcp.second;
         this.functionManager =
                 fm == null ? new FunctionManager(FunctionCollection.createDefaultFunctionCollection()) : fm.second;
@@ -138,8 +133,6 @@
 
     public ILangCompilationProvider getCompilationProvider(Language lang) {
         switch (lang) {
-            case AQL:
-                return aqlCompilationProvider;
             case SQLPP:
                 return sqlppCompilationProvider;
             default:
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
index 80200ca..a6ecc33 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
@@ -42,7 +42,6 @@
 import org.apache.asterix.common.messaging.api.ICcAddressedMessage;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.hyracks.bootstrap.CCApplication;
-import org.apache.asterix.lang.aql.parser.TokenMgrError;
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.messaging.CCMessageBroker;
@@ -162,8 +161,7 @@
             responseMsg.setStatementProperties(statementProperties);
             responseMsg.setExecutionPlans(translator.getExecutionPlans());
             responseMsg.setWarnings(warnings);
-        } catch (AlgebricksException | HyracksException | TokenMgrError
-                | org.apache.asterix.lang.sqlpp.parser.TokenMgrError pe) {
+        } catch (AlgebricksException | HyracksException | org.apache.asterix.lang.sqlpp.parser.TokenMgrError pe) {
             // we trust that "our" exceptions are serializable and have a comprehensible error message
             GlobalConfig.ASTERIX_LOGGER.log(Level.WARN, pe.getMessage(), pe);
             responseMsg.setError(pe);
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCExtensionManager.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCExtensionManager.java
index a1405a6..5c8e3b1 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCExtensionManager.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCExtensionManager.java
@@ -27,7 +27,6 @@
 import org.apache.asterix.common.api.IExtension;
 import org.apache.asterix.common.config.AsterixExtension;
 import org.apache.asterix.common.exceptions.ACIDException;
-import org.apache.asterix.compiler.provider.AqlCompilationProvider;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.compiler.provider.SqlppCompilationProvider;
 import org.apache.asterix.metadata.api.IMetadataExtension;
@@ -44,7 +43,6 @@
  */
 public class NCExtensionManager implements INCExtensionManager {
 
-    private final ILangCompilationProvider aqlCompilationProvider;
     private final ILangCompilationProvider sqlppCompilationProvider;
     private final MetadataTupleTranslatorProvider tupleTranslatorProvider;
     private final List<IMetadataExtension> mdExtensions;
@@ -76,7 +74,6 @@
                 switch (extension.getExtensionKind()) {
                     case LANG:
                         ILangExtension le = (ILangExtension) extension;
-                        aqlcp = ExtensionUtil.extendLangCompilationProvider(ILangExtension.Language.AQL, aqlcp, le);
                         sqlppcp =
                                 ExtensionUtil.extendLangCompilationProvider(ILangExtension.Language.SQLPP, sqlppcp, le);
                         break;
@@ -91,7 +88,6 @@
                 }
             }
         }
-        this.aqlCompilationProvider = aqlcp == null ? new AqlCompilationProvider() : aqlcp.second;
         this.sqlppCompilationProvider = sqlppcp == null ? new SqlppCompilationProvider() : sqlppcp.second;
         this.tupleTranslatorProvider = tupleTranslatorProviderExtension == null ? new MetadataTupleTranslatorProvider()
                 : tupleTranslatorProviderExtension.getMetadataTupleTranslatorProvider();
@@ -99,8 +95,6 @@
 
     public ILangCompilationProvider getCompilationProvider(ILangExtension.Language lang) {
         switch (lang) {
-            case AQL:
-                return aqlCompilationProvider;
             case SQLPP:
                 return sqlppCompilationProvider;
             default:
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ExecutionError.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ExecutionError.java
index 357c0a2..6556b61 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ExecutionError.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/result/ExecutionError.java
@@ -20,7 +20,6 @@
 
 import org.apache.asterix.api.http.server.ResultUtil;
 import org.apache.asterix.common.api.ICodedMessage;
-import org.apache.asterix.lang.aql.parser.TokenMgrError;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.exceptions.HyracksException;
 
@@ -38,7 +37,6 @@
         Throwable rootCause = ResultUtil.getRootCause(t);
         String msg = rootCause.getMessage();
         if (!(rootCause instanceof AlgebricksException || rootCause instanceof HyracksException
-                || rootCause instanceof TokenMgrError
                 || rootCause instanceof org.apache.asterix.lang.sqlpp.parser.TokenMgrError)) {
             msg = rootCause.getClass().getSimpleName() + (msg == null ? "" : ": " + msg);
         }
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/drivers/AsterixClientDriver.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/drivers/AsterixClientDriver.java
index 558c25d..a5d99fb 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/drivers/AsterixClientDriver.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/drivers/AsterixClientDriver.java
@@ -23,8 +23,8 @@
 import org.apache.asterix.api.common.AsterixClientConfig;
 import org.apache.asterix.api.java.AsterixJavaClient;
 import org.apache.asterix.app.translator.DefaultStatementExecutorFactory;
-import org.apache.asterix.compiler.provider.AqlCompilationProvider;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
+import org.apache.asterix.compiler.provider.SqlppCompilationProvider;
 import org.apache.asterix.file.StorageComponentProvider;
 import org.apache.hyracks.api.client.IHyracksClientConnection;
 import org.apache.hyracks.ipc.impl.HyracksConnection;
@@ -62,7 +62,7 @@
 
     private static AsterixJavaClient compileQuery(IHyracksClientConnection hcc, String filename, boolean optimize,
             boolean onlyPhysical, boolean createBinaryRuntime) throws Exception {
-        ILangCompilationProvider compilationProvider = new AqlCompilationProvider();
+        ILangCompilationProvider compilationProvider = new SqlppCompilationProvider();
         FileReader reader = new FileReader(filename);
         AsterixJavaClient q = new AsterixJavaClient(null, hcc, reader, compilationProvider,
                 new DefaultStatementExecutorFactory(), new StorageComponentProvider());
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
index d06b8ab..3d5eb47 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
@@ -19,7 +19,6 @@
 
 package org.apache.asterix.hyracks.bootstrap;
 
-import static org.apache.asterix.algebra.base.ILangExtension.Language.AQL;
 import static org.apache.asterix.algebra.base.ILangExtension.Language.SQLPP;
 import static org.apache.asterix.api.http.server.ServletConstants.ASTERIX_APP_CONTEXT_INFO_ATTR;
 import static org.apache.asterix.api.http.server.ServletConstants.HYRACKS_CONNECTION_ATTR;
@@ -263,8 +262,7 @@
                 externalProperties.getWebInterfacePort(), config);
         webServer.setAttribute(HYRACKS_CONNECTION_ATTR, hcc);
         webServer.addServlet(new ApiServlet(webServer.ctx(), new String[] { "/*" }, appCtx,
-                ccExtensionManager.getCompilationProvider(AQL), ccExtensionManager.getCompilationProvider(SQLPP),
-                getStatementExecutorFactory(), componentProvider));
+                ccExtensionManager.getCompilationProvider(SQLPP), getStatementExecutorFactory(), componentProvider));
         return webServer;
     }
 
@@ -285,7 +283,6 @@
         addServlet(jsonAPIServer, Servlets.QUERY_STATUS);
         addServlet(jsonAPIServer, Servlets.QUERY_RESULT);
         addServlet(jsonAPIServer, Servlets.QUERY_SERVICE);
-        addServlet(jsonAPIServer, Servlets.QUERY_AQL);
         addServlet(jsonAPIServer, Servlets.RUNNING_REQUESTS);
         addServlet(jsonAPIServer, Servlets.CONNECTOR);
         addServlet(jsonAPIServer, Servlets.SHUTDOWN);
@@ -329,9 +326,6 @@
                 return new QueryServiceServlet(ctx, paths, appCtx, SQLPP,
                         ccExtensionManager.getCompilationProvider(SQLPP), getStatementExecutorFactory(),
                         componentProvider, null);
-            case Servlets.QUERY_AQL:
-                return new QueryServiceServlet(ctx, paths, appCtx, AQL, ccExtensionManager.getCompilationProvider(AQL),
-                        getStatementExecutorFactory(), componentProvider, null);
             case Servlets.CONNECTOR:
                 return new ConnectorApiServlet(ctx, paths, appCtx);
             case Servlets.REBALANCE:
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/utils/FeedOperations.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/utils/FeedOperations.java
index 68234b7..dcd52a0 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/utils/FeedOperations.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/utils/FeedOperations.java
@@ -29,10 +29,8 @@
 import java.util.Set;
 import java.util.TreeSet;
 
-import org.apache.asterix.algebra.base.ILangExtension;
 import org.apache.asterix.app.result.ResponsePrinter;
 import org.apache.asterix.app.translator.DefaultStatementExecutorFactory;
-import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.dataflow.LSMTreeInsertDeleteOperatorDescriptor;
@@ -451,8 +449,7 @@
 
     public static Pair<JobSpecification, AlgebricksAbsolutePartitionConstraint> buildStartFeedJob(
             MetadataProvider metadataProvider, Feed feed, List<FeedConnection> feedConnections,
-            IStatementExecutor statementExecutor, IHyracksClientConnection hcc, ILangExtension.Language translatorLang)
-            throws Exception {
+            IStatementExecutor statementExecutor, IHyracksClientConnection hcc) throws Exception {
         FeedPolicyAccessor fpa = new FeedPolicyAccessor(new HashMap<>());
         Pair<JobSpecification, ITypedAdapterFactory> intakeInfo = buildFeedIntakeJobSpec(feed, metadataProvider, fpa);
         List<JobSpecification> jobsList = new ArrayList<>();
@@ -466,14 +463,10 @@
         metadataProvider.getConfig().put(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS, Boolean.TRUE.toString());
         metadataProvider.getConfig().put(FeedActivityDetails.COLLECT_LOCATIONS,
                 StringUtils.join(ingestionLocations, ','));
-        // TODO: Once we deprecated AQL, this extra queryTranslator can be removed.
-        IStatementExecutor translator = translatorLang == ILangExtension.Language.AQL
-                ? getSQLPPTranslator(metadataProvider, ((QueryTranslator) statementExecutor).getSessionOutput())
-                : statementExecutor;
         // Add connection job
         for (FeedConnection feedConnection : feedConnections) {
             JobSpecification connectionJob =
-                    getConnectionJob(metadataProvider, feedConnection, translator, hcc, insertFeed);
+                    getConnectionJob(metadataProvider, feedConnection, statementExecutor, hcc, insertFeed);
             jobsList.add(connectionJob);
         }
         return Pair.of(combineIntakeCollectJobs(metadataProvider, feed, intakeJob, jobsList, feedConnections,
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
index cd0dee2..690eac0 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
@@ -1457,8 +1457,7 @@
     public ExtractedResult executeQuery(OutputFormat fmt, String statement, Map<String, Object> variableCtx,
             TestFileContext ctx, File expectedResultFile, File actualResultFile, MutableInt queryCount,
             int numResultFiles, List<Parameter> params, ComparisonEnum compare) throws Exception {
-        URI uri = getEndpoint(ctx.getFile().getName().endsWith("aql") ? Servlets.QUERY_AQL : Servlets.QUERY_SERVICE,
-                FilenameUtils.getExtension(ctx.getFile().getName()));
+        URI uri = getEndpoint(Servlets.QUERY_SERVICE, FilenameUtils.getExtension(ctx.getFile().getName()));
         return executeQuery(fmt, statement, variableCtx, ctx, expectedResultFile, actualResultFile, queryCount,
                 numResultFiles, params, compare, uri);
     }
@@ -2417,7 +2416,7 @@
     }
 
     private URI getQueryServiceUri(String extension) throws URISyntaxException {
-        return extension.endsWith(AQL) ? getEndpoint(Servlets.QUERY_AQL) : getEndpoint(Servlets.QUERY_SERVICE);
+        return getEndpoint(Servlets.QUERY_SERVICE);
     }
 
     protected void validateWarning(ExtractedResult result, TestCaseContext testCaseCtx, CompilationUnit cUnit,
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/dml/DmlTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/dml/DmlTest.java
index 3b636c6..e015ffc 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/dml/DmlTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/dml/DmlTest.java
@@ -30,7 +30,7 @@
 import org.apache.asterix.app.translator.DefaultStatementExecutorFactory;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.compiler.provider.AqlCompilationProvider;
+import org.apache.asterix.compiler.provider.SqlppCompilationProvider;
 import org.apache.asterix.file.StorageComponentProvider;
 import org.apache.asterix.test.base.AsterixTestHelper;
 import org.apache.asterix.test.common.TestExecutor;
@@ -64,7 +64,7 @@
                 new BufferedReader(new InputStreamReader(new FileInputStream(LOAD_FOR_ENLIST_FILE), "UTF-8"));
         AsterixJavaClient asterixLoad =
                 new AsterixJavaClient((ICcApplicationContext) integrationUtil.cc.getApplicationContext(),
-                        integrationUtil.getHyracksClientConnection(), loadReader, ERR, new AqlCompilationProvider(),
+                        integrationUtil.getHyracksClientConnection(), loadReader, ERR, new SqlppCompilationProvider(),
                         new DefaultStatementExecutorFactory(), new StorageComponentProvider());
         try {
             asterixLoad.compile(true, false, false, false, false, true, false);
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/jsonplan/JsonLogicalPlanTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/jsonplan/JsonLogicalPlanTest.java
index 8663918..6779df3 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/jsonplan/JsonLogicalPlanTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/jsonplan/JsonLogicalPlanTest.java
@@ -37,7 +37,6 @@
 import org.apache.asterix.common.context.IStorageComponentProvider;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.AsterixException;
-import org.apache.asterix.compiler.provider.AqlCompilationProvider;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.compiler.provider.SqlppCompilationProvider;
 import org.apache.asterix.external.util.ExternalDataConstants;
@@ -92,7 +91,6 @@
     private static final ArrayList<String> ignore = AsterixTestHelper.readTestListFile(FILENAME_IGNORE, PATH_BASE);
     private static final ArrayList<String> only = AsterixTestHelper.readTestListFile(FILENAME_ONLY, PATH_BASE);
     protected static final String TEST_CONFIG_FILE_NAME = "src/main/resources/cc.conf";
-    private static final ILangCompilationProvider aqlCompilationProvider = new AqlCompilationProvider();
     private static final ILangCompilationProvider sqlppCompilationProvider = new SqlppCompilationProvider();
     protected static ILangCompilationProvider extensionLangCompilationProvider = null;
     protected static IStatementExecutorFactory statementExecutorFactory = new DefaultStatementExecutorFactory();
@@ -190,8 +188,7 @@
             // Forces the creation of actualFile.
             actualFile.getParentFile().mkdirs();
 
-            ILangCompilationProvider provider =
-                    queryFile.getName().endsWith("aql") ? aqlCompilationProvider : sqlppCompilationProvider;
+            ILangCompilationProvider provider = sqlppCompilationProvider;
             if (extensionLangCompilationProvider != null) {
                 provider = extensionLangCompilationProvider;
             }
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java
index c3dc821..e8505be 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java
@@ -37,7 +37,6 @@
 import org.apache.asterix.app.translator.DefaultStatementExecutorFactory;
 import org.apache.asterix.common.context.IStorageComponentProvider;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
-import org.apache.asterix.compiler.provider.AqlCompilationProvider;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.compiler.provider.SqlppCompilationProvider;
 import org.apache.asterix.external.util.ExternalDataConstants;
@@ -87,7 +86,6 @@
     private static final ArrayList<String> ignore = AsterixTestHelper.readTestListFile(FILENAME_IGNORE, PATH_BASE);
     private static final ArrayList<String> only = AsterixTestHelper.readTestListFile(FILENAME_ONLY, PATH_BASE);
     protected static final String TEST_CONFIG_FILE_NAME = "src/main/resources/cc.conf";
-    private static final ILangCompilationProvider aqlCompilationProvider = new AqlCompilationProvider();
     private static final ILangCompilationProvider sqlppCompilationProvider = new SqlppCompilationProvider();
     protected static ILangCompilationProvider extensionLangCompilationProvider = null;
     protected static IStatementExecutorFactory statementExecutorFactory = new DefaultStatementExecutorFactory();
@@ -194,8 +192,7 @@
             // Forces the creation of actualFile.
             actualFile.getParentFile().mkdirs();
 
-            ILangCompilationProvider provider =
-                    queryFile.getName().endsWith("aql") ? aqlCompilationProvider : sqlppCompilationProvider;
+            ILangCompilationProvider provider = sqlppCompilationProvider;
             if (extensionLangCompilationProvider != null) {
                 provider = extensionLangCompilationProvider;
             }
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/querygen/AQLToSQLPPConverter.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/querygen/AQLToSQLPPConverter.java
deleted file mode 100644
index 9b06143..0000000
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/querygen/AQLToSQLPPConverter.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.test.querygen;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.util.List;
-
-import org.apache.asterix.lang.aql.parser.AQLParserFactory;
-import org.apache.asterix.lang.aql.util.AQLFormatPrintUtil;
-import org.apache.asterix.lang.common.base.IParser;
-import org.apache.asterix.lang.common.base.IParserFactory;
-import org.apache.asterix.lang.common.base.Statement;
-import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
-import org.apache.commons.io.FileUtils;
-
-public class AQLToSQLPPConverter {
-
-    private final static IParserFactory aqlParserFactory = new AQLParserFactory();
-    private final static IParserFactory sqlppParserFactory = new SqlppParserFactory();
-
-    public static void convert(String dirName) throws Exception {
-        File dir = new File(dirName);
-        File target = new File(dirName + "_sqlpp");
-        FileUtils.deleteQuietly(target);
-        FileUtils.forceMkdir(target);
-        convert(dir, target);
-    }
-
-    private static void convert(File src, File dest) throws Exception {
-        if (src.isFile()) {
-            BufferedReader parserReader = new BufferedReader(new InputStreamReader(new FileInputStream(src)));
-            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(src)));
-            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dest)));
-            try {
-                String line = null;
-                while ((line = reader.readLine()) != null) {
-                    if (line.startsWith("/*") || line.startsWith(" *") || line.startsWith("*") || line.startsWith("\t")
-                            || line.startsWith(" \t")) {
-                        writer.write(line + "\n");
-                    } else {
-                        break;
-                    }
-                }
-                writer.write("\n");
-                reader.close();
-
-                IParser parser = aqlParserFactory.createParser(parserReader);
-                List<Statement> statements = parser.parse();
-                parserReader.close();
-
-                String sqlString = AQLFormatPrintUtil.toSQLPPString(statements);
-                writer.write(sqlString);
-            } catch (Exception e) {
-                System.out.println("AQL parser fails at: " + src.getAbsolutePath());
-                //e.printStackTrace();
-            } finally {
-                parserReader.close();
-                reader.close();
-                writer.close();
-            }
-
-            BufferedReader sqlReader = new BufferedReader(new InputStreamReader(new FileInputStream(dest)));
-            try {
-                IParser sqlParser = sqlppParserFactory.createParser(sqlReader);
-                sqlParser.parse();
-            } catch (Exception e) {
-                System.out.println("SQL++ parser cannot parse: ");
-                System.out.println(dest.getAbsolutePath());
-                e.printStackTrace();
-            } finally {
-                sqlReader.close();
-            }
-            return;
-        }
-        for (File child : src.listFiles()) {
-            String lastName = child.getName();
-            lastName = lastName.replaceAll("\\.aql", "\\.sqlpp");
-            File targetChild = new File(dest, lastName);
-            if (child.isDirectory()) {
-                FileUtils.forceMkdir(targetChild);
-            } else {
-                targetChild.createNewFile();
-            }
-            convert(child, targetChild);
-        }
-    }
-
-    public static void main(String[] args) throws Exception {
-        convert("src/test/resources/runtimets/queries");
-        convert("src/test/resources/optimizerts/queries");
-    }
-
-}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.sqlpp
similarity index 85%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.sqlpp
index 7b8c63b..98ad1ff 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.sqlpp
@@ -18,27 +18,27 @@
  */
 drop dataverse experiments if exists;
 create dataverse experiments;
-use dataverse experiments;
+use experiments;
 
 create type TwitterUserType as closed {
-    screen-name: string,
+    `screen-name`: string,
     lang: string,
     friends_count: int32,
     statuses_count: int32,
     name: string,
     followers_count: int32
-}
+};
 
 create type TweetMessageType as closed {
     tweetid: string,
-    tweetid-copy:string,
+    `tweetid-copy`:string,
     user: TwitterUserType,
-    sender-location: point,
-    send-time: datetime,
-    send-time-copy:datetime,
-    referred-topics: {{ string }},
-    message-text: string
-}
+    `sender-location`: point,
+    `send-time`: datetime,
+    `send-time-copy`:datetime,
+    `referred-topics`: {{ string }},
+    `message-text`: string
+};
 
 create dataset Tweets1(TweetMessageType) primary key tweetid;
 create dataset Tweets2(TweetMessageType) primary key tweetid;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.sqlpp
similarity index 92%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.sqlpp
index e056a87..63a5589 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.sqlpp
@@ -17,8 +17,8 @@
  * under the License.
  */
 
-use dataverse experiments;
-set wait-for-completion-feed "false";
+use experiments;
+set `wait-for-completion-feed` "false";
 
 connect feed TweetFeed to dataset Tweets1;
 connect feed TweetFeed to dataset Tweets2;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.3.server.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.3.server.sqlpp
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.3.server.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.3.server.sqlpp
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.4.sleep.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.4.sleep.sqlpp
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.4.sleep.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.4.sleep.sqlpp
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.sqlpp
similarity index 96%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.sqlpp
index 2e7268e..6def89b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.sqlpp
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-use dataverse experiments;
+use experiments;
 stop feed TweetFeed;
 disconnect feed TweetFeed from dataset Tweets1;
 disconnect feed TweetFeed from dataset Tweets2;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.7.server.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.7.server.sqlpp
similarity index 100%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.7.server.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.7.server.sqlpp
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.sqlpp
similarity index 96%
rename from asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.aql
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.sqlpp
index e3097c8..e4d2615 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.sqlpp
@@ -17,5 +17,5 @@
  * under the License.
  */
 
-use dataverse experiments;
+use experiments;
 drop dataverse experiments;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.1.ddl.aqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.1.ddl.aqlpp
deleted file mode 100644
index bd244d0..0000000
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/union/query-ASTERIXDB-1205-3/query-ASTERIXDB-1205.1.ddl.aqlpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/Servlets.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/Servlets.java
index 93a959f..69e9267 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/Servlets.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/Servlets.java
@@ -23,7 +23,6 @@
     public static final String QUERY_STATUS = "/query/service/status/*";
     public static final String QUERY_RESULT = "/query/service/result/*";
     public static final String QUERY_SERVICE = "/query/service";
-    public static final String QUERY_AQL = "/query/aql";
     public static final String CONNECTOR = "/connector";
     public static final String REBALANCE = "/admin/rebalance";
     public static final String SHUTDOWN = "/admin/shutdown";
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
deleted file mode 100644
index 1174717..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/DistinctClause.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.clause;
-
-import java.util.List;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
-import org.apache.asterix.lang.common.base.AbstractClause;
-import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
-
-public class DistinctClause extends AbstractClause {
-
-    private List<Expression> distinctByExprs;
-
-    public DistinctClause(List<Expression> distinctByExpr) {
-        this.distinctByExprs = distinctByExpr;
-    }
-
-    public List<Expression> getDistinctByExpr() {
-        return distinctByExprs;
-    }
-
-    public void setDistinctByExpr(List<Expression> exprList) {
-        this.distinctByExprs = exprList;
-    }
-
-    @Override
-    public ClauseType getClauseType() {
-        return ClauseType.DISTINCT_BY_CLAUSE;
-    }
-
-    @Override
-    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
deleted file mode 100644
index 39ad04f..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/clause/ForClause.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.clause;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
-import org.apache.asterix.lang.common.base.AbstractClause;
-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;
-
-public class ForClause extends AbstractClause {
-    private VariableExpr varExpr = null;
-    private VariableExpr posExpr = null;
-    private Expression inExpr = null;
-
-    public ForClause() {
-    }
-
-    public ForClause(VariableExpr varExpr, Expression inExpr) {
-        this.varExpr = varExpr;
-        this.inExpr = inExpr;
-    }
-
-    public ForClause(VariableExpr varExpr, Expression inExpr, VariableExpr posExpr) {
-        this.varExpr = varExpr;
-        this.inExpr = inExpr;
-        this.posExpr = posExpr;
-    }
-
-    public VariableExpr getVarExpr() {
-        return varExpr;
-    }
-
-    public void setVarExpr(VariableExpr varExpr) {
-        this.varExpr = varExpr;
-    }
-
-    public Expression getInExpr() {
-        return inExpr;
-    }
-
-    public void setInExpr(Expression inExpr) {
-        this.inExpr = inExpr;
-    }
-
-    @Override
-    public ClauseType getClauseType() {
-        return ClauseType.FOR_CLAUSE;
-    }
-
-    @Override
-    public <R, T> R accept(ILangVisitor<R, T> visitor, T arg) throws CompilationException {
-        return ((IAQLVisitor<R, T>) visitor).visit(this, arg);
-    }
-
-    public void setPosExpr(VariableExpr posExpr) {
-        this.posExpr = posExpr;
-    }
-
-    public VariableExpr getPosVarExpr() {
-        return posExpr;
-    }
-
-    public boolean hasPosVar() {
-        return posExpr != null;
-    }
-}
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
deleted file mode 100644
index 54fd8cf..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/FLWOGRExpression.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.expression;
-
-import java.util.List;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
-import org.apache.asterix.lang.common.base.AbstractExpression;
-import org.apache.asterix.lang.common.base.Clause;
-import org.apache.asterix.lang.common.base.Clause.ClauseType;
-import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
-
-public class FLWOGRExpression extends AbstractExpression {
-    private List<Clause> clauseList;
-    private Expression returnExpr;
-
-    public FLWOGRExpression() {
-        super();
-    }
-
-    public FLWOGRExpression(List<Clause> clauseList, Expression returnExpr) {
-        super();
-        this.clauseList = clauseList;
-        this.returnExpr = returnExpr;
-    }
-
-    public List<Clause> getClauseList() {
-        return clauseList;
-    }
-
-    public void setClauseList(List<Clause> clauseList) {
-        this.clauseList = clauseList;
-    }
-
-    public Expression getReturnExpr() {
-        return returnExpr;
-    }
-
-    public void setReturnExpr(Expression returnExpr) {
-        this.returnExpr = returnExpr;
-    }
-
-    @Override
-    public Kind getKind() {
-        return Kind.FLWOGR_EXPRESSION;
-    }
-
-    public boolean noForClause() {
-        for (Clause c : clauseList) {
-            if (c.getClauseType() == ClauseType.FOR_CLAUSE) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    @Override
-    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/UnionExpr.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/UnionExpr.java
deleted file mode 100644
index bb29762..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/expression/UnionExpr.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.expression;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.lang.aql.visitor.base.IAQLVisitor;
-import org.apache.asterix.lang.common.base.AbstractExpression;
-import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
-
-public class UnionExpr extends AbstractExpression {
-
-    private List<Expression> exprs;
-
-    public UnionExpr() {
-        exprs = new ArrayList<>();
-    }
-
-    public UnionExpr(List<Expression> exprs) {
-        this.exprs = exprs;
-    }
-
-    @Override
-    public Kind getKind() {
-        return Kind.UNION_EXPRESSION;
-    }
-
-    public List<Expression> getExprs() {
-        return exprs;
-    }
-
-    public void setExprs(List<Expression> exprs) {
-        this.exprs = exprs;
-    }
-
-    public void addExpr(Expression exp) {
-        exprs.add(exp);
-    }
-
-    @Override
-    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/AQLParserFactory.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/AQLParserFactory.java
deleted file mode 100644
index 3aa1217..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/parser/AQLParserFactory.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.parser;
-
-import java.io.Reader;
-
-import org.apache.asterix.lang.common.base.IParser;
-import org.apache.asterix.lang.common.base.IParserFactory;
-
-public class AQLParserFactory implements IParserFactory {
-
-    // WARNING: This value is stored in function metadata. Do not modify.
-    public static final String AQL = "AQL";
-
-    @Override
-    public IParser createParser(String query) {
-        return new AQLParser(query);
-    }
-
-    @Override
-    public IParser createParser(Reader reader) {
-        return new AQLParser(reader);
-    }
-
-    @Override
-    public String getLanguage() {
-        return AQL;
-    }
-}
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlFunctionBodyRewriter.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlFunctionBodyRewriter.java
deleted file mode 100644
index e8b6747..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlFunctionBodyRewriter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.asterix.lang.aql.rewrites;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.lang.common.base.IParserFactory;
-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.struct.VarIdentifier;
-import org.apache.asterix.metadata.declared.MetadataProvider;
-
-public final class AqlFunctionBodyRewriter extends AqlQueryRewriter {
-
-    public AqlFunctionBodyRewriter(IParserFactory parserFactory) {
-        super(parserFactory);
-    }
-
-    @Override
-    public void rewrite(List<FunctionDecl> declaredFunctions, IReturningStatement topStatement,
-            MetadataProvider metadataProvider, LangRewritingContext context, boolean inlineUdfs,
-            Collection<VarIdentifier> externalVars) throws CompilationException {
-        setup(declaredFunctions, topStatement, metadataProvider, context);
-        resolveFunctionCalls();
-        inlineDeclaredUdfs();
-    }
-}
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlFunctionBodyRewriterFactory.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlFunctionBodyRewriterFactory.java
deleted file mode 100644
index f14eef9..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlFunctionBodyRewriterFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.asterix.lang.aql.rewrites;
-
-import org.apache.asterix.lang.common.base.IParserFactory;
-import org.apache.asterix.lang.common.base.IQueryRewriter;
-import org.apache.asterix.lang.common.base.IRewriterFactory;
-import org.apache.asterix.lang.common.base.IStatementRewriter;
-
-public final class AqlFunctionBodyRewriterFactory implements IRewriterFactory {
-
-    private final IParserFactory parserFactory;
-
-    public AqlFunctionBodyRewriterFactory(IParserFactory parserFactory) {
-        this.parserFactory = parserFactory;
-    }
-
-    @Override
-    public IQueryRewriter createQueryRewriter() {
-        return new AqlFunctionBodyRewriter(parserFactory);
-    }
-
-    @Override
-    public IStatementRewriter createStatementRewriter() {
-        throw new IllegalStateException("There could not be non-query statements inside a function definition.");
-    }
-}
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
deleted file mode 100644
index 53893cb..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlQueryRewriter.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.rewrites;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-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;
-import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-import org.apache.asterix.lang.aql.rewrites.visitor.AqlFunctionCallResolverVisitor;
-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.Expression.Kind;
-import org.apache.asterix.lang.common.base.IParserFactory;
-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.CallExpr;
-import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.parser.FunctionParser;
-import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
-import org.apache.asterix.lang.common.statement.FunctionDecl;
-import org.apache.asterix.lang.common.struct.Identifier;
-import org.apache.asterix.lang.common.struct.VarIdentifier;
-import org.apache.asterix.lang.common.util.FunctionUtil;
-import org.apache.asterix.lang.common.visitor.GatherFunctionCallsVisitor;
-import org.apache.asterix.metadata.declared.MetadataProvider;
-import org.apache.hyracks.algebricks.common.utils.Pair;
-
-class AqlQueryRewriter implements IQueryRewriter {
-
-    private final IParserFactory parserFactory;
-    private final FunctionParser functionParser;
-    private IReturningStatement topStatement;
-    private List<FunctionDecl> declaredFunctions;
-    private LangRewritingContext context;
-    private MetadataProvider metadataProvider;
-
-    AqlQueryRewriter(IParserFactory parserFactory) {
-        this.parserFactory = parserFactory;
-        functionParser = new FunctionParser(parserFactory);
-    }
-
-    protected void setup(List<FunctionDecl> declaredFunctions, IReturningStatement topStatement,
-            MetadataProvider metadataProvider, LangRewritingContext context) {
-        this.topStatement = topStatement;
-        this.context = context;
-        this.declaredFunctions = declaredFunctions;
-        this.metadataProvider = metadataProvider;
-    }
-
-    @Override
-    public void rewrite(List<FunctionDecl> declaredFunctions, IReturningStatement topStatement,
-            MetadataProvider metadataProvider, LangRewritingContext context, boolean inlineUdfs,
-            Collection<VarIdentifier> externalVars) throws CompilationException {
-        setup(declaredFunctions, topStatement, metadataProvider, context);
-        if (topStatement.isTopLevel()) {
-            wrapInLets();
-        }
-        resolveFunctionCalls();
-        inlineDeclaredUdfs();
-        topStatement.setVarCounter(context.getVarCounter().get());
-    }
-
-    protected void wrapInLets() {
-        // If the top expression of the main statement is not a FLWOR, it wraps
-        // it into a let clause.
-        if (topStatement == null) {
-            return;
-        }
-        Expression body = topStatement.getBody();
-        if (body.getKind() != Kind.FLWOGR_EXPRESSION) {
-            VarIdentifier var = context.newVariable();
-            VariableExpr v = new VariableExpr(var);
-            LetClause c1 = new LetClause(v, body);
-            ArrayList<Clause> clauseList = new ArrayList<>(1);
-            clauseList.add(c1);
-            FLWOGRExpression newBody = new FLWOGRExpression(clauseList, new VariableExpr(var));
-            topStatement.setBody(newBody);
-        }
-    }
-
-    protected void resolveFunctionCalls() throws CompilationException {
-        if (topStatement == null) {
-            return;
-        }
-        AqlFunctionCallResolverVisitor visitor =
-                new AqlFunctionCallResolverVisitor(metadataProvider, declaredFunctions);
-        topStatement.accept(visitor, null);
-    }
-
-    protected void inlineDeclaredUdfs() throws CompilationException {
-        if (topStatement == null) {
-            return;
-        }
-        List<FunctionSignature> funIds = new ArrayList<FunctionSignature>();
-        for (FunctionDecl fdecl : declaredFunctions) {
-            funIds.add(fdecl.getSignature());
-        }
-
-        List<FunctionDecl> storedFunctionDecls = new ArrayList<>();
-        for (Expression topLevelExpr : topStatement.getDirectlyEnclosedExpressions()) {
-            storedFunctionDecls.addAll(FunctionUtil.retrieveUsedStoredFunctions(metadataProvider, topLevelExpr, funIds,
-                    null, this::getFunctionCalls, functionParser, metadataProvider.getDefaultDataverseName()));
-            declaredFunctions.addAll(storedFunctionDecls);
-        }
-        if (!declaredFunctions.isEmpty()) {
-            AQLInlineUdfsVisitor visitor = new AQLInlineUdfsVisitor(context,
-                    new AqlFunctionBodyRewriterFactory(parserFactory), declaredFunctions, metadataProvider);
-            while (topStatement.accept(visitor, declaredFunctions)) {
-                // loop until no more changes
-            }
-        }
-        declaredFunctions.removeAll(storedFunctionDecls);
-    }
-
-    @Override
-    public Set<CallExpr> getFunctionCalls(Expression expression) throws CompilationException {
-        GatherFunctionCalls gfc = new GatherFunctionCalls();
-        expression.accept(gfc, null);
-        return gfc.getCalls();
-    }
-
-    @Override
-    public Set<VariableExpr> getExternalVariables(Expression expr) {
-        throw new UnsupportedOperationException("getExternalVariables not implemented for AQL");
-    }
-
-    private static class GatherFunctionCalls extends GatherFunctionCallsVisitor implements IAQLVisitor<Void, Void> {
-
-        public GatherFunctionCalls() {
-        }
-
-        @Override
-        public Void visit(DistinctClause dc, Void arg) throws CompilationException {
-            for (Expression e : dc.getDistinctByExpr()) {
-                e.accept(this, arg);
-            }
-            return null;
-        }
-
-        @Override
-        public Void visit(FLWOGRExpression flwor, Void arg) throws CompilationException {
-            for (Clause c : flwor.getClauseList()) {
-                c.accept(this, arg);
-            }
-            flwor.getReturnExpr().accept(this, arg);
-            return null;
-        }
-
-        @Override
-        public Void visit(ForClause fc, Void arg) throws CompilationException {
-            fc.getInExpr().accept(this, arg);
-            if (fc.getPosVarExpr() != null) {
-                fc.getPosVarExpr().accept(this, arg);
-            }
-            return null;
-        }
-
-        @Override
-        public Void visit(GroupbyClause gc, Void arg) throws CompilationException {
-            for (List<GbyVariableExpressionPair> gbyPairList : gc.getGbyPairList()) {
-                for (GbyVariableExpressionPair p : gbyPairList) {
-                    p.getExpr().accept(this, arg);
-                }
-            }
-            if (gc.hasDecorList()) {
-                for (GbyVariableExpressionPair p : gc.getDecorPairList()) {
-                    p.getExpr().accept(this, arg);
-                }
-            }
-            if (gc.hasGroupFieldList()) {
-                for (Pair<Expression, Identifier> p : gc.getGroupFieldList()) {
-                    p.first.accept(this, arg);
-                }
-            }
-            if (gc.hasWithMap()) {
-                for (Map.Entry<Expression, VariableExpr> me : gc.getWithVarMap().entrySet()) {
-                    me.getKey().accept(this, arg);
-                }
-            }
-            return null;
-        }
-
-        @Override
-        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 CompilationException {
-            for (Expression e : u.getExprs()) {
-                e.accept(this, arg);
-            }
-            return null;
-        }
-    }
-}
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlRewriterFactory.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlRewriterFactory.java
deleted file mode 100644
index c0ce3d3..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlRewriterFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.rewrites;
-
-import org.apache.asterix.lang.common.base.IParserFactory;
-import org.apache.asterix.lang.common.base.IQueryRewriter;
-import org.apache.asterix.lang.common.base.IRewriterFactory;
-import org.apache.asterix.lang.common.base.IStatementRewriter;
-
-public class AqlRewriterFactory implements IRewriterFactory {
-
-    private final IParserFactory parserFactory;
-
-    public AqlRewriterFactory(IParserFactory parserFactory) {
-        this.parserFactory = parserFactory;
-    }
-
-    @Override
-    public IQueryRewriter createQueryRewriter() {
-        return new AqlQueryRewriter(parserFactory);
-    }
-
-    @Override
-    public IStatementRewriter createStatementRewriter() {
-        return new AqlStatementRewriter();
-    }
-
-}
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
deleted file mode 100644
index eee6499..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/AqlStatementRewriter.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.rewrites;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.lang.aql.visitor.AqlStatementRewriteVisitor;
-import org.apache.asterix.lang.common.base.IStatementRewriter;
-import org.apache.asterix.lang.common.base.Statement;
-import org.apache.asterix.lang.common.struct.VarIdentifier;
-import org.apache.asterix.metadata.declared.MetadataProvider;
-
-class AqlStatementRewriter implements IStatementRewriter {
-
-    private static final char VAR_PREFIX = '$';
-
-    @Override
-    public boolean isRewritable(Statement.Kind kind) {
-        return kind == Statement.Kind.DELETE;
-    }
-
-    @Override
-    public void rewrite(Statement stmt, MetadataProvider metadataProvider) throws CompilationException {
-        if (stmt != null) {
-            stmt.accept(AqlStatementRewriteVisitor.INSTANCE, metadataProvider);
-        }
-    }
-
-    @Override
-    public String toExternalVariableName(String statementParameterName) {
-        return null;
-    }
-
-    @Override
-    public String toFunctionParameterName(VarIdentifier paramVar) {
-        String name = paramVar.getValue();
-        if (name.charAt(0) != VAR_PREFIX) {
-            throw new IllegalArgumentException(name);
-        }
-        return name.substring(1);
-    }
-}
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/visitor/AqlFunctionCallResolverVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/visitor/AqlFunctionCallResolverVisitor.java
deleted file mode 100644
index 32f368b..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/rewrites/visitor/AqlFunctionCallResolverVisitor.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.asterix.lang.aql.rewrites.visitor;
-
-import java.util.List;
-import java.util.Set;
-import java.util.function.BiFunction;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.common.functions.FunctionSignature;
-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.statement.FunctionDecl;
-import org.apache.asterix.lang.common.util.FunctionUtil;
-import org.apache.asterix.metadata.declared.MetadataProvider;
-
-public class AqlFunctionCallResolverVisitor extends AbstractAqlSimpleExpressionVisitor {
-
-    private final MetadataProvider metadataProvider;
-
-    private final Set<FunctionSignature> declaredFunctions;
-
-    private final BiFunction<String, Integer, FunctionSignature> callExprResolver;
-
-    public AqlFunctionCallResolverVisitor(MetadataProvider metadataProvider, List<FunctionDecl> declaredFunctions) {
-        this.metadataProvider = metadataProvider;
-        this.declaredFunctions = FunctionUtil.getFunctionSignatures(declaredFunctions);
-        this.callExprResolver = createBuiltinFunctionResolver(metadataProvider);
-    }
-
-    @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
-        FunctionSignature fs = FunctionUtil.resolveFunctionCall(callExpr.getFunctionSignature(),
-                callExpr.getSourceLocation(), metadataProvider, declaredFunctions, callExprResolver);
-        callExpr.setFunctionSignature(fs);
-        return super.visit(callExpr, arg);
-    }
-
-    protected BiFunction<String, Integer, FunctionSignature> createBuiltinFunctionResolver(
-            MetadataProvider metadataProvider) {
-        return FunctionUtil.createBuiltinFunctionResolver(metadataProvider);
-    }
-}
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
deleted file mode 100644
index 7848bf3..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLFormatPrintUtil.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.util;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-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;
-import org.apache.asterix.lang.common.base.Statement;
-
-public class AQLFormatPrintUtil {
-
-    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 CompilationException {
-        AQLFormatPrintVisitor visitor = new AQLFormatPrintVisitor(output);
-        for (Statement expr : exprs) {
-            expr.accept(visitor, 0);
-        }
-    }
-
-    /**
-     * @param expr
-     *            a language expression.
-     * @return a formatted string of a language expression.
-     * @throws CompilationException
-     */
-    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 CompilationException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        PrintWriter output = new PrintWriter(bos);
-        AQLFormatPrintVisitor visitor = new AQLFormatPrintVisitor(output);
-        for (ILangExpression expr : exprs) {
-            expr.accept(visitor, 0);
-        }
-        output.close();
-        return bos.toString();
-    }
-
-    public static String toSQLPPString(List<Statement> exprs) throws CompilationException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        PrintWriter output = new PrintWriter(bos);
-        AQLToSQLPPPrintVisitor visitor = new AQLToSQLPPPrintVisitor(output);
-        for (Statement expr : exprs) {
-            expr.accept(visitor, 0);
-        }
-        output.close();
-        return bos.toString();
-    }
-}
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
deleted file mode 100644
index eb087b8..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/util/AQLVariableSubstitutionUtil.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.util;
-
-import java.util.Map;
-
-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;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
-import org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment;
-import org.apache.hyracks.api.exceptions.IWarningCollector;
-import org.apache.hyracks.api.exceptions.Warning;
-
-public class AQLVariableSubstitutionUtil {
-
-    private AQLVariableSubstitutionUtil() {
-    }
-
-    public static ILangExpression substituteVariable(ILangExpression expression,
-            Map<VariableExpr, Expression> varExprMap) throws CompilationException {
-        AQLCloneAndSubstituteVariablesVisitor visitor =
-                new AQLCloneAndSubstituteVariablesVisitor(new LangRewritingContext(0, new IWarningCollector() {
-                    @Override
-                    public void warn(Warning warning) {
-                        // no-op
-                    }
-
-                    @Override
-                    public boolean shouldWarn() {
-                        return false;
-                    }
-
-                    @Override
-                    public long getTotalWarningsCount() {
-                        return 0;
-                    }
-                }));
-        VariableSubstitutionEnvironment env = new VariableSubstitutionEnvironment(varExprMap);
-        return expression.accept(visitor, env).first;
-    }
-
-}
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
deleted file mode 100644
index d78640c..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLAstPrintVisitor.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor;
-
-import java.io.PrintWriter;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.common.exceptions.ErrorCode;
-import org.apache.asterix.lang.aql.clause.DistinctClause;
-import org.apache.asterix.lang.aql.clause.ForClause;
-import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-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.clause.GroupbyClause;
-import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
-import org.apache.asterix.lang.common.expression.ListSliceExpression;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.visitor.QueryPrintVisitor;
-
-class AQLAstPrintVisitor extends QueryPrintVisitor implements IAQLVisitor<Void, Integer> {
-
-    public AQLAstPrintVisitor(PrintWriter out) {
-        super(out);
-    }
-
-    @Override
-    public Void visit(FLWOGRExpression flwor, Integer step) throws CompilationException {
-        out.println(skip(step) + "FLWOGR [");
-        for (Clause cl : flwor.getClauseList()) {
-            cl.accept(this, step + 1);
-        }
-        out.println(skip(step + 1) + "Return");
-        flwor.getReturnExpr().accept(this, step + 2);
-        out.println(skip(step) + "]");
-        return null;
-    }
-
-    @Override
-    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 ");
-        fc.getInExpr().accept(this, step + 1);
-        return null;
-    }
-
-    @Override
-    public Void visit(UnionExpr u, Integer step) throws CompilationException {
-        out.println(skip(step) + "Union [");
-        for (Expression expr : u.getExprs()) {
-            expr.accept(this, step + 1);
-        }
-        out.println(skip(step) + "]");
-        return null;
-    }
-
-    @Override
-    public Void visit(DistinctClause dc, Integer step) throws CompilationException {
-        out.print(skip(step) + "Distinct ");
-        for (Expression expr : dc.getDistinctByExpr()) {
-            expr.accept(this, step + 1);
-        }
-        return null;
-    }
-
-    @Override
-    public Void visit(ListSliceExpression expression, Integer step) throws CompilationException {
-        // This functionality is not supported for AQL
-        return null;
-    }
-
-    @Override
-    public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
-        out.println(skip(step) + "Groupby");
-        List<List<GbyVariableExpressionPair>> gbyList = gc.getGbyPairList();
-        if (gbyList.size() == 1) {
-            for (GbyVariableExpressionPair pair : gbyList.get(0)) {
-                if (pair.getVar() != null) {
-                    pair.getVar().accept(this, step + 1);
-                    out.println(skip(step + 1) + ":=");
-                }
-                pair.getExpr().accept(this, step + 1);
-            }
-        } else {
-            // AQL does not support grouping sets
-            throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, gc.getSourceLocation(), "");
-        }
-        if (gc.hasDecorList()) {
-            out.println(skip(step + 1) + "Decor");
-            for (GbyVariableExpressionPair pair : gc.getDecorPairList()) {
-                if (pair.getVar() != null) {
-                    pair.getVar().accept(this, step + 1);
-                    out.println(skip(step + 1) + ":=");
-                }
-                pair.getExpr().accept(this, step + 1);
-            }
-        }
-        if (gc.hasWithMap()) {
-            out.println(skip(step + 1) + "With");
-            for (Map.Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
-                Expression key = entry.getKey();
-                VariableExpr value = entry.getValue();
-                key.accept(this, step + 1);
-                if (!key.equals(value)) {
-                    out.println(skip(step + 1) + "AS");
-                    value.accept(this, step + 1);
-                }
-            }
-        }
-        out.println();
-        return null;
-    }
-}
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLAstPrintVisitorFactory.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLAstPrintVisitorFactory.java
deleted file mode 100644
index ff76fee..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLAstPrintVisitorFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor;
-
-import java.io.PrintWriter;
-
-import org.apache.asterix.lang.common.base.IAstPrintVisitorFactory;
-import org.apache.asterix.lang.common.visitor.QueryPrintVisitor;
-
-public class AQLAstPrintVisitorFactory implements IAstPrintVisitorFactory {
-
-    @Override
-    public QueryPrintVisitor createLangVisitor(PrintWriter writer) {
-        return new AQLAstPrintVisitor(writer);
-    }
-
-}
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
deleted file mode 100644
index 6008723..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLCloneAndSubstituteVariablesVisitor.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-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;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-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.ILangExpression;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
-import org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment;
-import org.apache.asterix.lang.common.util.VariableCloneAndSubstitutionUtil;
-import org.apache.asterix.lang.common.visitor.CloneAndSubstituteVariablesVisitor;
-import org.apache.hyracks.algebricks.common.utils.Pair;
-
-public class AQLCloneAndSubstituteVariablesVisitor extends CloneAndSubstituteVariablesVisitor implements
-        IAQLVisitor<Pair<ILangExpression, VariableSubstitutionEnvironment>, VariableSubstitutionEnvironment> {
-
-    private LangRewritingContext context;
-
-    public AQLCloneAndSubstituteVariablesVisitor(LangRewritingContext context) {
-        super(context);
-        this.context = context;
-    }
-
-    @Override
-    public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(ForClause fc,
-            VariableSubstitutionEnvironment env) throws CompilationException {
-        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fc.getInExpr().accept(this, env);
-        VariableExpr varExpr = fc.getVarExpr();
-        VariableExpr newVe = generateNewVariable(context, varExpr);
-        VariableSubstitutionEnvironment resultEnv = new VariableSubstitutionEnvironment(env);
-        resultEnv.removeSubstitution(varExpr);
-
-        VariableExpr newPosVarExpr = null;
-        if (fc.hasPosVar()) {
-            VariableExpr posVarExpr = fc.getPosVarExpr();
-            newPosVarExpr = generateNewVariable(context, posVarExpr);
-            resultEnv.removeSubstitution(posVarExpr);
-        }
-        ForClause newFor = new ForClause(newVe, (Expression) p1.first, newPosVarExpr);
-        return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newFor, resultEnv);
-    }
-
-    @Override
-    public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FLWOGRExpression flwor,
-            VariableSubstitutionEnvironment env) throws CompilationException {
-        List<Clause> newClauses = new ArrayList<Clause>(flwor.getClauseList().size());
-        VariableSubstitutionEnvironment currentEnv = env;
-        for (Clause c : flwor.getClauseList()) {
-            Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = c.accept(this, currentEnv);
-            currentEnv = p1.second;
-            newClauses.add((Clause) p1.first);
-        }
-        Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = flwor.getReturnExpr().accept(this, currentEnv);
-        Expression newReturnExpr = (Expression) p2.first;
-        FLWOGRExpression newFlwor = new FLWOGRExpression(newClauses, newReturnExpr);
-        return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newFlwor, p2.second);
-    }
-
-    @Override
-    public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(UnionExpr u,
-            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);
-    }
-
-    @Override
-    public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(DistinctClause dc,
-            VariableSubstitutionEnvironment env) throws CompilationException {
-        List<Expression> exprList =
-                VariableCloneAndSubstitutionUtil.visitAndCloneExprList(dc.getDistinctByExpr(), env, this);
-        DistinctClause dc2 = new DistinctClause(exprList);
-        return new Pair<ILangExpression, VariableSubstitutionEnvironment>(dc2, env);
-    }
-}
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
deleted file mode 100644
index 3edbcce..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLFormatPrintVisitor.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor;
-
-import java.io.PrintWriter;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.common.exceptions.ErrorCode;
-import org.apache.asterix.lang.aql.clause.DistinctClause;
-import org.apache.asterix.lang.aql.clause.ForClause;
-import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-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.clause.GroupbyClause;
-import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.visitor.FormatPrintVisitor;
-
-public class AQLFormatPrintVisitor extends FormatPrintVisitor implements IAQLVisitor<Void, Integer> {
-
-    public AQLFormatPrintVisitor(PrintWriter out) {
-        super(out);
-    }
-
-    @Override
-    public Void visit(FLWOGRExpression flwor, Integer step) throws CompilationException {
-        for (Clause cl : flwor.getClauseList()) {
-            cl.accept(this, step);
-        }
-        out.print(skip(step) + "return ");
-        flwor.getReturnExpr().accept(this, step + 2);
-        return null;
-    }
-
-    @Override
-    public Void visit(ForClause fc, Integer step) throws CompilationException {
-        out.print("for ");
-        fc.getVarExpr().accept(this, step + 2);
-        if (fc.hasPosVar()) {
-            out.print(" at ");
-            fc.getPosVarExpr().accept(this, step + 2);
-        }
-        out.print(" in ");
-        fc.getInExpr().accept(this, step + 2);
-        out.println();
-        return null;
-    }
-
-    @Override
-    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 CompilationException {
-        out.print(skip(step) + "distinct by ");
-        printDelimitedExpressions(dc.getDistinctByExpr(), COMMA, step + 2);
-        out.println();
-        return null;
-    }
-
-    @Override
-    public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
-        if (gc.hasHashGroupByHint()) {
-            out.println(skip(step) + "/* +hash */");
-        }
-        out.print(skip(step) + "group by ");
-        List<List<GbyVariableExpressionPair>> gbyList = gc.getGbyPairList();
-        if (gbyList.size() == 1) {
-            printDelimitedGbyExpressions(gbyList.get(0), step + 2);
-        } else {
-            // AQL does not support grouping sets
-            throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, gc.getSourceLocation(), "");
-        }
-        if (gc.hasDecorList()) {
-            out.print(" decor ");
-            printDelimitedGbyExpressions(gc.getDecorPairList(), step + 2);
-        }
-        if (gc.hasWithMap()) {
-            out.print(" with ");
-            Map<Expression, VariableExpr> withVarMap = gc.getWithVarMap();
-            int index = 0;
-            int size = withVarMap.size();
-            for (Map.Entry<Expression, VariableExpr> entry : withVarMap.entrySet()) {
-                Expression key = entry.getKey();
-                VariableExpr value = entry.getValue();
-                key.accept(this, step + 2);
-                if (!key.equals(value)) {
-                    out.print(" as ");
-                    value.accept(this, step + 2);
-                }
-                if (++index < size) {
-                    out.print(COMMA);
-                }
-            }
-        }
-        out.println();
-        return null;
-    }
-}
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
deleted file mode 100644
index 92ac21f..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLInlineUdfsVisitor.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-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;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-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.IRewriterFactory;
-import org.apache.asterix.lang.common.clause.LetClause;
-import org.apache.asterix.lang.common.expression.ListSliceExpression;
-import org.apache.asterix.lang.common.rewrites.LangRewritingContext;
-import org.apache.asterix.lang.common.statement.FunctionDecl;
-import org.apache.asterix.lang.common.visitor.AbstractInlineUdfsVisitor;
-import org.apache.asterix.metadata.declared.MetadataProvider;
-import org.apache.hyracks.algebricks.common.utils.Pair;
-
-public class AQLInlineUdfsVisitor extends AbstractInlineUdfsVisitor
-        implements IAQLVisitor<Boolean, List<FunctionDecl>> {
-
-    public AQLInlineUdfsVisitor(LangRewritingContext context, IRewriterFactory rewriterFactory,
-            List<FunctionDecl> declaredFunctions, MetadataProvider metadataProvider) {
-        super(context, rewriterFactory, declaredFunctions, metadataProvider,
-                new AQLCloneAndSubstituteVariablesVisitor(context));
-    }
-
-    @Override
-    public Boolean visit(FLWOGRExpression flwor, List<FunctionDecl> arg) throws CompilationException {
-        boolean changed = false;
-        for (Clause c : flwor.getClauseList()) {
-            if (c.accept(this, arg)) {
-                changed = true;
-            }
-        }
-        Pair<Boolean, Expression> p = inlineUdfsInExpr(flwor.getReturnExpr(), arg);
-        flwor.setReturnExpr(p.second);
-        return changed || p.first;
-    }
-
-    @Override
-    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 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 CompilationException {
-        Pair<Boolean, List<Expression>> p = inlineUdfsInExprList(dc.getDistinctByExpr(), arg);
-        dc.setDistinctByExpr(p.second);
-        return p.first;
-    }
-
-    @Override
-    public Boolean visit(ListSliceExpression expression, List<FunctionDecl> arg) throws CompilationException {
-        // This functionality is not supported for AQL
-        return false;
-    }
-
-    @Override
-    protected Expression generateQueryExpression(List<LetClause> letClauses, Expression returnExpr) {
-        List<Clause> letList = new ArrayList<Clause>();
-        letList.addAll(letClauses);
-        return new FLWOGRExpression(letList, returnExpr);
-    }
-}
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
deleted file mode 100644
index d0d88c8..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AQLToSQLPPPrintVisitor.java
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.asterix.common.exceptions.CompilationException;
-import org.apache.asterix.common.exceptions.ErrorCode;
-import org.apache.asterix.common.metadata.DataverseName;
-import org.apache.asterix.lang.aql.clause.DistinctClause;
-import org.apache.asterix.lang.aql.clause.ForClause;
-import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-import org.apache.asterix.lang.aql.util.AQLVariableSubstitutionUtil;
-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;
-import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.base.Expression.Kind;
-import org.apache.asterix.lang.common.clause.GroupbyClause;
-import org.apache.asterix.lang.common.clause.LetClause;
-import org.apache.asterix.lang.common.clause.WhereClause;
-import org.apache.asterix.lang.common.expression.CallExpr;
-import org.apache.asterix.lang.common.expression.FieldAccessor;
-import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
-import org.apache.asterix.lang.common.expression.OperatorExpr;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.statement.DataverseDecl;
-import org.apache.asterix.lang.common.statement.DeleteStatement;
-import org.apache.asterix.lang.common.statement.InsertStatement;
-import org.apache.asterix.lang.common.statement.Query;
-import org.apache.asterix.lang.common.struct.Identifier;
-import org.apache.asterix.lang.common.struct.OperatorType;
-import org.apache.asterix.lang.common.struct.VarIdentifier;
-import org.apache.asterix.lang.common.util.ExpressionUtils;
-import org.apache.asterix.lang.common.util.FunctionUtil;
-import org.apache.asterix.lang.common.visitor.FormatPrintVisitor;
-import org.apache.hyracks.algebricks.common.utils.Pair;
-
-public class AQLToSQLPPPrintVisitor extends FormatPrintVisitor implements IAQLVisitor<Void, Integer> {
-
-    private final PrintWriter out;
-    private final Set<String> reservedKeywords = new HashSet<String>();
-    private int generatedId = 0;
-
-    public AQLToSQLPPPrintVisitor() {
-        this(new PrintWriter(System.out));
-    }
-
-    public AQLToSQLPPPrintVisitor(PrintWriter out) {
-        super(out);
-        this.out = out;
-        initialize();
-    }
-
-    private void initialize() {
-        dataverseSymbol = " database ";
-        datasetSymbol = " table ";
-        assignSymbol = "=";
-        reservedKeywords.addAll(Arrays.asList(new String[] { "order", "value", "nest", "keyword", "all" }));
-    }
-
-    @Override
-    public Void visit(FLWOGRExpression flwor, Integer step) throws CompilationException {
-        if (step != 0) {
-            out.println("(");
-        }
-        List<Clause> clauseList = new ArrayList<Clause>();
-        clauseList.addAll(flwor.getClauseList());
-
-        // Processes data-independent let clauses.
-        if (hasFor(clauseList)) {
-            processLeadingLetClauses(step, clauseList);
-        }
-
-        // Distill unnecessary order-bys before a group-by.
-        distillRedundantOrderby(clauseList);
-
-        // Correlated "for" clauses after group-by.
-        Pair<GroupbyClause, List<Clause>> extraction = extractUnnestAfterGroupby(clauseList);
-        GroupbyClause cuttingGbyClause = extraction.first;
-        List<Clause> unnestClauseList = extraction.second;
-        Expression returnExpr = flwor.getReturnExpr();
-        if (unnestClauseList.size() == 0) {
-            if (hasFor(clauseList)) {
-                out.print(skip(step) + "select element ");
-                returnExpr.accept(this, step + 2);
-                out.println();
-            } else {
-                // The FLOWGR only contains let-return, then inline let binding expressions into the return expression.
-                Map<VariableExpr, Expression> varExprMap = extractLetBindingVariables(clauseList, cuttingGbyClause);
-                returnExpr = (Expression) AQLVariableSubstitutionUtil.substituteVariable(returnExpr, varExprMap);
-                returnExpr.accept(this, step);
-                return null;
-            }
-        }
-
-        String generated = generateVariableSymbol();
-        if (unnestClauseList.size() > 0) {
-            Map<VariableExpr, Expression> varExprMap =
-                    extractDefinedCollectionVariables(clauseList, cuttingGbyClause, generated);
-
-            returnExpr = (Expression) AQLVariableSubstitutionUtil.substituteVariable(returnExpr, varExprMap);
-            List<Clause> newUnnestClauses = new ArrayList<Clause>();
-            for (Clause nestedCl : unnestClauseList) {
-                newUnnestClauses.add((Clause) AQLVariableSubstitutionUtil.substituteVariable(nestedCl, varExprMap));
-            }
-            unnestClauseList = newUnnestClauses;
-
-            out.print(skip(step) + "select element " + (hasDistinct(unnestClauseList) ? "distinct " : ""));
-            returnExpr.accept(this, step + 2);
-            out.println();
-            out.println(skip(step) + "from");
-            out.print(skip(step + 2) + "( select element " + (hasDistinct(clauseList) ? "distinct " : "") + "{");
-            int index = 0;
-            int size = varExprMap.size();
-            for (VariableExpr var : varExprMap.keySet()) {
-                out.print("\'" + var.getVar().getValue().substring(1) + "\':" + var.getVar().getValue().substring(1));
-                if (++index < size) {
-                    out.print(COMMA);
-                }
-            }
-            out.println("}");
-        }
-
-        reorder(clauseList);
-        reorder(unnestClauseList);
-
-        mergeConsecutiveWhereClauses(clauseList);
-        mergeConsecutiveWhereClauses(unnestClauseList);
-
-        boolean firstFor = true;
-        boolean firstLet = true;
-        int forStep = unnestClauseList.size() == 0 ? step : step + 3;
-        int size = clauseList.size();
-        // Processes all other clauses, with special printing for consecutive
-        // "for"s.
-        for (int i = 0; i < size; ++i) {
-            Clause cl = clauseList.get(i);
-            if (cl.getClauseType() == ClauseType.FOR_CLAUSE) {
-                boolean hasConsequentFor = false;
-                if (i < size - 1) {
-                    Clause nextCl = clauseList.get(i + 1);
-                    hasConsequentFor = nextCl.getClauseType() == ClauseType.FOR_CLAUSE;
-                }
-                visitForClause((ForClause) cl, forStep, firstFor, hasConsequentFor);
-                firstFor = false;
-            } else if (cl.getClauseType() == ClauseType.LET_CLAUSE) {
-                boolean hasConsequentLet = false;
-                if (i < size - 1) {
-                    Clause nextCl = clauseList.get(i + 1);
-                    hasConsequentLet = nextCl.getClauseType() == ClauseType.LET_CLAUSE;
-                }
-                visitLetClause((LetClause) cl, forStep, firstLet, hasConsequentLet);
-                firstLet = false;
-            } else {
-                cl.accept(this, forStep);
-            }
-
-            if (cl.getClauseType() == ClauseType.FROM_CLAUSE || cl.getClauseType() == ClauseType.GROUP_BY_CLAUSE) {
-                firstLet = true;
-            }
-        }
-
-        if (unnestClauseList.size() > 0) {
-            out.println(skip(forStep - 1) + ") as " + generated.substring(1) + ",");
-            for (Clause nestedCl : unnestClauseList) {
-                if (nestedCl.getClauseType() == ClauseType.FOR_CLAUSE) {
-                    visitForClause((ForClause) nestedCl, step - 1, firstFor, false);
-                } else {
-                    nestedCl.accept(this, step);
-                }
-            }
-        }
-
-        if (step > 0) {
-            out.print(skip(step - 2) + ")");
-        }
-        return null;
-    }
-
-    @Override
-    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 CompilationException {
-        if (startFor) {
-            out.print(skip(step) + "from  ");
-        } else {
-            out.print(skip(step + 3));
-        }
-        fc.getInExpr().accept(this, step + 2);
-        out.print(" as ");
-        fc.getVarExpr().accept(this, step + 2);
-        if (fc.hasPosVar()) {
-            out.print(" at ");
-            fc.getPosVarExpr().accept(this, step + 2);
-        }
-        if (hasConsequentFor) {
-            out.print(COMMA);
-        }
-        out.println();
-    }
-
-    private void visitLetClause(LetClause lc, Integer step, boolean startLet, boolean hasConsequentLet)
-            throws CompilationException {
-        if (startLet) {
-            out.print(skip(step) + "with  ");
-        } else {
-            out.print(skip(step + 3));
-        }
-        lc.getVarExpr().accept(this, step + 3);
-        out.print(" as ");
-        lc.getBindingExpr().accept(this, step + 3);
-        if (hasConsequentLet) {
-            out.print(COMMA);
-        }
-        out.println();
-    }
-
-    @Override
-    public Void visit(Query q, Integer step) throws CompilationException {
-        Expression expr = q.getBody();
-        if (expr != null) {
-            if (expr.getKind() != Kind.FLWOGR_EXPRESSION) {
-                out.print("select element ");
-                expr.accept(this, step + 2);
-            } else {
-                expr.accept(this, step);
-            }
-        }
-        if (q.isTopLevel()) {
-            out.println(SEMICOLON);
-        }
-        return null;
-    }
-
-    @Override
-    public Void visit(DataverseDecl dv, Integer step) throws CompilationException {
-        out.println(skip(step) + "use " + generateDataverseName(dv.getDataverseName()) + ";\n\n");
-        return null;
-    }
-
-    @Override
-    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 CompilationException {
-        return null;
-    }
-
-    @Override
-    public Void visit(VariableExpr v, Integer step) {
-        String varStr = v.getVar().getValue().substring(1);
-        if (reservedKeywords.contains(varStr)) {
-            varStr = varStr + "s";
-        }
-        out.print(varStr);
-        return null;
-    }
-
-    @Override
-    public Void visit(LetClause lc, Integer step) throws CompilationException {
-        out.print(skip(step) + "with ");
-        lc.getVarExpr().accept(this, step + 2);
-        out.print(" as ");
-        Expression bindingExpr = lc.getBindingExpr();
-        bindingExpr.accept(this, step + 2);
-        out.println();
-        return null;
-    }
-
-    @Override
-    public Void visit(CallExpr callExpr, Integer step) throws CompilationException {
-        if (FunctionUtil.isBuiltinDatasetFunction(callExpr.getFunctionSignature())) {
-            Pair<DataverseName, String> dataset = FunctionUtil.parseDatasetFunctionArguments(callExpr.getExprList(),
-                    null, callExpr.getSourceLocation(), ExpressionUtils::getStringLiteral);
-            if (dataset.first != null) {
-                out.print(generateDataverseName(dataset.first));
-                out.print(".");
-            }
-            out.print(normalize(dataset.second));
-        } else {
-            printHints(callExpr.getHints(), step);
-            out.print(generateFullName(callExpr.getFunctionSignature().getDataverseName(),
-                    callExpr.getFunctionSignature().getName()) + "(");
-            printDelimitedExpressions(callExpr.getExprList(), COMMA, step);
-            out.print(")");
-        }
-        return null;
-    }
-
-    @Override
-    public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
-        if (gc.hasHashGroupByHint()) {
-            out.println(skip(step) + "/* +hash */");
-        }
-        out.print(skip(step) + "group by ");
-        List<List<GbyVariableExpressionPair>> gbyList = gc.getGbyPairList();
-        if (gbyList.size() == 1) {
-            printDelimitedGbyExpressions(gbyList.get(0), step + 2);
-        } else {
-            // AQL does not support grouping sets
-            throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, gc.getSourceLocation(), "");
-        }
-        out.println();
-        return null;
-    }
-
-    @Override
-    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);
-        out.println(SEMICOLON);
-        return null;
-    }
-
-    @Override
-    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()));
-        if (del.getCondition() != null) {
-            out.print(skip(step) + " where ");
-            del.getCondition().accept(this, step + 2);
-        }
-        out.println(SEMICOLON);
-        return null;
-    }
-
-    @Override
-    protected String normalize(String str) {
-        if (needQuotes(str) || containsReservedKeyWord(str.toLowerCase())) {
-            return revertStringToQuoted(str);
-        }
-        return str;
-    }
-
-    protected boolean containsReservedKeyWord(String str) {
-        if (reservedKeywords.contains(str)) {
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    protected void printDelimitedGbyExpressions(List<GbyVariableExpressionPair> gbyList, int step)
-            throws CompilationException {
-        int gbySize = gbyList.size();
-        int gbyIndex = 0;
-        for (GbyVariableExpressionPair pair : gbyList) {
-            pair.getExpr().accept(this, step);
-            if (pair.getVar() != null) {
-                out.print(" as ");
-                pair.getVar().accept(this, step);
-            }
-            if (++gbyIndex < gbySize) {
-                out.print(COMMA);
-            }
-        }
-    }
-
-    @Override
-    protected void printDelimitedIdentifiers(List<Identifier> ids, String delimiter) {
-        int index = 0;
-        int size = ids.size();
-        for (Identifier id : ids) {
-            String idStr = id.getValue();
-            if (idStr.startsWith("$")) {
-                id = new Identifier(idStr.substring(1));
-            }
-            out.print(id);
-            if (++index < size) {
-                out.print(delimiter);
-            }
-        }
-    }
-
-    // Collects produced variables from group-by.
-    private List<VariableExpr> collectProducedVariablesFromGroupby(GroupbyClause gbyClause) {
-        List<VariableExpr> producedVars = new ArrayList<>();
-        for (List<GbyVariableExpressionPair> gbyPairList : gbyClause.getGbyPairList()) {
-            for (GbyVariableExpressionPair keyPair : gbyPairList) {
-                producedVars.add(keyPair.getVar());
-            }
-        }
-        if (gbyClause.hasDecorList()) {
-            for (GbyVariableExpressionPair keyPair : gbyClause.getDecorPairList()) {
-                producedVars.add(keyPair.getVar());
-            }
-        }
-        if (gbyClause.hasWithMap()) {
-            producedVars.addAll(gbyClause.getWithVarMap().values());
-        }
-        return producedVars;
-    }
-
-    // Randomly generates a new variable symbol.
-    private String generateVariableSymbol() {
-        return "$gen" + generatedId++;
-    }
-
-    // Removes all redundant order by clauses.
-    private void distillRedundantOrderby(List<Clause> clauseList) {
-        List<Clause> redundantOrderbys = new ArrayList<Clause>();
-        boolean gbyAfterOrderby = false;
-        for (Clause cl : clauseList) {
-            if (cl.getClauseType() == ClauseType.ORDER_BY_CLAUSE) {
-                redundantOrderbys.add(cl);
-            }
-            if (cl.getClauseType() == ClauseType.GROUP_BY_CLAUSE) {
-                gbyAfterOrderby = true;
-                break;
-            }
-        }
-        if (gbyAfterOrderby) {
-            clauseList.removeAll(redundantOrderbys);
-        }
-
-        redundantOrderbys.clear();
-        for (Clause cl : clauseList) {
-            if (cl.getClauseType() == ClauseType.ORDER_BY_CLAUSE) {
-                redundantOrderbys.add(cl);
-            }
-        }
-        if (redundantOrderbys.size() > 0) {
-            redundantOrderbys.remove(redundantOrderbys.size() - 1);
-        }
-        clauseList.removeAll(redundantOrderbys);
-    }
-
-    // Processes leading "let"s in a FLWOGR.
-    private void processLeadingLetClauses(Integer step, List<Clause> clauseList) throws CompilationException {
-        List<Clause> processedLetList = new ArrayList<Clause>();
-        boolean firstLet = true;
-        int size = clauseList.size();
-        for (int i = 0; i < size; ++i) {
-            Clause cl = clauseList.get(i);
-            if (cl.getClauseType() != ClauseType.LET_CLAUSE) {
-                break;
-            }
-            boolean hasConsequentLet = false;
-            if (i < size - 1) {
-                Clause nextCl = clauseList.get(i + 1);
-                hasConsequentLet = nextCl.getClauseType() == ClauseType.LET_CLAUSE;
-            }
-            visitLetClause((LetClause) cl, step, firstLet, hasConsequentLet);
-            firstLet = false;
-            processedLetList.add(cl);
-        }
-        clauseList.removeAll(processedLetList);
-    }
-
-    // Extracts all clauses that led by a "for" clause after the first group-by
-    // clause in the input clause list.
-    // Those extracted clauses will be removed from the input clause list.
-    /**
-     * @param clauseList
-     *            , a list of clauses
-     * @return the cutting group-by clause and the list of extracted clauses.
-     * @throws CompilationException
-     */
-    private Pair<GroupbyClause, List<Clause>> extractUnnestAfterGroupby(List<Clause> clauseList)
-            throws CompilationException {
-        List<Clause> nestedClauses = new ArrayList<Clause>();
-        GroupbyClause cuttingGbyClause = null;
-        boolean meetGroupBy = false;
-        boolean nestedClauseStarted = false;
-        for (Clause cl : clauseList) {
-            if (cl.getClauseType() == ClauseType.GROUP_BY_CLAUSE) {
-                meetGroupBy = true;
-                cuttingGbyClause = (GroupbyClause) cl;
-                continue;
-            }
-            if (meetGroupBy && cl.getClauseType() == ClauseType.FOR_CLAUSE) {
-                nestedClauseStarted = true;
-            }
-            if (nestedClauseStarted) {
-                nestedClauses.add(cl);
-            }
-        }
-        clauseList.removeAll(nestedClauses);
-        return new Pair<GroupbyClause, List<Clause>>(cuttingGbyClause, nestedClauses);
-    }
-
-    // Extracts the variables to be substituted with a path access.
-    private Map<VariableExpr, Expression> extractDefinedCollectionVariables(List<Clause> clauses,
-            GroupbyClause cuttingGbyClause, String generatedAlias) {
-        Map<VariableExpr, Expression> varExprMap = new HashMap<VariableExpr, Expression>();
-        List<VariableExpr> varToSubstitute = collectProducedVariablesFromGroupby(cuttingGbyClause);
-        int gbyIndex = clauses.indexOf(cuttingGbyClause);
-        for (int i = gbyIndex + 1; i < clauses.size(); i++) {
-            Clause cl = clauses.get(i);
-            if (cl.getClauseType() == ClauseType.LET_CLAUSE) {
-                varToSubstitute.add(((LetClause) cl).getVarExpr());
-            }
-        }
-        for (VariableExpr var : varToSubstitute) {
-            varExprMap.put(var, new FieldAccessor(new VariableExpr(new VarIdentifier(generatedAlias)),
-                    new VarIdentifier(var.getVar().getValue().substring(1))));
-        }
-        return varExprMap;
-    }
-
-    // Extracts the variables to be substituted.
-    private Map<VariableExpr, Expression> extractLetBindingVariables(List<Clause> clauses,
-            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++) {
-            Clause cl = clauses.get(i);
-            if (cl.getClauseType() == ClauseType.LET_CLAUSE) {
-                LetClause letClause = (LetClause) cl;
-                // inline let variables one by one iteratively.
-                letClause.setBindingExpr((Expression) AQLVariableSubstitutionUtil
-                        .substituteVariable(letClause.getBindingExpr(), varExprMap));
-                varExprMap.put(letClause.getVarExpr(), letClause.getBindingExpr());
-            }
-        }
-        return varExprMap;
-    }
-
-    // Re-order clauses.
-    private List<Clause> reorder(List<Clause> clauses) {
-        Comparator<Clause> comparator = new ClauseComparator();
-        List<Clause> results = new ArrayList<Clause>();
-        int size = clauses.size();
-        int start = 0;
-        for (int index = 0; index < size; ++index) {
-            Clause clause = clauses.get(index);
-            if (clause.getClauseType() == ClauseType.GROUP_BY_CLAUSE) {
-                List<Clause> subList = clauses.subList(start, index);
-                Collections.sort(subList, comparator);
-                results.addAll(subList);
-                results.add(clause);
-                start = index + 1;
-            }
-        }
-        if (start < clauses.size()) {
-            List<Clause> subList = clauses.subList(start, size);
-            Collections.sort(subList, comparator);
-            results.addAll(subList);
-        }
-        return results;
-    }
-
-    // Merge consecutive "where" clauses.
-    private void mergeConsecutiveWhereClauses(List<Clause> clauses) throws CompilationException {
-        List<Clause> results = new ArrayList<Clause>();
-        int size = clauses.size();
-        for (int index = 0; index < size;) {
-            Clause clause = clauses.get(index);
-            if (clause.getClauseType() != ClauseType.WHERE_CLAUSE) {
-                results.add(clause);
-                ++index;
-            } else {
-                List<Expression> expressions = new ArrayList<Expression>();
-                Clause firstWhereClause = clause;
-                do {
-                    WhereClause whereClause = (WhereClause) clause;
-                    expressions.add(whereClause.getWhereExpr());
-                    if (++index >= size) {
-                        break;
-                    }
-                    clause = clauses.get(index);
-                } while (clause.getClauseType() == ClauseType.WHERE_CLAUSE);
-                if (expressions.size() > 1) {
-                    OperatorExpr newWhereExpr = new OperatorExpr();
-                    newWhereExpr.setExprList(expressions);
-                    newWhereExpr.setCurrentop(true);
-                    for (int operatorIndex = 0; operatorIndex < expressions.size(); ++operatorIndex) {
-                        newWhereExpr.addOperator(OperatorType.AND);
-                    }
-                    results.add(new WhereClause(newWhereExpr));
-                } else {
-                    results.add(firstWhereClause);
-                }
-            }
-        }
-        clauses.clear();
-        clauses.addAll(results);
-    }
-
-    // Where there is a distinct clause.
-    protected boolean hasDistinct(List<Clause> clauses) {
-        for (Clause clause : clauses) {
-            if (clause.getClauseType() == ClauseType.DISTINCT_BY_CLAUSE) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    // Whether the list of clauses contains a for clause.
-    private boolean hasFor(List<Clause> clauses) {
-        for (Clause cl : clauses) {
-            if (cl.getClauseType() == ClauseType.FOR_CLAUSE) {
-                return true;
-            }
-        }
-        return false;
-    }
-}
-
-/**
- * This comparator is used to safely mutate the order of clauses in a FLWOGR
- * expression. Note: clauses before and after a group-by cannot be re-aligned.
- */
-class ClauseComparator implements Comparator<Clause> {
-
-    @Override
-    public int compare(Clause left, Clause right) {
-        int ordinalLeft = left.getClauseType().ordinal();
-        int ordinalRight = right.getClauseType().ordinal();
-        return ordinalLeft > ordinalRight ? 1 : (ordinalLeft == ordinalRight ? 0 : -1);
-    }
-}
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AqlStatementRewriteVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AqlStatementRewriteVisitor.java
deleted file mode 100644
index f6a4905..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/AqlStatementRewriteVisitor.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.asterix.common.functions.FunctionSignature;
-import org.apache.asterix.common.metadata.DataverseName;
-import org.apache.asterix.lang.aql.clause.ForClause;
-import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
-import org.apache.asterix.lang.aql.visitor.base.AbstractAqlAstVisitor;
-import org.apache.asterix.lang.common.base.Clause;
-import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.clause.WhereClause;
-import org.apache.asterix.lang.common.expression.CallExpr;
-import org.apache.asterix.lang.common.expression.LiteralExpr;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.literal.StringLiteral;
-import org.apache.asterix.lang.common.statement.DeleteStatement;
-import org.apache.asterix.lang.common.statement.Query;
-import org.apache.asterix.metadata.declared.MetadataProvider;
-import org.apache.asterix.om.functions.BuiltinFunctions;
-
-public class AqlStatementRewriteVisitor extends AbstractAqlAstVisitor<Void, MetadataProvider> {
-
-    public static final AqlStatementRewriteVisitor INSTANCE = new AqlStatementRewriteVisitor();
-
-    private AqlStatementRewriteVisitor() {
-    }
-
-    @Override
-    public Void visit(DeleteStatement deleteStmt, MetadataProvider metadataProvider) {
-        List<Expression> arguments = new ArrayList<>();
-        DataverseName dataverseName = deleteStmt.getDataverseName();
-        if (dataverseName == null) {
-            dataverseName = metadataProvider.getDefaultDataverseName();
-        }
-        String datasetName = deleteStmt.getDatasetName();
-        arguments.add(new LiteralExpr(new StringLiteral(dataverseName.getCanonicalForm())));
-        arguments.add(new LiteralExpr(new StringLiteral(datasetName)));
-        CallExpr callExpression = new CallExpr(new FunctionSignature(BuiltinFunctions.DATASET), arguments);
-
-        List<Clause> clauseList = new ArrayList<>();
-        VariableExpr var = deleteStmt.getVariableExpr();
-        Clause forClause = new ForClause(var, callExpression);
-        clauseList.add(forClause);
-        Clause whereClause = null;
-        Expression condition = deleteStmt.getCondition();
-        if (condition != null) {
-            whereClause = new WhereClause(condition);
-            clauseList.add(whereClause);
-        }
-        VariableExpr returnExpr = new VariableExpr(var.getVar());
-        returnExpr.setIsNewVar(false);
-        FLWOGRExpression flowgr = new FLWOGRExpression(clauseList, returnExpr);
-        Query query = new Query(false);
-        query.setBody(flowgr);
-        deleteStmt.setQuery(query);
-        return null;
-    }
-
-}
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
deleted file mode 100644
index 3b9ed7f..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlAstVisitor.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor.base;
-
-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;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-import org.apache.asterix.lang.common.expression.ListSliceExpression;
-import org.apache.asterix.lang.common.visitor.base.AbstractAstVisitor;
-
-public abstract class AbstractAqlAstVisitor<R, T> extends AbstractAstVisitor<R, T> implements IAQLVisitor<R, T> {
-
-    @Override
-    public R visit(FLWOGRExpression flwogreExpr, T arg) throws CompilationException {
-        return null;
-    }
-
-    @Override
-    public R visit(UnionExpr u, T arg) throws CompilationException {
-        return null;
-    }
-
-    @Override
-    public R visit(ForClause forClause, T arg) throws CompilationException {
-        return null;
-    }
-
-    @Override
-    public R visit(DistinctClause distinctClause, T arg) throws CompilationException {
-        return null;
-    }
-
-    @Override
-    public R visit(ListSliceExpression expression, T arg) throws CompilationException {
-        return null;
-    }
-}
diff --git a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlQueryExpressionVisitor.java b/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlQueryExpressionVisitor.java
deleted file mode 100644
index 977c3b1..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlQueryExpressionVisitor.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor.base;
-
-import org.apache.asterix.lang.common.visitor.base.AbstractQueryExpressionVisitor;
-
-public abstract class AbstractAqlQueryExpressionVisitor<R, T> extends AbstractQueryExpressionVisitor<R, T>
-        implements IAQLVisitor<R, T> {
-
-}
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
deleted file mode 100644
index e23eec9..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/AbstractAqlSimpleExpressionVisitor.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.asterix.lang.aql.visitor.base;
-
-import java.util.ArrayList;
-import java.util.List;
-
-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;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-import org.apache.asterix.lang.common.base.Clause;
-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.clause.LetClause;
-import org.apache.asterix.lang.common.clause.LimitClause;
-import org.apache.asterix.lang.common.clause.OrderbyClause;
-import org.apache.asterix.lang.common.clause.WhereClause;
-import org.apache.asterix.lang.common.expression.CallExpr;
-import org.apache.asterix.lang.common.expression.FieldAccessor;
-import org.apache.asterix.lang.common.expression.FieldBinding;
-import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
-import org.apache.asterix.lang.common.expression.IfExpr;
-import org.apache.asterix.lang.common.expression.IndexAccessor;
-import org.apache.asterix.lang.common.expression.ListConstructor;
-import org.apache.asterix.lang.common.expression.ListSliceExpression;
-import org.apache.asterix.lang.common.expression.LiteralExpr;
-import org.apache.asterix.lang.common.expression.OperatorExpr;
-import org.apache.asterix.lang.common.expression.QuantifiedExpression;
-import org.apache.asterix.lang.common.expression.RecordConstructor;
-import org.apache.asterix.lang.common.expression.UnaryExpr;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.statement.FunctionDecl;
-import org.apache.asterix.lang.common.statement.InsertStatement;
-import org.apache.asterix.lang.common.statement.Query;
-import org.apache.asterix.lang.common.struct.QuantifiedPair;
-
-public class AbstractAqlSimpleExpressionVisitor extends AbstractAqlQueryExpressionVisitor<Expression, ILangExpression> {
-
-    @Override
-    public Expression visit(FLWOGRExpression flwogreExpr, ILangExpression arg) throws CompilationException {
-        for (Clause clause : flwogreExpr.getClauseList()) {
-            clause.accept(this, arg);
-        }
-        flwogreExpr.setReturnExpr(flwogreExpr.getReturnExpr().accept(this, arg));
-        return flwogreExpr;
-    }
-
-    @Override
-    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 CompilationException {
-        forClause.setInExpr(forClause.getInExpr().accept(this, arg));
-        return null;
-    }
-
-    @Override
-    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 CompilationException {
-        q.setBody(visit(q.getBody(), q));
-        return null;
-    }
-
-    @Override
-    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 CompilationException {
-        whereClause.setWhereExpr(visit(whereClause.getWhereExpr(), whereClause));
-        return null;
-    }
-
-    @Override
-    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 CompilationException {
-        for (List<GbyVariableExpressionPair> gbyPairList : gc.getGbyPairList()) {
-            for (GbyVariableExpressionPair gbyVarExpr : gbyPairList) {
-                gbyVarExpr.setExpr(visit(gbyVarExpr.getExpr(), gc));
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public Expression visit(LimitClause limitClause, ILangExpression arg) throws CompilationException {
-        limitClause.setLimitExpr(visit(limitClause.getLimitExpr(), limitClause));
-        if (limitClause.hasOffset()) {
-            limitClause.setOffset(visit(limitClause.getOffset(), limitClause));
-        }
-        return null;
-    }
-
-    @Override
-    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 CompilationException {
-        return l;
-    }
-
-    @Override
-    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 CompilationException {
-        for (FieldBinding binding : rc.getFbList()) {
-            binding.setLeftExpr(visit(binding.getLeftExpr(), rc));
-            binding.setRightExpr(visit(binding.getRightExpr(), rc));
-        }
-        return rc;
-    }
-
-    @Override
-    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 CompilationException {
-        ifExpr.setCondExpr(visit(ifExpr.getCondExpr(), ifExpr));
-        ifExpr.setThenExpr(visit(ifExpr.getThenExpr(), ifExpr));
-        ifExpr.setElseExpr(visit(ifExpr.getElseExpr(), ifExpr));
-        return ifExpr;
-    }
-
-    @Override
-    public Expression visit(QuantifiedExpression qe, ILangExpression arg) throws CompilationException {
-        for (QuantifiedPair pair : qe.getQuantifiedList()) {
-            pair.setExpr(visit(pair.getExpr(), qe));
-        }
-        qe.setSatisfiesExpr(visit(qe.getSatisfiesExpr(), qe));
-        return qe;
-    }
-
-    @Override
-    public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
-        callExpr.setExprList(visit(callExpr.getExprList(), arg));
-        if (callExpr.hasAggregateFilterExpr()) {
-            callExpr.setAggregateFilterExpr(visit(callExpr.getAggregateFilterExpr(), arg));
-        }
-        return callExpr;
-    }
-
-    @Override
-    public Expression visit(VariableExpr varExpr, ILangExpression arg) throws CompilationException {
-        return varExpr;
-    }
-
-    @Override
-    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 CompilationException {
-        fa.setExpr(visit(fa.getExpr(), fa));
-        return fa;
-    }
-
-    @Override
-    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));
-        }
-        return ia;
-    }
-
-    @Override
-    public Expression visit(ListSliceExpression expression, ILangExpression arg) throws CompilationException {
-        // This functionality is not supported for AQL
-        return null;
-    }
-
-    @Override
-    public Expression visit(InsertStatement insertStatement, ILangExpression arg) throws CompilationException {
-        Expression returnExpr = insertStatement.getReturnExpression();
-        if (returnExpr != null) {
-            insertStatement.setReturnExpression(visit(returnExpr, arg));
-        }
-        Query bodyQuery = insertStatement.getQuery();
-        bodyQuery.accept(this, arg);
-        return null;
-    }
-
-    protected Expression visit(Expression expr, ILangExpression arg) throws CompilationException {
-        return postVisit(preVisit(expr).accept(this, arg));
-    }
-
-    protected Expression preVisit(Expression expr) throws CompilationException {
-        return expr;
-    }
-
-    protected Expression postVisit(Expression expr) throws CompilationException {
-        return expr;
-    }
-
-    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));
-        }
-        return newExprList;
-    }
-}
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
deleted file mode 100644
index 303f47b..0000000
--- a/asterixdb/asterix-lang-aql/src/main/java/org/apache/asterix/lang/aql/visitor/base/IAQLVisitor.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.lang.aql.visitor.base;
-
-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;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
-
-public interface IAQLVisitor<R, T> extends ILangVisitor<R, T> {
-
-    R visit(FLWOGRExpression flwogreExpr, T arg) throws CompilationException;
-
-    R visit(UnionExpr u, T arg) throws CompilationException;
-
-    R visit(ForClause forClause, T arg) throws CompilationException;
-
-    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
deleted file mode 100644
index e00e175..0000000
--- a/asterixdb/asterix-lang-aql/src/main/javacc/AQL.jj
+++ /dev/null
@@ -1,2980 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-options {
-
-
-       STATIC = false;
-
-}
-
-
-PARSER_BEGIN(AQLParser)
-
-package org.apache.asterix.lang.aql.parser;
-
-// For AQLParserTokenManager
-import java.util.ArrayDeque;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.asterix.common.annotations.AutoDataGen;
-import org.apache.asterix.common.annotations.DateBetweenYearsDataGen;
-import org.apache.asterix.common.annotations.DatetimeAddRandHoursDataGen;
-import org.apache.asterix.common.annotations.DatetimeBetweenYearsDataGen;
-import org.apache.asterix.common.annotations.FieldIntervalDataGen;
-import org.apache.asterix.common.annotations.FieldValFileDataGen;
-import org.apache.asterix.common.annotations.FieldValFileSameIndexDataGen;
-import org.apache.asterix.common.annotations.IRecordFieldDataGen;
-import org.apache.asterix.common.annotations.InsertRandIntDataGen;
-import org.apache.asterix.common.annotations.ListDataGen;
-import org.apache.asterix.common.annotations.ListValFileDataGen;
-import org.apache.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
-import org.apache.asterix.common.annotations.TypeDataGen;
-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.CompilationException;
-import org.apache.asterix.common.functions.FunctionSignature;
-import org.apache.asterix.common.metadata.DataverseName;
-import org.apache.asterix.lang.aql.clause.DistinctClause;
-import org.apache.asterix.lang.aql.clause.ForClause;
-import org.apache.asterix.lang.aql.expression.FLWOGRExpression;
-import org.apache.asterix.lang.aql.expression.UnionExpr;
-import org.apache.asterix.lang.aql.util.AQLFormatPrintUtil;
-import org.apache.asterix.lang.common.base.Clause;
-import org.apache.asterix.lang.common.base.Expression;
-import org.apache.asterix.lang.common.base.ILangExpression;
-import org.apache.asterix.lang.common.base.IParser;
-import org.apache.asterix.lang.common.base.IParserFactory;
-import org.apache.asterix.lang.common.base.Literal;
-import org.apache.asterix.lang.common.base.Statement;
-import org.apache.asterix.lang.common.clause.GroupbyClause;
-import org.apache.asterix.lang.common.clause.LetClause;
-import org.apache.asterix.lang.common.clause.LimitClause;
-import org.apache.asterix.lang.common.clause.OrderbyClause;
-import org.apache.asterix.lang.common.clause.UpdateClause;
-import org.apache.asterix.lang.common.clause.WhereClause;
-import org.apache.asterix.lang.common.context.RootScopeFactory;
-import org.apache.asterix.lang.common.context.Scope;
-import org.apache.asterix.lang.common.expression.AbstractAccessor;
-import org.apache.asterix.lang.common.expression.CallExpr;
-import org.apache.asterix.lang.common.expression.FieldAccessor;
-import org.apache.asterix.lang.common.expression.FieldBinding;
-import org.apache.asterix.lang.common.expression.GbyVariableExpressionPair;
-import org.apache.asterix.lang.common.expression.IfExpr;
-import org.apache.asterix.lang.common.expression.IndexAccessor;
-import org.apache.asterix.lang.common.expression.IndexedTypeExpression;
-import org.apache.asterix.lang.common.expression.ListConstructor;
-import org.apache.asterix.lang.common.expression.LiteralExpr;
-import org.apache.asterix.lang.common.expression.OperatorExpr;
-import org.apache.asterix.lang.common.expression.OrderedListTypeDefinition;
-import org.apache.asterix.lang.common.expression.QuantifiedExpression;
-import org.apache.asterix.lang.common.expression.RecordConstructor;
-import org.apache.asterix.lang.common.expression.RecordTypeDefinition;
-import org.apache.asterix.lang.common.expression.TypeExpression;
-import org.apache.asterix.lang.common.expression.TypeReferenceExpression;
-import org.apache.asterix.lang.common.expression.UnaryExpr;
-import org.apache.asterix.lang.common.expression.UnorderedListTypeDefinition;
-import org.apache.asterix.lang.common.expression.VariableExpr;
-import org.apache.asterix.lang.common.literal.DoubleLiteral;
-import org.apache.asterix.lang.common.literal.FalseLiteral;
-import org.apache.asterix.lang.common.literal.FloatLiteral;
-import org.apache.asterix.lang.common.literal.LongIntegerLiteral;
-import org.apache.asterix.lang.common.literal.MissingLiteral;
-import org.apache.asterix.lang.common.literal.NullLiteral;
-import org.apache.asterix.lang.common.literal.StringLiteral;
-import org.apache.asterix.lang.common.literal.TrueLiteral;
-import org.apache.asterix.lang.common.parser.ScopeChecker;
-import org.apache.asterix.lang.common.statement.CompactStatement;
-import org.apache.asterix.lang.common.statement.ConnectFeedStatement;
-import org.apache.asterix.lang.common.statement.CreateDataverseStatement;
-import org.apache.asterix.lang.common.statement.CreateFeedPolicyStatement;
-import org.apache.asterix.lang.common.statement.CreateFeedStatement;
-import org.apache.asterix.lang.common.statement.StartFeedStatement;
-import org.apache.asterix.lang.common.statement.StopFeedStatement;
-import org.apache.asterix.lang.common.statement.CreateFunctionStatement;
-import org.apache.asterix.lang.common.statement.CreateIndexStatement;
-import org.apache.asterix.lang.common.statement.DatasetDecl;
-import org.apache.asterix.lang.common.statement.DataverseDecl;
-import org.apache.asterix.lang.common.statement.DataverseDropStatement;
-import org.apache.asterix.lang.common.statement.DeleteStatement;
-import org.apache.asterix.lang.common.statement.DisconnectFeedStatement;
-import org.apache.asterix.lang.common.statement.DropDatasetStatement;
-import org.apache.asterix.lang.common.statement.ExternalDetailsDecl;
-import org.apache.asterix.lang.common.statement.FeedDropStatement;
-import org.apache.asterix.lang.common.statement.FeedPolicyDropStatement;
-import org.apache.asterix.lang.common.statement.FunctionDecl;
-import org.apache.asterix.lang.common.statement.FunctionDropStatement;
-import org.apache.asterix.lang.common.statement.IndexDropStatement;
-import org.apache.asterix.lang.common.statement.InsertStatement;
-import org.apache.asterix.lang.common.statement.InternalDetailsDecl;
-import org.apache.asterix.lang.common.statement.LoadStatement;
-import org.apache.asterix.lang.common.statement.NodeGroupDropStatement;
-import org.apache.asterix.lang.common.statement.NodegroupDecl;
-import org.apache.asterix.lang.common.statement.Query;
-import org.apache.asterix.lang.common.statement.RefreshExternalDatasetStatement;
-import org.apache.asterix.lang.common.statement.SetStatement;
-import org.apache.asterix.lang.common.statement.TypeDecl;
-import org.apache.asterix.lang.common.statement.TypeDropStatement;
-import org.apache.asterix.lang.common.statement.UpdateStatement;
-import org.apache.asterix.lang.common.statement.UpsertStatement;
-import org.apache.asterix.lang.common.statement.WriteStatement;
-import org.apache.asterix.lang.common.struct.Identifier;
-import org.apache.asterix.lang.common.struct.OperatorType;
-import org.apache.asterix.lang.common.struct.QuantifiedPair;
-import org.apache.asterix.lang.common.struct.VarIdentifier;
-import org.apache.asterix.lang.common.util.RangeMapBuilder;
-import org.apache.asterix.metadata.utils.MetadataConstants;
-import org.apache.asterix.om.types.BuiltinType;
-import org.apache.hyracks.algebricks.common.utils.Pair;
-import org.apache.hyracks.algebricks.common.utils.Triple;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation;
-import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
-import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
-import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-
-
-class AQLParser extends ScopeChecker implements IParser {
-
-    // optimizer hints
-    private static final String AUTO_HINT = "auto";
-    private static final String HASH_BROADCAST_JOIN_HINT = "hash-bcast";
-    private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
-    private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
-    private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
-    private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
-    private static final String HASH_GROUP_BY_HINT = "hash";
-    private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
-    private static final String INMEMORY_HINT = "inmem";
-    private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
-    private static final String INTERVAL_HINT = "interval";
-    private static final String LIST_HINT = "list";
-    private static final String LIST_VAL_FILE_HINT = "list-val-file";
-    private static final String RANGE_HINT = "range";
-    private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
-    private static final String VAL_FILE_HINT = "val-files";
-    private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
-    private static final String GEN_FIELDS_HINT = "gen-fields";
-    // data generator hints
-    private static final String DGEN_HINT = "dgen";
-
-    private static final String INT_TYPE_NAME = "int";
-
-    private static final char VAR_PREFIX = '$';
-
-    private DataverseName defaultDataverse;
-
-    private static class IndexParams {
-      public IndexType type;
-      public int gramLength;
-
-      public IndexParams(IndexType type, int gramLength) {
-        this.type = type;
-        this.gramLength = gramLength;
-      }
-    };
-
-    private static class FunctionName {
-       public DataverseName dataverse = null;
-       public String library = null;
-       public String function = null;
-       public String hint = null;
-    }
-
-    private static String getHint(Token t) {
-        if (t.specialToken == null) {
-            return null;
-        }
-        String s = t.specialToken.image;
-        int n = s.length();
-        if (n < 2) {
-            return null;
-        }
-        return s.substring(1).trim();
-    }
-
-    private static void checkBindingVariable(Expression returnExpression, VariableExpr var,
-                                             ILangExpression bodyExpression) throws ParseException {
-       if (returnExpression != null && var == null) {
-         try {
-           throw new ParseException("Need a binding variable for the enclosed expression: " +
-                                       AQLFormatPrintUtil.toString(bodyExpression));
-         } catch (CompilationException e){
-           throw new ParseException(e.getLocalizedMessage());
-         }
-       }
-    }
-
-    private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
-      IRecordFieldDataGen rfdg = null;
-      String splits[] = hint.split(" +");
-      if (splits[0].equals(VAL_FILE_HINT)) {
-        File[] valFiles = new File[splits.length - 1];
-        for (int k=1; k<splits.length; k++) {
-          valFiles[k-1] = new File(splits[k]);
-        }
-        rfdg = new FieldValFileDataGen(valFiles);
-      } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
-        rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
-      } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
-        rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
-      } else if (splits[0].equals(LIST_HINT)) {
-        rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
-      } else if (splits[0].equals(INTERVAL_HINT)) {
-        FieldIntervalDataGen.ValueType vt;
-        if (splits[1].equals("int")) {
-          vt = FieldIntervalDataGen.ValueType.INT;
-        } else if (splits[1].equals("long")) {
-          vt = FieldIntervalDataGen.ValueType.LONG;
-        } else if (splits[1].equals("float")) {
-          vt = FieldIntervalDataGen.ValueType.FLOAT;
-        } else if (splits[1].equals("double")) {
-          vt = FieldIntervalDataGen.ValueType.DOUBLE;
-        } else {
-          throw new ParseException("Unknown type for interval data gen: " + splits[1]);
-        }
-        rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
-      } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
-        rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
-      } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
-        rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
-      } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
-        rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
-      } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
-        rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
-      } else if (splits[0].equals(AUTO_HINT)) {
-        rfdg = new AutoDataGen(splits[1]);
-      }
-      return rfdg;
-    }
-
-    public AQLParser(String s){
-        this(new StringReader(s));
-        super.setInput(s);
-    }
-
-    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);
-        List<Statement> st = parser.parse();
-        //st.accept(new AQLPrintVisitor(), 0);
-    }
-
-    @Override
-    public List<Statement> parse() throws CompilationException {
-        return parseImpl(new ParseFunction<List<Statement>>() {
-            @Override
-            public List<Statement> parse() throws ParseException {
-                return AQLParser.this.Statement();
-            }
-        });
-    }
-
-    @Override
-    public Expression parseExpression() throws CompilationException {
-        return parseImpl(new ParseFunction<Expression>() {
-            @Override
-            public Expression parse() throws ParseException {
-                return AQLParser.this.Expression();
-            }
-        });
-    }
-
-    private static Expression parseExpression(String text) throws CompilationException {
-        return new AQLParser(text).parseExpression();
-    }
-
-    @Override
-    public FunctionDecl parseFunctionBody(FunctionSignature signature, List<String> paramNames)
-      throws CompilationException {
-        return parseImpl(new ParseFunction<FunctionDecl>() {
-            @Override
-            public FunctionDecl parse() throws ParseException {
-                DataverseName dataverse = defaultDataverse;
-                defaultDataverse = signature.getDataverseName();
-                createNewScope();
-                List<VarIdentifier> paramVars = new ArrayList<VarIdentifier>(paramNames.size());
-                for (String paramName : paramNames) {
-                    VarIdentifier var = new VarIdentifier(VAR_PREFIX + paramName);
-                    paramVars.add(var);
-                    getCurrentScope().addNewVarSymbolToScope(var);
-                }
-                Expression functionBodyExpr = AQLParser.this.FunctionBody();
-                removeCurrentScope();
-                defaultDataverse = dataverse;
-                return new FunctionDecl(signature, paramVars, functionBodyExpr);
-            }
-        });
-    }
-
-    private <T> T parseImpl(ParseFunction<T> parseFunction) throws CompilationException {
-        try {
-            return parseFunction.parse();
-        } 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 CompilationException(new ParseException(e.getMessage()));
-        } catch (ParseException e){
-            throw new CompilationException(e.getMessage());
-        }
-    }
-
-    @FunctionalInterface
-    private interface ParseFunction<T> {
-        T parse() throws ParseException;
-    }
-}
-
-PARSER_END(AQLParser)
-
-
-List<Statement> Statement() throws ParseException:
-{
-  scopeStack.push(RootScopeFactory.createRootScope(this));
-  List<Statement> decls = new ArrayList<Statement>();
-  Statement stmt = null;
-}
-{
-  ( stmt = SingleStatement() (";") ?
-    {
-      decls.add(stmt);
-    }
-  )*
-  (";") *
-  <EOF>
-  {
-    return decls;
-  }
-}
-
-Statement SingleStatement() throws ParseException:
-{
-  Statement stmt = null;
-}
-{
-  (
-    stmt = DataverseDeclaration()
-    | stmt = FunctionDeclaration()
-    | stmt = CreateStatement()
-    | stmt = LoadStatement()
-    | stmt = DropStatement()
-    | stmt = WriteStatement()
-    | stmt = SetStatement()
-    | stmt = InsertStatement()
-    | stmt = UpsertStatement()
-    | stmt = DeleteStatement()
-    | stmt = UpdateStatement()
-    | stmt = FeedStatement()
-    | stmt = CompactStatement()
-    | stmt = Query()
-    | stmt = RefreshExternalDatasetStatement()
-  )
-  {
-    return stmt;
-  }
-}
-
-DataverseDecl DataverseDeclaration() throws ParseException:
-{
-  String dvName = null;
-}
-{
-  <USE> <DATAVERSE> dvName = Identifier()
-    {
-      defaultDataverse = DataverseName.createSinglePartName(dvName);
-      return new DataverseDecl(defaultDataverse);
-    }
-}
-
-Statement CreateStatement() throws ParseException:
-{
-  String hint = null;
-  boolean dgen = false;
-  Statement stmt = null;
-}
-{
-  <CREATE>
-  (
-    {
-      hint = getHint(token);
-      if (hint != null && hint.startsWith(DGEN_HINT)) {
-        dgen = true;
-      }
-    }
-    stmt = TypeSpecification(hint, dgen)
-    | stmt = NodegroupSpecification()
-    | stmt = DatasetSpecification()
-    | stmt = IndexSpecification()
-    | stmt = DataverseSpecification()
-    | stmt = FunctionSpecification()
-    | stmt = FeedSpecification()
-    | stmt = FeedPolicySpecification()
-  )
-  {
-    return stmt;
-  }
-}
-
-TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
-{
-  Pair<DataverseName,Identifier> nameComponents = null;
-  boolean ifNotExists = false;
-  TypeExpression typeExpr = null;
-}
-{
-  <TYPE> nameComponents = TypeName() ifNotExists = IfNotExists()
-  <AS> typeExpr = TypeExpr()
-    {
-      long numValues = -1;
-      String filename = null;
-      if (dgen) {
-        String splits[] = hint.split(" +");
-        if (splits.length != 3) {
-          throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
-        }
-        filename = splits[1];
-        numValues = Long.parseLong(splits[2]);
-      }
-      TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
-      return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
-    }
-}
-
-
-NodegroupDecl NodegroupSpecification() throws ParseException:
-{
-  String name = null;
-  String tmp = null;
-  boolean ifNotExists = false;
-  List<Identifier>ncNames = null;
-}
-{
-  <NODEGROUP> name = Identifier()
-  ifNotExists = IfNotExists() <ON> tmp = Identifier()
-    {
-      ncNames = new ArrayList<Identifier>();
-      ncNames.add(new Identifier(tmp));
-    }
-  ( <COMMA> tmp = Identifier()
-    {
-      ncNames.add(new Identifier(tmp));
-    }
-  )*
-    {
-      return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
-    }
-}
-
-DatasetDecl DatasetSpecification() throws ParseException:
-{
-  Pair<DataverseName,Identifier> nameComponents = null;
-  boolean ifNotExists = false;
-  Pair<DataverseName,Identifier> typeComponents = null;
-  Pair<DataverseName,Identifier> metaTypeComponents = null;
-  String adapterName = null;
-  Map<String,String> properties = null;
-  FunctionSignature appliedFunction = null;
-  Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
-  Map<String,String> hints = new HashMap<String,String>();
-  DatasetDecl dsetDecl = null;
-  boolean autogenerated = false;
-  Pair<Integer, List<String>> filterField = null;
-  RecordConstructor withRecord = null;
-}
-{
-  (
-    <EXTERNAL> <DATASET> nameComponents = QualifiedName()
-    <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
-    ifNotExists = IfNotExists()
-    <USING> adapterName = AdapterName() properties = Configuration()
-    ( <HINTS> hints = Properties() )?
-    ( <WITH> withRecord = RecordConstructor() )?
-      {
-        ExternalDetailsDecl edd = new ExternalDetailsDecl();
-        edd.setAdapter(adapterName);
-        edd.setProperties(properties);
-        try{
-            dsetDecl = new DatasetDecl(nameComponents.first,
-              nameComponents.second,
-              new TypeReferenceExpression(typeComponents),
-              null,
-              hints,
-              DatasetType.EXTERNAL,
-              edd,
-              withRecord,
-              ifNotExists);
-       } catch (CompilationException e){
-           throw new ParseException(e.getMessage());
-       }
-      }
-
-    | ( <INTERNAL> )?
-    <DATASET> nameComponents = QualifiedName()
-    <LEFTPAREN> typeComponents = TypeName() <RIGHTPAREN>
-    (
-        { String name; }
-        <WITH>
-        name = Identifier()
-        {
-            if(!name.equals("meta")){
-                throw new ParseException("We can only support one additional associated field called \"meta\".");
-            }
-        }
-        <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
-    )?
-    ifNotExists = IfNotExists()
-    primaryKeyFields = PrimaryKey()
-    ( <AUTOGENERATED> { autogenerated = true; } )?
-    ( <HINTS> hints = Properties() )?
-    ( LOOKAHEAD(2) <WITH> <FILTER> <ON> filterField = NestedField() )?
-    ( <WITH> withRecord = RecordConstructor() )?
-      {
-        if(filterField!=null && filterField.first!=0){
-          throw new ParseException("A filter field can only be a field in the main record of the dataset.");
-        }
-        try{
-          InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
-                                                          primaryKeyFields.first,
-                                                          autogenerated,
-                                                          filterField == null? null : filterField.first,
-                                                          filterField == null? null : filterField.second);
-          dsetDecl = new DatasetDecl(nameComponents.first,
-                                   nameComponents.second,
-                                   new TypeReferenceExpression(typeComponents),
-                                   metaTypeComponents != null ? new TypeReferenceExpression(metaTypeComponents) : null,
-                                   hints,
-                                   DatasetType.INTERNAL,
-                                   idd,
-                                   withRecord,
-                                   ifNotExists);
-        } catch (CompilationException e){
-           throw new ParseException(e.getMessage());
-        }
-      }
-  )
-    {
-      return dsetDecl;
-    }
-}
-
-RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
-{
-  RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
-  Pair<DataverseName,Identifier> nameComponents = null;
-  String datasetName = null;
-}
-{
-  (
-    <REFRESH> <EXTERNAL> <DATASET> nameComponents = QualifiedName()
-    {
-    redss.setDataverseName(nameComponents.first);
-    redss.setDatasetName(nameComponents.second);
-    return redss;
-    }
-  )
-}
-
-CreateIndexStatement IndexSpecification() throws ParseException:
-{
-  CreateIndexStatement cis = new CreateIndexStatement();
-  String indexName = null;
-  boolean ifNotExists = false;
-  Pair<DataverseName,Identifier> nameComponents = null;
-  Pair<Integer, Pair<List<String>, IndexedTypeExpression>> fieldPair = null;
-  IndexParams indexType = null;
-  boolean enforced = false;
-  boolean isPrimaryIdx = false;
-}
-{
-  (
-    (<INDEX> indexName = Identifier()
-    ifNotExists = IfNotExists()
-    <ON> nameComponents = QualifiedName()
-    <LEFTPAREN> ( fieldPair = OpenField()
-      {
-        cis.addFieldExprPair(fieldPair.second);
-        cis.addFieldIndexIndicator(fieldPair.first);
-      }
-    ) (<COMMA> fieldPair = OpenField()
-      {
-        cis.addFieldExprPair(fieldPair.second);
-        cis.addFieldIndexIndicator(fieldPair.first);
-      }
-    )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
-    |
-    (<PRIMARY> <INDEX> {isPrimaryIdx = true;}
-      (
-        (indexName = Identifier())? ifNotExists = IfNotExists()
-      )
-      <ON> nameComponents = QualifiedName() (<TYPE> <BTREE>)?
-    )
-  )
-  {
-    if (isPrimaryIdx && indexName == null) {
-      indexName = "primary_idx_" + nameComponents.second;
-    }
-    cis.setIndexName(new Identifier(indexName));
-    cis.setIfNotExists(ifNotExists);
-    cis.setDataverseName(nameComponents.first);
-    cis.setDatasetName(nameComponents.second);
-    if (indexType != null) {
-      cis.setIndexType(indexType.type);
-      cis.setGramLength(indexType.gramLength);
-    }
-    cis.setEnforced(enforced);
-    return cis;
-  }
-}
-
-String CompactionPolicy() throws ParseException :
-{
-  String compactionPolicy = null;
-}
-{
-  compactionPolicy = Identifier()
-    {
-      return compactionPolicy;
-    }
-}
-
-String FilterField() throws ParseException :
-{
-  String filterField = null;
-}
-{
-  filterField = Identifier()
-    {
-      return filterField;
-    }
-}
-
-IndexParams IndexType() throws ParseException:
-{
-  IndexType type = null;
-  int gramLength = 0;
-}
-{
-  (
-    <BTREE>
-    {
-      type = IndexType.BTREE;
-    }
-   |<RTREE>
-    {
-      type = IndexType.RTREE;
-    }
-   |<KEYWORD>
-    {
-      type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
-    }
-   |<FULLTEXT>
-    {
-      type = IndexType.SINGLE_PARTITION_WORD_INVIX;
-    }
-   |<NGRAM> <LEFTPAREN> <INTEGER_LITERAL>
-    {
-      type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
-      gramLength = Integer.valueOf(token.image);
-    }
-    <RIGHTPAREN>
-  )
-  {
-    return new IndexParams(type, gramLength);
-  }
-}
-
-CreateDataverseStatement DataverseSpecification() throws ParseException :
-{
-  String dvName = null;
-  boolean ifNotExists = false;
-  String format = null;
-}
-{
-  <DATAVERSE> dvName = Identifier()
-  ifNotExists = IfNotExists()
-  ( <WITH> <FORMAT> format = StringLiteral() )?
-    {
-      return new CreateDataverseStatement(DataverseName.createSinglePartName(dvName), format, ifNotExists);
-    }
-}
-
-CreateFunctionStatement FunctionSpecification() throws ParseException:
-{
-  FunctionSignature signature;
-  boolean ifNotExists = false;
-  List<VarIdentifier> paramList;
-  String functionBody;
-  VarIdentifier var = null;
-  Expression functionBodyExpr;
-  Token beginPos;
-  Token endPos;
-  FunctionName fctName = null;
-  List<Pair<VarIdentifier,TypeExpression>> bodge = new ArrayList<Pair<VarIdentifier,TypeExpression>>();
-  createNewScope();
-}
-{
-  <FUNCTION> fctName = FunctionName()
-  ifNotExists = IfNotExists()
-  paramList = ParameterList()
-  <LEFTBRACE>
-  {
-     beginPos = token;
-  }
-  functionBodyExpr = FunctionBody() <RIGHTBRACE>
-    {
-      endPos = token;
-      functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
-      // TODO use fctName.library
-      signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
-      getCurrentScope().addFunctionDescriptor(signature, false);
-      removeCurrentScope();
-      for(VarIdentifier v: paramList){
-          bodge.add(new Pair<VarIdentifier,TypeExpression>(v,null));
-      }
-      return new CreateFunctionStatement(signature, bodge, functionBody, functionBodyExpr, false, ifNotExists);
-    }
-}
-
-Expression FunctionBody() throws ParseException:
-{
-  Expression functionBodyExpr = null;
-}
-{
-  functionBodyExpr = Expression()
-  {
-    return functionBodyExpr;
-  }
-}
-
-CreateFeedStatement FeedSpecification() throws ParseException:
-{
-  Pair<DataverseName,Identifier> nameComponents = null;
-  boolean ifNotExists = false;
-  CreateFeedStatement cfs = null;
-  RecordConstructor withRecord = null;
-}
-{
-  <FEED> nameComponents = QualifiedName() ifNotExists = IfNotExists()
-  <WITH> withRecord = RecordConstructor()
-    {
-      try {
-        cfs = new CreateFeedStatement(nameComponents, withRecord, ifNotExists);
-        return cfs;
-      } catch (AlgebricksException e) {
-        throw new ParseException(e.getMessage());
-      }
-    }
-}
-
-CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
-{
-  String policyName = null;
-  String basePolicyName = null;
-  String sourcePolicyFile = null;
-  String definition = null;
-  boolean ifNotExists = false;
-  Map<String,String> properties = null;
-  CreateFeedPolicyStatement cfps = null;
-}
-{
-  (
-    <INGESTION> <POLICY>  policyName = Identifier() ifNotExists = IfNotExists()
-    <FROM>
-    (
-      <POLICY> basePolicyName = Identifier() properties = Configuration() ( <DEFINITION> definition = StringLiteral())?
-      {
-        cfps = new CreateFeedPolicyStatement(policyName, basePolicyName, properties, definition, ifNotExists);
-      }
-     |<PATH> sourcePolicyFile = StringLiteral() (<DEFINITION> definition = StringLiteral())?
-      {
-        cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
-      }
-    )
-  )
-  {
-    return cfps;
-  }
-}
-
-
-
-List<VarIdentifier> ParameterList() throws ParseException:
-{
-  List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
-  VarIdentifier var = null;
-}
-{
-  <LEFTPAREN> (<VARIABLE>
-    {
-      var = new VarIdentifier(token.image);
-      paramList.add(var);
-      getCurrentScope().addNewVarSymbolToScope(var);
-    }
-  ( <COMMA> <VARIABLE>
-    {
-      var = new VarIdentifier(token.image);
-      paramList.add(var);
-      getCurrentScope().addNewVarSymbolToScope(var);
-    }
-  )*)? <RIGHTPAREN>
-    {
-      return paramList;
-    }
-}
-
-boolean IfNotExists() throws ParseException:
-{
-}
-{
-  (
-    LOOKAHEAD(1)
-    <IF>
-    <IDENTIFIER>
-    (
-      {
-        if(!token.image.equals("not")){
-           throw new ParseException("Expect word \"not\" at line " + token.beginLine + ", column "
-                         + token.beginColumn +"!");
-        }
-      }
-    )
-    <EXISTS>
-    {
-      return true;
-    }
-  )?
-    {
-      return false;
-    }
-}
-
-void ApplyFunction(List<FunctionSignature> funcSigs) throws ParseException:
-{
-  FunctionName functioName = null;
-  String fqFunctionName = null;
-}
-{
-  <APPLY> <FUNCTION> functioName = FunctionName()
-    {
-       fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
-       funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
-    }
-  (
-    <COMMA> functioName = FunctionName()
-    {
-      fqFunctionName = functioName.library == null ? functioName.function : functioName.library + "#" + functioName.function;
-      funcSigs.add(new FunctionSignature(functioName.dataverse, fqFunctionName, 1));
-    }
-  )*
-}
-
-String GetPolicy() throws ParseException:
-{
-  String policy = null;
-}
-{
-   <USING> <POLICY> policy = Identifier()
-   {
-     return policy;
-   }
-
-}
-
-FunctionSignature FunctionSignature() throws ParseException:
-{
-  FunctionName fctName = null;
-  int arity = 0;
-}
-{
-  fctName = FunctionName() <SYMBOLAT> <INTEGER_LITERAL>
-    {
-      arity = new Integer(token.image);
-      if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
-        throw new ParseException(" invalid arity:" + arity);
-      }
-
-      // TODO use fctName.library
-      String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
-      return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
-    }
-}
-
-Pair<List<Integer>, List<List<String>>> PrimaryKey() throws ParseException:
-{
-   Pair<Integer, List<String>> tmp = null;
-   List<Integer> keyFieldSourceIndicators = new ArrayList<Integer>();
-   List<List<String>> primaryKeyFields = new ArrayList<List<String>>();
-}
-{
-  <PRIMARY> <KEY> tmp = NestedField()
-    {
-      keyFieldSourceIndicators.add(tmp.first);
-      primaryKeyFields.add(tmp.second);
-    }
-  ( <COMMA> tmp = NestedField()
-    {
-      keyFieldSourceIndicators.add(tmp.first);
-      primaryKeyFields.add(tmp.second);
-    }
-  )*
-    {
-      return new Pair<List<Integer>, List<List<String>>> (keyFieldSourceIndicators, primaryKeyFields);
-    }
-}
-
-Statement DropStatement() throws ParseException:
-{
-  String id = null;
-  Pair<DataverseName,Identifier> pairId = null;
-  Triple<DataverseName,Identifier,Identifier> tripleId = null;
-  FunctionSignature funcSig = null;
-  boolean ifExists = false;
-  Statement stmt = null;
-}
-{
-  <DROP>
-  (
-    <DATASET> pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new DropDatasetStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <INDEX> tripleId = DoubleQualifiedName() ifExists = IfExists()
-      {
-        stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
-      }
-    | <NODEGROUP> id = Identifier() ifExists = IfExists()
-      {
-        stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
-      }
-    | <TYPE> pairId = TypeName() ifExists = IfExists()
-      {
-        stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <DATAVERSE> id = Identifier() ifExists = IfExists()
-      {
-        stmt = new DataverseDropStatement(DataverseName.createSinglePartName(id), ifExists);
-      }
-    | <FUNCTION> funcSig = FunctionSignature() ifExists = IfExists()
-      {
-        stmt = new FunctionDropStatement(funcSig, ifExists);
-      }
-    | <FEED> pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
-      }
-    | <INGESTION> <POLICY> pairId = QualifiedName() ifExists = IfExists()
-      {
-        stmt = new FeedPolicyDropStatement(pairId.first, pairId.second, ifExists);
-      }
-  )
-  {
-    return stmt;
-  }
-}
-
-boolean IfExists() throws ParseException :
-{
-}
-{
-  (
-    LOOKAHEAD(1)
-    <IF> <EXISTS>
-    {
-      return true;
-    }
-  )?
-    {
-      return false;
-    }
-}
-
-InsertStatement InsertStatement() throws ParseException:
-{
-  Pair<DataverseName,Identifier> nameComponents = null;
-  VariableExpr var = null;
-  Query query;
-  Expression returnExpression = null;
-}
-{
-  <INSERT> <INTO> <DATASET> nameComponents = QualifiedName()
-  (<AS> var = Variable())?
-  {
-    if(var != null){
-      getCurrentScope().addNewVarSymbolToScope(var.getVar());
-    }
-  }
-  query = Query() ( <RETURNING> returnExpression = Expression())?
-    {
-      checkBindingVariable(returnExpression, var, query);
-      query.setTopLevel(true);
-      return new InsertStatement(nameComponents.first, nameComponents.second.getValue(), query, getVarCounter(), var,
-                                 returnExpression);
-    }
-}
-
-UpsertStatement UpsertStatement() throws ParseException:
-{
-  Pair<DataverseName,Identifier> nameComponents = null;
-  VariableExpr var = null;
-  Query query;
-  Expression returnExpression = null;
-}
-{
-  <UPSERT> <INTO> <DATASET> nameComponents = QualifiedName()
-  (<AS> var = Variable())?
-  {
-    if(var != null){
-      getCurrentScope().addNewVarSymbolToScope(var.getVar());
-    }
-  }
-  query = Query() ( <RETURNING> returnExpression = Expression())?
-    {
-      checkBindingVariable(returnExpression, var, query);
-      query.setTopLevel(true);
-      return new UpsertStatement(nameComponents.first, nameComponents.second.getValue(), query, getVarCounter(), var,
-                                 returnExpression);
-    }
-}
-
-DeleteStatement DeleteStatement() throws ParseException:
-{
-  VariableExpr var = null;
-  Expression condition = null;
-  Pair<DataverseName, Identifier> nameComponents;
-}
-{
-  <DELETE> var = Variable()
-    {
-      getCurrentScope().addNewVarSymbolToScope(var.getVar());
-    }
-  <FROM> <DATASET> nameComponents  = QualifiedName()
-  (<WHERE> condition = Expression())?
-    {
-      // First we get the dataverses and datasets that we want to lock
-      return new DeleteStatement(var, nameComponents.first, nameComponents.second.getValue(),
-          condition, getVarCounter());
-    }
-}
-
-UpdateStatement UpdateStatement() throws ParseException:
-{
-  VariableExpr vars;
-  Expression target;
-  Expression condition;
-  UpdateClause uc;
-  List<UpdateClause> ucs = new ArrayList<UpdateClause>();
-}
-{
-  <UPDATE> vars = Variable() <IN> target = Expression()
-  <WHERE> condition = Expression()
-  <LEFTPAREN> (uc = UpdateClause()
-    {
-      ucs.add(uc);
-    }
-  (<COMMA> uc = UpdateClause()
-    {
-      ucs.add(uc);
-    }
-  )*) <RIGHTPAREN>
-    {
-      return new UpdateStatement(vars, target, condition, ucs);
-    }
-}
-
-UpdateClause UpdateClause() throws ParseException:
-{
-  Expression target = null;
-  Expression value = null ;
-  InsertStatement is = null;
-  DeleteStatement ds = null;
-  UpdateStatement us = null;
-  Expression condition = null;
-  UpdateClause ifbranch = null;
-  UpdateClause elsebranch = null;
-}
-{
-   (<SET> target = Expression() <ASSIGN> value = Expression()
-   | is = InsertStatement()
-   | ds = DeleteStatement()
-   | us = UpdateStatement()
-   | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
-     <THEN> ifbranch = UpdateClause()
-     [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
-     {
-       return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
-     }
-   )
-}
-
-Statement SetStatement() throws ParseException:
-{
-  String pn = null;
-  String pv = null;
-}
-{
-  <SET> pn = Identifier() pv = StringLiteral()
-    {
-      return new SetStatement(pn, pv);
-    }
-}
-
-Statement WriteStatement() throws ParseException:
-{
-  String nodeName = null;
-  String fileName = null;
-  Query query;
-  String writerClass = null;
-  Pair<Identifier,Identifier> nameComponents = null;
-}
-{
-  <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = StringLiteral()
-    ( <USING> writerClass = StringLiteral() )?
-    {
-      return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
-    }
-}
-
-LoadStatement LoadStatement() throws ParseException:
-{
-  DataverseName dataverseName = null;
-  Identifier datasetName = null;
-  boolean alreadySorted = false;
-  String adapterName;
-  Map<String,String> properties;
-  Pair<DataverseName,Identifier> nameComponents = null;
-}
-{
-  <LOAD> <DATASET> nameComponents = QualifiedName()
-    {
-      dataverseName = nameComponents.first;
-      datasetName = nameComponents.second;
-    }
-  <USING> adapterName = AdapterName() properties = Configuration()
-  (<PRESORTED>
-    {
-      alreadySorted = true;
-    }
-  )?
-    {
-      return new LoadStatement(dataverseName, datasetName.getValue(), adapterName, properties, alreadySorted);
-    }
-}
-
-
-String AdapterName() throws ParseException :
-{
-  String adapterName = null;
-}
-{
-  adapterName = Identifier()
-    {
-      return adapterName;
-    }
-}
-
-Statement CompactStatement() throws ParseException:
-{
-  Pair<DataverseName,Identifier> nameComponents = null;
-  Statement stmt = null;
-}
-{
-  <COMPACT> <DATASET> nameComponents = QualifiedName()
-    {
-      stmt = new CompactStatement(nameComponents.first, nameComponents.second);
-    }
-    {
-      return stmt;
-    }
-}
-
-Statement FeedStatement() throws ParseException:
-{
-  Pair<DataverseName,Identifier> feedNameComponents = null;
-  Pair<DataverseName,Identifier> datasetNameComponents = null;
-
-  Map<String,String> configuration = null;
-  List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>();
-  Statement stmt = null;
-  String policy = null;
-}
-{
-  (
-    <CONNECT> <FEED> feedNameComponents = QualifiedName() <TO> <DATASET> datasetNameComponents = QualifiedName()
-    (ApplyFunction(appliedFunctions))? (policy = GetPolicy())?
-      {
-        stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, appliedFunctions, policy, null, getVarCounter());
-      }
-    | <DISCONNECT> <FEED> feedNameComponents = QualifiedName() <FROM> <DATASET> datasetNameComponents = QualifiedName()
-      {
-        stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
-      }
-    | <START> <FEED> feedNameComponents = QualifiedName()
-      {
-        stmt = new StartFeedStatement (feedNameComponents);
-      }
-    | <STOP> <FEED> feedNameComponents = QualifiedName()
-      {
-        stmt = new StopFeedStatement (feedNameComponents);
-      }
-  )
-    {
-      return stmt;
-    }
-}
-
-Map<String,String> Configuration()  throws ParseException :
-{
-    Map<String,String> configuration = new LinkedHashMap<String,String>();
-    Pair<String, String> keyValuePair = null;
-}
-{
-  <LEFTPAREN> ( keyValuePair = KeyValuePair()
-    {
-      configuration.put(keyValuePair.first, keyValuePair.second);
-    }
-  ( <COMMA> keyValuePair = KeyValuePair()
-    {
-      configuration.put(keyValuePair.first, keyValuePair.second);
-    }
-  )* )? <RIGHTPAREN>
-    {
-      return configuration;
-    }
-}
-
-Pair<String, String> KeyValuePair() throws ParseException:
-{
-  String key;
-  String value;
-}
-{
-  <LEFTPAREN> key = StringLiteral()
-  <EQ>( value = StringLiteral() | (<TRUE> | <FALSE>) {value = token.image.toLowerCase();} )
-  <RIGHTPAREN>
-    {
-      return new Pair<String, String>(key, value);
-    }
-}
-
-Map<String,String> Properties() throws ParseException:
-{
-  Map<String,String> properties = new HashMap<String,String>();
-  Pair<String, String> property;
-}
-{
-  ( <LEFTPAREN> property = Property()
-    {
-      properties.put(property.first, property.second);
-    }
-  ( <COMMA> property = Property()
-    {
-      properties.put(property.first, property.second);
-    }
-  )* <RIGHTPAREN> )?
-    {
-      return properties;
-    }
-}
-
-Pair<String, String> Property() throws ParseException:
-{
-  String key;
-  String value;
-}
-{
-  key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
-    {
-      try {
-        value = "" + Long.valueOf(token.image);
-      } catch (NumberFormatException nfe) {
-        throw new ParseException("inapproriate value: " + token.image);
-      }
-    }
-  )
-    {
-      return new Pair<String, String>(key.toUpperCase(), value);
-    }
-}
-
-IndexedTypeExpression IndexedTypeExpr() throws ParseException:
-{
-  TypeExpression typeExpr = null;
-  boolean isUnknownable = false;
-}
-{
-  (
-      typeExpr = TypeReference()
-    | typeExpr = OrderedListTypeDef()
-    | typeExpr = UnorderedListTypeDef()
-  )
-  ( <QUES> { isUnknownable = true; } )?
-  {
-    return new IndexedTypeExpression(typeExpr, isUnknownable);
-  }
-}
-
-TypeExpression TypeExpr() throws ParseException:
-{
-  TypeExpression typeExpr = null;
-}
-{
-  (
-      typeExpr = RecordTypeDef()
-    | typeExpr = TypeReference()
-    | typeExpr = OrderedListTypeDef()
-    | typeExpr = UnorderedListTypeDef()
-  )
-  {
-    return typeExpr;
-  }
-}
-
-RecordTypeDefinition RecordTypeDef() throws ParseException:
-{
-  RecordTypeDefinition recType = new RecordTypeDefinition();
-  RecordTypeDefinition.RecordKind recordKind = null;
-}
-{
-  ( <CLOSED>{ recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
-    | <OPEN>{ recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
-   <LEFTBRACE>
-    {
-      String hint = getHint(token);
-      if (hint != null) {
-        String splits[] = hint.split(" +");
-        if (splits[0].equals(GEN_FIELDS_HINT)) {
-          if (splits.length != 5) {
-            throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
-          }
-          if (!splits[1].equals("int")) {
-            throw new ParseException("The only supported type for gen-fields is int.");
-          }
-          UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
-             Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
-          recType.setUndeclaredFieldsDataGen(ufdg);
-        }
-      }
-
-    }
-        (
-          RecordField(recType)
-          ( <COMMA>  RecordField(recType) )*
-        )?
-   <RIGHTBRACE>
-   {
-      if (recordKind == null) {
-        recordKind = RecordTypeDefinition.RecordKind.OPEN;
-      }
-      recType.setRecordKind(recordKind);
-      return recType;
-   }
-}
-
-void RecordField(RecordTypeDefinition recType) throws ParseException:
-{
-  String fieldName;
-  TypeExpression type = null;
-  boolean nullable = false, missable = false;
-}
-{
-  fieldName = Identifier()
-    {
-      String hint = getHint(token);
-      IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
-    }
-  <COLON> type =  TypeExpr() (<QUES> { nullable = true; missable = true; } )?
-    {
-      recType.addField(fieldName, type, nullable, missable, rfdg);
-    }
-}
-
-TypeReferenceExpression TypeReference() throws ParseException:
-{
-  Pair<DataverseName,Identifier> id = null;
-}
-{
- id = QualifiedName()
-   {
-     if (id.first == null && id.second.getValue().equalsIgnoreCase(INT_TYPE_NAME)) {
-        id.second = new Identifier(BuiltinType.AINT64.getTypeName());
-     }
-
-     return new TypeReferenceExpression(id);
-   }
-}
-
-OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
-{
-  TypeExpression type = null;
-}
-{
-  <LEFTBRACKET>
-    ( type =  TypeExpr() )
-  <RIGHTBRACKET>
-  {
-    return new OrderedListTypeDefinition(type);
-  }
-}
-
-
-UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
-{
-  TypeExpression type = null;
-}
-{
-  <LEFTDBLBRACE>
-    ( type =  TypeExpr() )
-  <RIGHTDBLBRACE>
-  {
-    return new UnorderedListTypeDefinition(type);
-  }
-}
-
-FunctionName FunctionName() throws ParseException:
-{
-  String first = null;
-  String second = null;
-  String third = null;
-  boolean secondAfterDot = false;
-}
-{
-  first = Identifier()
-  {
-    FunctionName result = new FunctionName();
-    result.hint = getHint(token);
-  }
-  ( <DOT> second = Identifier()
-    {
-      secondAfterDot = true;
-    }
-  ( <SYMBOLHASH> third = Identifier())? | <SYMBOLHASH> second = Identifier() )?
-    {
-      if (second == null) {
-        result.dataverse = defaultDataverse;
-        result.library = null;
-        result.function = first;
-      } else if (third == null) {
-        if (secondAfterDot) {
-          result.dataverse = DataverseName.createSinglePartName(first);
-          result.library   = null;
-          result.function = second;
-        } else {
-          result.dataverse = defaultDataverse;
-          result.library   = first;
-          result.function = second;
-        }
-      } else {
-        result.dataverse = DataverseName.createSinglePartName(first);
-        result.library   = second;
-        result.function  = third;
-      }
-
-      if (result.function.equalsIgnoreCase(INT_TYPE_NAME)) {
-        result.function = BuiltinType.AINT64.getTypeName();
-      }
-      return result;
-    }
-}
-
-
-Pair<DataverseName,Identifier> TypeName() throws ParseException:
-{
-  Pair<DataverseName,Identifier> name = null;
-}
-{
-  name = QualifiedName()
-    {
-      if (name.first == null) {
-        name.first = defaultDataverse;
-      }
-      return name;
-    }
-}
-
-String Identifier() throws ParseException:
-{
-  String lit = null;
-}
-{
-  ((<IDENTIFIER>)
-    {
-      return token.image;
-    }
-  | lit = StringLiteral()
-    {
-      return lit;
-    }
-  )
-}
-
-Pair<Integer, Pair<List<String>, IndexedTypeExpression>> OpenField() throws ParseException:
-{
-  IndexedTypeExpression fieldType = null;
-  Pair<Integer, List<String>> fieldList = null;
-}
-{
-  fieldList = NestedField()
-  ( <COLON> fieldType = IndexedTypeExpr() )?
-  {
-    return new Pair<Integer, Pair<List<String>, IndexedTypeExpression>>
-            (fieldList.first, new Pair<List<String>, IndexedTypeExpression>(fieldList.second, fieldType));
-  }
-}
-
-Pair<Integer, List<String>> NestedField() throws ParseException:
-{
-  List<String> exprList = new ArrayList<String>();
-  String lit = null;
-  int source = 0;
-}
-{
-  lit = Identifier()
-  {
-    boolean meetParens = false;
-  }
-  (
-    LOOKAHEAD(1)
-    <LEFTPAREN><RIGHTPAREN>
-    {
-        if(!lit.equals("meta")){
-            throw new ParseException("The string before () has to be \"meta\".");
-        }
-        meetParens = true;
-        source = 1;
-    }
-  )?
-  {
-    if(!meetParens){
-        exprList.add(lit);
-    }
-  }
-  (<DOT>
-    lit = Identifier()
-    {
-      exprList.add(lit);
-    }
-  )*
-  {
-    return new Pair<Integer, List<String>>(source, exprList);
-  }
-}
-
-
-
-String StringLiteral() throws ParseException:
-{
-}
-{
-  <STRING_LITERAL>
-    {
-      return removeQuotesAndEscapes(token.image);
-    }
-}
-
-Pair<DataverseName,Identifier> QualifiedName() throws ParseException:
-{
-  String first = null;
-  String second = null;
-}
-{
-  first = Identifier() (<DOT> second = Identifier())?
-  {
-    DataverseName id1 = null;
-    Identifier id2 = null;
-    if (second == null) {
-      id2 = new Identifier(first);
-    } else
-    {
-      id1 = DataverseName.createSinglePartName(first);
-      id2 = new Identifier(second);
-    }
-    return new Pair<DataverseName,Identifier>(id1, id2);
-  }
-}
-
-Triple<DataverseName,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
-{
-  String first = null;
-  String second = null;
-  String third = null;
-}
-{
-  first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
-  {
-    DataverseName id1 = null;
-    Identifier id2 = null;
-    Identifier id3 = null;
-    if (third == null) {
-      id2 = new Identifier(first);
-      id3 = new Identifier(second);
-    } else {
-      id1 = DataverseName.createSinglePartName(first);
-      id2 = new Identifier(second);
-      id3 = new Identifier(third);
-    }
-    return new Triple<DataverseName,Identifier,Identifier>(id1, id2, id3);
-  }
-}
-
-FunctionDecl FunctionDeclaration() throws ParseException:
-{
-  FunctionDecl funcDecl;
-  FunctionSignature signature;
-  String functionName;
-  List<VarIdentifier> paramList_typ = new ArrayList<VarIdentifier>();
-  List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
-  Expression funcBody;
-  createNewScope();
-}
-{
-  <DECLARE> <FUNCTION> functionName = Identifier()
-
-  paramList_typ = ParameterList()
-  <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
-    {
-      for(VarIdentifier v: paramList_typ){
-            paramList.add(v);
-      }
-      signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
-      getCurrentScope().addFunctionDescriptor(signature, false);
-      funcDecl = new FunctionDecl(signature, paramList, funcBody);
-      removeCurrentScope();
-      return funcDecl;
-    }
-}
-
-
-Query Query() throws ParseException:
-{
-  Query query = new Query(false);
-  Expression expr;
-}
-{
-  expr = Expression()
-    {
-      query.setBody(expr);
-      query.setVarCounter(getVarCounter());
-      return query;
-    }
-}
-
-
-
-Expression Expression():
-{
-  Expression expr = null;
-  Expression exprP = null;
-}
-{
-(
-
-//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
-    expr = OperatorExpr()
-    | expr = IfThenElse()
-    | expr = FLWOGR()
-    | expr = QuantifiedExpression()
-
-
-)
-    {
-      return (exprP==null) ? expr : exprP;
-    }
-}
-
-
-
-Expression OperatorExpr()throws ParseException:
-{
-  OperatorExpr op = null;
-  Expression operand = null;
-}
-{
-    operand = AndExpr()
-    (
-
-      <OR>
-      {
-        if (op == null) {
-          op = new OperatorExpr();
-          op.addOperand(operand);
-        op.setCurrentop(true);
-        }
-        try{
-          op.addOperator(token.image);
-        } catch (CompilationException e){
-          throw new ParseException(e.getMessage());
-        }
-    }
-
-    operand = AndExpr()
-    {
-      op.addOperand(operand);
-    }
-
-    )*
-
-    {
-      return op==null? operand: op;
-    }
-}
-
-Expression AndExpr()throws ParseException:
-{
-  OperatorExpr op = null;
-  Expression operand = null;
-}
-{
-    operand = RelExpr()
-    (
-
-      <AND>
-      {
-        if (op == null) {
-          op = new OperatorExpr();
-          op.addOperand(operand);
-        op.setCurrentop(true);
-        }
-        try{
-          op.addOperator(token.image);
-        } catch (CompilationException e){
-          throw new ParseException(e.getMessage());
-        }
-    }
-
-    operand = RelExpr()
-    {
-      op.addOperand(operand);
-    }
-
-    )*
-
-    {
-      return op==null? operand: op;
-    }
-}
-
-
-
-Expression RelExpr()throws ParseException:
-{
-  OperatorExpr op = null;
-  Expression operand = null;
-  IExpressionAnnotation annotation = null;
-}
-{
-    operand = AddExpr()
-
-    (
-      LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
-        {
-          String mhint = getHint(token);
-          if (mhint != null) {
-            if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
-            annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
-          } else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
-            annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
-          }
-        }
-          if (op == null) {
-            op = new OperatorExpr();
-            op.addOperand(operand);
-          op.setCurrentop(true);
-          }
-         try{
-           op.addOperator(token.image);
-         } catch (CompilationException e){
-           throw new ParseException(e.getMessage());
-         }
-      }
-
-       operand = AddExpr()
-      {
-         if (operand instanceof VariableExpr) {
-           String hint = getHint(token);
-           if (hint != null && hint.equals(HASH_BROADCAST_JOIN_HINT)) {
-             annotation = new BroadcastExpressionAnnotation();
-             annotation.setObject(BroadcastExpressionAnnotation.BroadcastSide.RIGHT);
-           }
-         }
-         op.addOperand(operand);
-      }
-    )?
-
-     {
-       if (annotation != null) {
-         op.addHint(annotation);
-       }
-       return op==null? operand: op;
-     }
-}
-
-Expression AddExpr()throws ParseException:
-{
-  OperatorExpr op = null;
-  Expression operand = null;
-}
-{
-    operand = MultExpr()
-
-    ( (<PLUS> | <MINUS>)
-      {
-        if (op == null) {
-          op = new OperatorExpr();
-        op.addOperand(operand);
-        op.setCurrentop(true);
-        }
-        try{
-          ((OperatorExpr)op).addOperator(token.image);
-        } catch (CompilationException e){
-          throw new ParseException(e.getMessage());
-        }
-    }
-
-    operand = MultExpr()
-    {
-      op.addOperand(operand);
-    }
-    )*
-
-    {
-       return op==null? operand: op;
-     }
-}
-
-Expression MultExpr()throws ParseException:
-{
-  OperatorExpr op = null;
-  OperatorType opType = null;
-  Expression operand = null;
-}
-{
-    operand = ExponentExpr()
-
-    ( (
-        <MUL> { opType = OperatorType.MUL; } |
-        <DIVIDE> { opType = OperatorType.DIVIDE; } |
-        <DIV> { opType = OperatorType.DIV; } |
-        ( <MOD> | <PERCENT> ) { opType = OperatorType.MOD; }
-      )
-      {
-        if (op == null) {
-          op = new OperatorExpr();
-          op.addOperand(operand);
-          op.setCurrentop(true);
-        }
-        op.addOperator(opType);
-    }
-    operand = ExponentExpr()
-    {
-       op.addOperand(operand);
-    }
-    )*
-
-     {
-       return op==null?operand:op;
-     }
-}
-
-Expression ExponentExpr()throws ParseException:
-{
-  OperatorExpr op = null;
-  Expression operand = null;
-}
-{
-    operand = UnionExpr()
-
-    ( <CARET>
-      {
-        if (op == null) {
-          op = new OperatorExpr();
-          op.addOperand(operand);
-          op.setCurrentop(true);
-        }
-        try{
-          op.addOperator(token.image);
-        } catch (CompilationException e){
-          throw new ParseException(e.getMessage());
-        }
-    }
-    operand = UnionExpr()
-    {
-       op.addOperand(operand);
-    }
-    )?
-
-    {
-       return op==null?operand:op;
-    }
-}
-
-Expression UnionExpr() throws ParseException:
-{
-    UnionExpr union = null;
-    Expression operand1 = null;
-    Expression operand2 = null;
-}
-{
-   operand1 = UnaryExpr()
-   (<UNION>
-       (operand2 = UnaryExpr()) {
-          if (union == null) {
-             union = new UnionExpr();
-             union.addExpr(operand1);
-          }
-          union.addExpr(operand2);
-       } )*
-   {
-     return (union == null)? operand1: union;
-   }
-}
-
-Expression UnaryExpr() throws ParseException:
-{
-    UnaryExpr uexpr = null;
-    Expression expr = null;
-}
-{
-    ( (<PLUS> | <MINUS>)
-    {
-          uexpr = new UnaryExpr();
-          try{
-            uexpr.setExprType(token.image);
-          } catch (CompilationException e){
-            throw new ParseException(e.getMessage());
-          }
-    }
-    )?
-
-    expr = ValueExpr()
-    {
-        if(uexpr!=null){
-            ((UnaryExpr)uexpr).setExpr(expr);
-            return uexpr;
-        }
-        else{
-            return expr;
-        }
-    }
-}
-
-Expression ValueExpr()throws ParseException:
-{
-  Expression expr = null;
-  Identifier ident = null;
-  AbstractAccessor fa = null;
-  Pair<IndexAccessor.IndexKind, Expression> index = null;
-}
-{
-  expr = PrimaryExpr() ( ident = Field()
-    {
-      fa = (fa == null ? new FieldAccessor(expr, ident)
-                       : new FieldAccessor(fa, ident));
-    }
-  | index = Index()
-    {
-      fa = (fa == null ? new IndexAccessor(expr, index.first, index.second)
-                       : new IndexAccessor(fa, index.first, index.second));
-     }
-  )*
-    {
-      return fa == null ? expr : fa;
-    }
-}
-
-Identifier Field() throws ParseException:
-{
-  String ident = null;
-}
-{
-  <DOT> ident = Identifier()
-    {
-      return new Identifier(ident);
-    }
-}
-
-Pair<IndexAccessor.IndexKind, Expression> Index() throws ParseException:
-{
-    IndexAccessor.IndexKind kind = null;
-    Expression expr = null;
-}
-{
-  <LEFTBRACKET> ( expr = Expression()
-    {
-        if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
-        {
-            Literal lit = ((LiteralExpr)expr).getValue();
-            if(lit.getLiteralType() != Literal.Type.INTEGER &&
-               lit.getLiteralType() != Literal.Type.LONG) {
-                throw new ParseException("Index should be an INTEGER");
-            }
-        }
-        kind = IndexAccessor.IndexKind.ELEMENT;
-    }
-
-      | <QUES> // ANY
-    {
-        kind = IndexAccessor.IndexKind.ANY;
-    }
-      )
-
-   <RIGHTBRACKET>
-    {
-      return new Pair<IndexAccessor.IndexKind, Expression>(kind, expr);
-    }
-}
-
-
-Expression PrimaryExpr()throws ParseException:
-{
-  Expression expr = null;
-}
-{
-  ( LOOKAHEAD(2)
-    expr = FunctionCallExpr()
-  | expr = Literal()
-  | expr = DatasetAccessExpression()
-  | expr = VariableRef()
-    {
-      if(((VariableExpr)expr).getIsNewVar() == true)
-        throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
-    }
-  | expr = ListConstructor()
-  | expr = RecordConstructor()
-  | expr = ParenthesizedExpression()
-  )
-    {
-      return expr;
-    }
-}
-
-Expression Literal() throws ParseException:
-{
-  LiteralExpr lit = new LiteralExpr();
-  String str = null;
-}
-{
-  ( str = StringLiteral()
-    {
-      lit.setValue(new StringLiteral(str));
-    }
-  | <INTEGER_LITERAL>
-    {
-      lit.setValue(new LongIntegerLiteral(new Long(token.image)));
-    }
-  | <FLOAT_LITERAL>
-    {
-      lit.setValue(new FloatLiteral(new Float(token.image)));
-    }
-  | <DOUBLE_LITERAL>
-    {
-      lit.setValue(new DoubleLiteral(new Double(token.image)));
-    }
-  | <MISSING>
-    {
-      lit.setValue(MissingLiteral.INSTANCE);
-    }
-  | <NULL>
-    {
-      lit.setValue(NullLiteral.INSTANCE);
-    }
-  | <TRUE>
-    {
-      lit.setValue(TrueLiteral.INSTANCE);
-    }
-  | <FALSE>
-    {
-      lit.setValue(FalseLiteral.INSTANCE);
-    }
-  )
-    {
-      return lit;
-    }
-}
-
-
-VariableExpr VariableRef() throws ParseException:
-{
-}
-{
-  <VARIABLE>
-    {
-     String varName = token.image;
-     Identifier ident = lookupSymbol(varName);
-     if (isInForbiddenScopes(varName)) {
-       throw new ParseException("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.");
-     }
-     VariableExpr varExp;
-     if(ident != null) { // exist such ident
-       varExp = new VariableExpr((VarIdentifier)ident);
-       varExp.setIsNewVar(false);
-     } else {
-       varExp = new VariableExpr(new VarIdentifier(varName));
-     }
-     return varExp;
-    }
-}
-
-
-VariableExpr Variable() throws ParseException:
-{
-}
-{
-  <VARIABLE>
-    {
-     String varName = token.image;
-     Identifier ident = lookupSymbol(varName);
-     VariableExpr varExp = new VariableExpr(new VarIdentifier(varName));
-     if(ident != null) { // exist such ident
-       varExp.setIsNewVar(false);
-     }
-     return varExp;
-    }
-}
-
-Expression ListConstructor() throws ParseException:
-{
-    Expression expr = null;
-}
-{
-    (
-        expr = OrderedListConstructor() | expr = UnorderedListConstructor()
-    )
-
-    {
-      return expr;
-    }
-}
-
-
-ListConstructor OrderedListConstructor() throws ParseException:
-{
-      ListConstructor expr = new ListConstructor();
-      List<Expression> exprList = null;
-      expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
-}
-{
-    <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
-    {
-      expr.setExprList(exprList);
-      return expr;
-    }
-}
-
-ListConstructor UnorderedListConstructor() throws ParseException:
-{
-      ListConstructor expr = new ListConstructor();
-      List<Expression> exprList = null;
-      expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
-}
-{
-    <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
-    {
-      expr.setExprList(exprList);
-      return expr;
-    }
-}
-
-List<Expression> ExpressionList() throws ParseException:
-{
-      Expression expr = null;
-      List<Expression> list = null;
-      List<Expression> exprList = new ArrayList<Expression>();
-}
-{
-    (
-      expr = Expression() { exprList.add(expr); }
-      (LOOKAHEAD(1) <COMMA> list = ExpressionList() { exprList.addAll(list); })?
-    )?
-    (LOOKAHEAD(1) Comma())?
-    {
-        return exprList;
-    }
-}
-
-void Comma():
-{}
-{
-   <COMMA>
-}
-
-RecordConstructor RecordConstructor() throws ParseException:
-{
-      RecordConstructor expr = new RecordConstructor();
-      FieldBinding tmp = null;
-      List<FieldBinding> fbList = new ArrayList<FieldBinding>();
-}
-{
-    <LEFTBRACE> (tmp = FieldBinding()
-    {
-      fbList.add(tmp);
-    }
-    (<COMMA> tmp = FieldBinding() { fbList.add(tmp);  })*)? <RIGHTBRACE>
-    {
-      expr.setFbList(fbList);
-      return expr;
-    }
-}
-
-FieldBinding FieldBinding() throws ParseException:
-{
-    Expression left, right;
-}
-{
-    left = Expression() <COLON> right = Expression()
-    {
-      return new FieldBinding(left, right);
-    }
-}
-
-
-Expression FunctionCallExpr() throws ParseException:
-{
-  CallExpr callExpr;
-  List<Expression> argList = new ArrayList<Expression>();
-  Expression tmp;
-  int arity = 0;
-  FunctionName funcName = null;
-  String hint = null;
-}
-{
-  funcName = FunctionName()
-    {
-      hint = funcName.hint;
-    }
-  <LEFTPAREN> (tmp = Expression()
-    {
-      argList.add(tmp);
-      arity ++;
-    }
-  (<COMMA> tmp = Expression()
-    {
-      argList.add(tmp);
-      arity++;
-    }
-  )*)? <RIGHTPAREN>
-    {
-      // TODO use funcName.library
-      String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
-      FunctionSignature signature
-        = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
-      if (signature == null) {
-        signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
-      }
-      callExpr = new CallExpr(signature,argList);
-      if (hint != null) {
-        if (hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
-          callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
-        } else if (hint.startsWith(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
-          callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
-        }
-      }
-      return callExpr;
-    }
-}
-
-
-Expression DatasetAccessExpression() throws ParseException:
-{
-  String funcName;
-  String arg1 = null;
-  String arg2 = null;
-  Expression nameArg;
-}
-{
-  <DATASET>
-    {
-      funcName = token.image;
-    }
-  ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
-    {
-      String name = arg2 == null ? arg1 : arg1 + "." + arg2;
-      LiteralExpr ds = new LiteralExpr();
-      ds.setValue( new StringLiteral(name) );
-      nameArg = ds;
-    }
-  | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
-    {
-      DataverseName dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
-      FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
-      if (signature == null) {
-        signature = new FunctionSignature(dataverse, funcName, 1);
-      }
-      List<Expression> argList = new ArrayList<Expression>();
-      argList.add(nameArg);
-      return new CallExpr(signature, argList);
-    }
-}
-
-Expression ParenthesizedExpression() throws ParseException:
-{
-  Expression expr;
-}
-{
-    <LEFTPAREN> expr = Expression() <RIGHTPAREN>
-    {
-      return expr;
-    }
-}
-
-Expression IfThenElse() throws ParseException:
-{
-  Expression condExpr;
-  Expression thenExpr;
-  Expression elseExpr;
-  IfExpr ifExpr = new IfExpr();
-}
-{
-    <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
-
-    {
-      ifExpr.setCondExpr(condExpr);
-      ifExpr.setThenExpr(thenExpr);
-      ifExpr.setElseExpr(elseExpr);
-      return ifExpr;
-    }
-}
-
-Expression FLWOGR() throws ParseException:
-{
-    FLWOGRExpression flworg = new FLWOGRExpression();
-    List<Clause> clauseList = new ArrayList<Clause>();
-    Expression returnExpr;
-    Clause tmp;
-    createNewScope();
-}
-{
-     (tmp = ForClause()  {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
-      (tmp = Clause() {clauseList.add(tmp);})* (<RETURN>|<SELECT>) returnExpr = Expression()
-
-     {
-       flworg.setClauseList(clauseList);
-       flworg.setReturnExpr(returnExpr);
-       removeCurrentScope();
-       return flworg;
-     }
-}
-
-Clause Clause()throws ParseException :
-{
-  Clause clause;
-}
-{
-    (
-         clause = ForClause()
-       | clause = LetClause()
-       | clause = WhereClause()
-       | clause = OrderbyClause()
-       | clause = GroupClause()
-       | clause = LimitClause()
-       | clause = DistinctClause()
-    )
-    {
-      return clause;
-    }
-}
-
-Clause ForClause()throws ParseException :
-{
-    ForClause fc = new ForClause();
-    VariableExpr varExp;
-    VariableExpr varPos = null;
-    Expression inExp;
-    extendCurrentScope();
-}
-{
-    (<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())?  <IN> ( inExp = Expression() )
-    {
-      fc.setVarExpr(varExp);
-      getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
-      fc.setInExpr(inExp);
-      if (varPos != null) {
-        fc.setPosExpr(varPos);
-        getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
-      }
-      return fc;
-    }
-}
-
-Clause LetClause() throws ParseException:
-{
-    LetClause lc = new LetClause();
-    VariableExpr varExp;
-    Expression beExp;
-    extendCurrentScope();
-}
-{
-    (<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
-    {
-      getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
-      lc.setVarExpr(varExp);
-      lc.setBindingExpr(beExp);
-      return lc;
-    }
-}
-
-Clause WhereClause()throws ParseException :
-{
-  WhereClause wc = new WhereClause();
-  Expression whereExpr;
-}
-{
-    <WHERE> whereExpr = Expression()
-    {
-      wc.setWhereExpr(whereExpr);
-      return wc;
-    }
-}
-
-Clause OrderbyClause()throws ParseException :
-{
-    OrderbyClause oc = new OrderbyClause();
-    Expression orderbyExpr;
-    List<Expression> orderbyList = new ArrayList<Expression>();
-    List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
-    int numOfOrderby = 0;
-}
-{
-  (
-    <ORDER>
-      {
-        String hint = getHint(token);
-        if (hint != null) {
-          if (hint.startsWith(INMEMORY_HINT)) {
-            String splits[] = hint.split(" +");
-            int numFrames = Integer.parseInt(splits[1]);
-            int numTuples = Integer.parseInt(splits[2]);
-            oc.setNumFrames(numFrames);
-            oc.setNumTuples(numTuples);
-          } else if (hint.startsWith(RANGE_HINT)) {
-            try {
-              oc.setRangeMap(RangeMapBuilder.parseHint(parseExpression(hint.substring(RANGE_HINT.length()))));
-            } catch (CompilationException e) {
-              throw new ParseException(e.getMessage());
-            }
-          }
-        }
-      }
-    <BY> orderbyExpr = Expression()
-    {
-      orderbyList.add(orderbyExpr);
-      OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
-    }
-    ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
-    | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
-    {
-      modifierList.add(modif);
-    }
-
-    (<COMMA> orderbyExpr = Expression()
-    {
-      orderbyList.add(orderbyExpr);
-      modif = OrderbyClause.OrderModifier.ASC;
-    }
-    ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
-    | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
-    {
-      modifierList.add(modif);
-    }
-    )*
-)
-    {
-      oc.setModifierList(modifierList);
-      oc.setOrderbyList(orderbyList);
-      return oc;
-    }
-}
-Clause GroupClause()throws ParseException :
-{
-    GroupbyClause gbc = new GroupbyClause();
-    // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
-    List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
-    List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
-    Map<Expression, VariableExpr> withVarMap = new HashMap<Expression, VariableExpr>();
-    VariableExpr var = null;
-    VariableExpr withVar = null;
-    Expression expr = null;
-    VariableExpr decorVar = null;
-    Expression decorExpr = null;
-}
-{
-      {
-        Scope newScope = extendCurrentScopeNoPush(true);
-        // extendCurrentScope(true);
-      }
-    <GROUP>
-      {
-         String hint = getHint(token);
-         if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
-           gbc.setHashGroupByHint(true);
-         }
-      }
-    <BY> (LOOKAHEAD(2)  var = Variable()
-    {
-      newScope.addNewVarSymbolToScope(var.getVar());
-    } <ASSIGN>)?
-    expr = Expression()
-       {
-         GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
-         vePairList.add(pair1);
-       }
-    (<COMMA> ( LOOKAHEAD(2) var = Variable()
-    {
-      newScope.addNewVarSymbolToScope(var.getVar());
-    } <ASSIGN>)?
-        expr = Expression()
-         {
-           GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
-           vePairList.add(pair2);
-         }
-        )*
-    (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
-       {
-         newScope.addNewVarSymbolToScope(decorVar.getVar());
-         GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
-         decorPairList.add(pair3);
-       }
-      (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
-           {
-             newScope.addNewVarSymbolToScope(decorVar.getVar());
-             GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
-             decorPairList.add(pair4);
-           }
-       )*
-    )?
-    (<WITH>|<KEEPING>) withVar = VariableRef()
-    {
-      if(withVar.getIsNewVar()==true)
-          throw new ParseException("can't find variable " + withVar.getVar());
-      withVarMap.put(withVar, withVar);
-      newScope.addNewVarSymbolToScope(withVar.getVar());
-    }
-    (<COMMA> withVar = VariableRef()
-    {
-      if(withVar.getIsNewVar()==true)
-          throw new ParseException("can't find variable " + withVar.getVar());
-      withVarMap.put(withVar, withVar);
-      newScope.addNewVarSymbolToScope(withVar.getVar());
-    })*
-    {
-      gbc.setGbyPairList(Collections.singletonList(vePairList));
-      gbc.setDecorPairList(decorPairList);
-      gbc.setWithVarMap(withVarMap);
-      replaceCurrentScope(newScope);
-      return gbc;
-    }
-}
-
-
-LimitClause LimitClause() throws ParseException:
-{
-    LimitClause lc = new LimitClause();
-    Expression expr;
-    pushForbiddenScope(getCurrentScope());
-}
-{
-    <LIMIT> expr = Expression()    { lc.setLimitExpr(expr);    }
-    (<OFFSET> expr = Expression() { lc.setOffset(expr);    })?
-
-  {
-    popForbiddenScope();
-    return lc;
-  }
-}
-
-DistinctClause DistinctClause() throws ParseException:
-{
-  List<Expression> exprs = new ArrayList<Expression>();
-  Expression expr;
-}
-{
-  <DISTINCT> <BY> expr = Expression()
-  {
-    exprs.add(expr);
-  }
-  (<COMMA> expr = Expression()
-      {
-          exprs.add(expr);
-      }
-  )*
-  {
-      return new DistinctClause(exprs);
-  }
-}
-
-QuantifiedExpression QuantifiedExpression()throws ParseException:
-{
-  QuantifiedExpression qc = new QuantifiedExpression();
-  List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
-  Expression satisfiesExpr;
-  VariableExpr var;
-  Expression inExpr;
-  QuantifiedPair pair;
-}
-{
-  {
-    createNewScope();
-  }
-
-   (      (<SOME>  {  qc.setQuantifier(QuantifiedExpression.Quantifier.SOME);    })
-        | (<EVERY> {  qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY);    }))
-    var = Variable() <IN> inExpr = Expression()
-    {
-      pair = new QuantifiedPair(var, inExpr);
-      getCurrentScope().addNewVarSymbolToScope(var.getVar());
-      quantifiedList.add(pair);
-    }
-    (
-    <COMMA> var = Variable() <IN> inExpr = Expression()
-    {
-      pair = new QuantifiedPair(var, inExpr);
-      getCurrentScope().addNewVarSymbolToScope(var.getVar());
-      quantifiedList.add(pair);
-    }
-    )*
-     <SATISFIES> satisfiesExpr = Expression()
-     {
-       qc.setSatisfiesExpr(satisfiesExpr);
-       qc.setQuantifiedList(quantifiedList);
-       removeCurrentScope();
-       return qc;
-     }
-}
-
-TOKEN_MGR_DECLS:
-{
-    public int commentDepth = 0;
-    public ArrayDeque<Integer> lexerStateStack = new ArrayDeque<Integer>();
-
-    public void pushState() {
-      lexerStateStack.push( curLexState );
-    }
-
-    public void popState(String token) {
-      if (lexerStateStack.size() > 0) {
-         SwitchTo( lexerStateStack.pop() );
-      } else {
-         int errorLine = input_stream.getEndLine();
-         int errorColumn = input_stream.getEndColumn();
-         String msg = "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered \"" + token
-             + "\" but state stack is empty.";
-         throw new TokenMgrError(msg, -1);
-      }
-    }
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <APPLY : "apply">
-  | <AS : "as">
-  | <ASC : "asc">
-  | <AT : "at">
-  | <AUTOGENERATED : "autogenerated">
-  | <BTREE : "btree">
-  | <BY : "by">
-  | <CLOSED : "closed">
-  | <COMPACT : "compact">
-  | <COMPACTION : "compaction">
-  | <CONNECT : "connect">
-  | <CREATE : "create">
-  | <DATASET : "dataset">
-  | <DATAVERSE : "dataverse">
-  | <DECLARE : "declare">
-  | <DECOR : "decor">
-  | <DEFINITION : "definition">
-  | <DELETE : "delete">
-  | <DESC : "desc">
-  | <DISCONNECT : "disconnect">
-  | <DISTINCT : "distinct">
-  | <DROP : "drop">
-  | <ELSE : "else">
-  | <ENFORCED : "enforced">
-  | <EVERY : "every">
-  | <EXISTS : "exists">
-  | <EXTERNAL : "external">
-  | <FEED : "feed">
-  | <FILTER : "filter">
-  | <FOR : "for">
-  | <FORMAT : "format">
-  | <FROM : "from">
-  | <FULLTEXT : "fulltext">
-  | <FUNCTION : "function">
-  | <GROUP : "group">
-  | <HINTS : "hints">
-  | <IF : "if">
-  | <IN : "in">
-  | <INDEX : "index">
-  | <INGESTION : "ingestion">
-  | <INSERT : "insert">
-  | <INTERNAL : "internal">
-  | <INTO : "into">
-  | <KEY : "key">
-  | <KEYWORD : "keyword">
-  | <KEEPING : "keeping">
-  | <LET : "let">
-  | <LIMIT : "limit">
-  | <LOAD : "load">
-  | <NGRAM : "ngram">
-  | <NODEGROUP : "nodegroup">
-  | <OFFSET : "offset">
-  | <ON : "on">
-  | <OPEN : "open">
-  | <ORDER : "order">
-  | <OUTPUT : "output">
-  | <PATH : "path">
-  | <POLICY : "policy">
-  | <PRESORTED : "pre-sorted">
-  | <PRIMARY : "primary">
-  | <REFRESH : "refresh">
-  | <RETURN : "return">
-  | <RETURNING : "returning">
-  | <RTREE : "rtree">
-  | <RUN : "run">
-  | <SATISFIES : "satisfies">
-  | <SECONDARY : "secondary">
-  | <SELECT : "select">
-  | <SET : "set">
-  | <START: "start">
-  | <STOP: "stop">
-  | <SOME : "some">
-  | <TEMPORARY : "temporary"> // intentionally not used but reserved for future usage
-  | <THEN : "then">
-  | <TO : "to">
-  | <TYPE : "type">
-  | <UNION : "union">
-  | <UPDATE : "update">
-  | <UPSERT : "upsert">
-  | <USE : "use">
-  | <USING : "using">
-  | <WHERE : "where">
-  | <WITH : "with">
-  | <WRITE : "write">
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <CARET : "^">
-  | <DIVIDE : "/">
-  | <DIV : "div">
-  | <MINUS : "-">
-  | <MOD : "mod">
-  | <MUL : "*">
-  | <PLUS : "+">
-
-  | <LEFTPAREN : "(">
-  | <RIGHTPAREN : ")">
-  | <LEFTBRACKET : "[">
-  | <RIGHTBRACKET : "]">
-
-  | <COLON : ":">
-  | <COMMA : ",">
-  | <DOT : ".">
-  | <PERCENT: "%">
-  | <QUES : "?">
-
-  | <LT : "<">
-  | <GT : ">">
-  | <LE : "<=">
-  | <GE : ">=">
-  | <EQ : "=">
-  | <NE : "!=">
-  | <SIMILAR : "~=">
-  | <ASSIGN : ":=">
-
-  | <AND : "and">
-  | <OR : "or">
-
-  | <SYMBOLAT : "@">
-  | <SYMBOLHASH : "#">
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <LEFTBRACE : "{"> { pushState(); } : DEFAULT
-}
-
-<DEFAULT>
-TOKEN :
-{
-    <RIGHTBRACE : "}"> { popState("}"); }
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
-}
-
-<IN_DBL_BRACE>
-TOKEN :
-{
-    <RIGHTDBLBRACE : "}}"> { popState("}}"); }
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <INTEGER_LITERAL : (<DIGIT>)+ >
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-  < MISSING : "missing">
-  | <NULL : "null">
-  | <TRUE : "true">
-  | <FALSE : "false">
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <#DIGIT : ["0" - "9"]>
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN:
-{
-    < DOUBLE_LITERAL: <DIGITS> ( "." <DIGITS> ) (("e"|"E") ("+"|"-")? <DIGITS>)?
-                          | <DIGITS> (("e"|"E") ("+"|"-")? <DIGITS>)
-                          | "." <DIGITS> (("e"|"E") ("+"|"-")? <DIGITS>)?
-    >
-  | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
-        | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
-        | "." <DIGITS> ( "f" | "F" )
-    >
-  | <DIGITS : (<DIGIT>)+ >
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <#LETTER : ["A" - "Z", "a" - "z"]>
-  | <SPECIALCHARS : ["$", "_", "-"]>
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    // backslash u + 4 hex digits escapes are handled in the underlying JavaCharStream
-    <STRING_LITERAL : ("\"" (
-          <EscapeQuot>
-        | <EscapeBslash>
-        | <EscapeSlash>
-        | <EscapeBspace>
-        | <EscapeFormf>
-        | <EscapeNl>
-        | <EscapeCr>
-        | <EscapeTab>
-        | ~["\"","\\"])* "\"")
-      | ("\'"(
-          <EscapeApos>
-        | <EscapeBslash>
-        | <EscapeSlash>
-        | <EscapeBspace>
-        | <EscapeFormf>
-        | <EscapeNl>
-        | <EscapeCr>
-        | <EscapeTab>
-        | ~["\'","\\"])* "\'")>
-  | < #EscapeQuot: "\\\"" >
-  | < #EscapeApos: "\\\'" >
-  | < #EscapeBslash: "\\\\" >
-  | < #EscapeSlash: "\\/" >
-  | < #EscapeBspace: "\\b" >
-  | < #EscapeFormf: "\\f" >
-  | < #EscapeNl: "\\n" >
-  | < #EscapeCr: "\\r" >
-  | < #EscapeTab: "\\t" >
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
-}
-
-<DEFAULT,IN_DBL_BRACE>
-TOKEN :
-{
-    <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
-}
-
-<DEFAULT,IN_DBL_BRACE>
-SKIP:
-{
-    " "
-  | "\t"
-  | "\r"
-  | "\n"
-}
-
-<DEFAULT,IN_DBL_BRACE>
-SKIP:
-{
-    <"//" (~["\n"])* "\n">
-}
-
-<DEFAULT,IN_DBL_BRACE>
-SKIP:
-{
-    <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
-}
-
-<DEFAULT,IN_DBL_BRACE>
-SKIP:
-{
-    <"/*"> { pushState(); } : INSIDE_COMMENT
-}
-
-<INSIDE_COMMENT>
-SPECIAL_TOKEN:
-{
-    <"+"(" ")*(~["*"])*>
-}
-
-<INSIDE_COMMENT>
-SKIP:
-{
-    <"/*"> { pushState(); }
-}
-
-<INSIDE_COMMENT>
-SKIP:
-{
-    <"*/"> { popState("*/"); }
-  | <~[]>
-}
diff --git a/asterixdb/asterix-tools/src/test/java/org/apache/asterix/tools/datagen/AdmDataGen.java b/asterixdb/asterix-tools/src/test/java/org/apache/asterix/tools/datagen/AdmDataGen.java
index 09a898a..aa86916 100644
--- a/asterixdb/asterix-tools/src/test/java/org/apache/asterix/tools/datagen/AdmDataGen.java
+++ b/asterixdb/asterix-tools/src/test/java/org/apache/asterix/tools/datagen/AdmDataGen.java
@@ -47,11 +47,10 @@
 import org.apache.asterix.common.annotations.UndeclaredFieldsDataGen;
 import org.apache.asterix.common.exceptions.ACIDException;
 import org.apache.asterix.common.transactions.TxnId;
-import org.apache.asterix.lang.aql.parser.AQLParserFactory;
-import org.apache.asterix.lang.aql.parser.ParseException;
 import org.apache.asterix.lang.common.base.IParser;
 import org.apache.asterix.lang.common.base.IParserFactory;
 import org.apache.asterix.lang.common.base.Statement;
+import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
 import org.apache.asterix.metadata.MetadataTransactionContext;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
@@ -928,14 +927,14 @@
     private Map<TypeSignature, IAType> typeMap;
     private Map<TypeSignature, TypeDataGen> typeAnnotMap;
     private DataGeneratorContext dgCtx;
-    private final IParserFactory parserFactory = new AQLParserFactory();
+    private final IParserFactory parserFactory = new SqlppParserFactory();
 
     public AdmDataGen(File schemaFile, File outputDir) {
         this.schemaFile = schemaFile;
         this.outputDir = outputDir;
     }
 
-    public void init() throws IOException, ParseException, ACIDException, AlgebricksException {
+    public void init() throws IOException, ACIDException, AlgebricksException {
         FileReader aql = new FileReader(schemaFile);
         IParser parser = parserFactory.createParser(aql);
         List<Statement> statements = parser.parse();
diff --git a/asterixdb/asterix-tools/src/test/java/org/apache/asterix/tools/test/AdmDataGenTest.java b/asterixdb/asterix-tools/src/test/java/org/apache/asterix/tools/test/AdmDataGenTest.java
deleted file mode 100644
index 8582f52..0000000
--- a/asterixdb/asterix-tools/src/test/java/org/apache/asterix/tools/test/AdmDataGenTest.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.tools.test;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.asterix.test.base.AsterixTestHelper;
-import org.apache.asterix.tools.datagen.AdmDataGen;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.junit.AfterClass;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-@RunWith(Parameterized.class)
-public class AdmDataGenTest {
-
-    private static final Logger LOGGER = LogManager.getLogger();
-
-    private static final String SEPARATOR = File.separator;
-    private static final String EXTENSION_QUERY = "adg";
-    private static final String FILENAME_IGNORE = "ignore.txt";
-    private static final String FILENAME_ONLY = "only.txt";
-    private static final String PATH_BASE =
-            "src" + SEPARATOR + "test" + SEPARATOR + "resources" + SEPARATOR + "adgts" + SEPARATOR;
-    private static final String PATH_QUERIES = PATH_BASE + "dgscripts" + SEPARATOR;
-    private static final String PATH_EXPECTED = PATH_BASE + "results" + SEPARATOR;
-    private static final String PATH_ACTUAL = "adgtest" + SEPARATOR;
-
-    private static final ArrayList<String> ignore = AsterixTestHelper.readTestListFile(FILENAME_IGNORE, PATH_BASE);
-    private static final ArrayList<String> only = AsterixTestHelper.readTestListFile(FILENAME_ONLY, PATH_BASE);
-
-    @BeforeClass
-    public static void setUp() throws Exception {
-        File outdir = new File(PATH_ACTUAL);
-        if (outdir.exists()) {
-            AsterixTestHelper.deleteRec(outdir);
-        }
-        outdir.mkdirs();
-    }
-
-    @AfterClass
-    public static void tearDown() throws Exception {
-        // _bootstrap.stop();
-        File outdir = new File(PATH_ACTUAL);
-        File[] files = outdir.listFiles();
-        if (files == null || files.length == 0) {
-            outdir.delete();
-        }
-    }
-
-    private static void suiteBuild(File dir, Collection<Object[]> testArgs, String path) {
-        for (File file : dir.listFiles()) {
-            if (file.isDirectory() && !file.getName().startsWith(".")) {
-                suiteBuild(file, testArgs, path + file.getName() + SEPARATOR);
-            }
-            if (file.isFile() && file.getName().endsWith(EXTENSION_QUERY)
-            // && !ignore.contains(path + file.getName())
-            ) {
-                File expectedDir = new File(PATH_EXPECTED + path);
-                File actualDir = new File(PATH_ACTUAL + SEPARATOR + path);
-                testArgs.add(new Object[] { file, expectedDir, actualDir });
-            }
-        }
-    }
-
-    @Parameters
-    public static Collection<Object[]> tests() {
-        Collection<Object[]> testArgs = new ArrayList<Object[]>();
-        suiteBuild(new File(PATH_QUERIES), testArgs, "");
-        return testArgs;
-    }
-
-    private File actualDir;
-    private File expectedDir;
-    private File scriptFile;
-
-    public AdmDataGenTest(File scriptFile, File expectedDir, File actualDir) {
-        this.scriptFile = scriptFile;
-        this.expectedDir = expectedDir;
-        this.actualDir = actualDir;
-    }
-
-    @Test
-    public void test() throws Exception {
-        String scriptFileShort =
-                scriptFile.getPath().substring(PATH_QUERIES.length()).replace(SEPARATOR.charAt(0), '/');
-        if (!only.isEmpty()) {
-            if (!only.contains(scriptFileShort)) {
-                LOGGER.info(
-                        "SKIP TEST: \"" + scriptFile.getPath() + "\" \"only.txt\" not empty and not in \"only.txt\".");
-            }
-            Assume.assumeTrue(only.contains(scriptFileShort));
-        }
-        if (ignore.contains(scriptFileShort)) {
-            LOGGER.info("SKIP TEST: \"" + scriptFile.getPath() + "\" in \"ignore.txt\".");
-        }
-        Assume.assumeTrue(!ignore.contains(scriptFileShort));
-
-        LOGGER.info("RUN TEST: \"" + scriptFile.getPath() + "\"");
-
-        actualDir.mkdirs();
-        AdmDataGen adg = new AdmDataGen(scriptFile, actualDir);
-        try {
-            adg.init();
-            adg.dataGen();
-        } catch (Exception e) {
-            throw new Exception("Data gen. ERROR for " + scriptFile + ": " + e.getMessage(), e);
-        }
-
-        if (!expectedDir.isDirectory()) {
-            throw new Exception(expectedDir + " is not a directory.");
-        }
-        if (!actualDir.isDirectory()) {
-            throw new Exception(expectedDir + " is not a directory.");
-        }
-
-        File[] expectedFileSet = expectedDir.listFiles(AdmFileFilter.INSTANCE);
-        File[] actualFileSet = actualDir.listFiles(AdmFileFilter.INSTANCE);
-
-        if (expectedFileSet.length != actualFileSet.length) {
-            throw new Exception("Expecting " + expectedFileSet.length + " files and found " + actualFileSet.length
-                    + " files instead.");
-        }
-
-        for (File expectedFile : expectedFileSet) {
-            if (expectedFile.isHidden()) {
-                continue;
-            }
-            File actualFile = null;
-            for (File f : actualFileSet) {
-                if (f.getName().equals(expectedFile.getName())) {
-                    actualFile = f;
-                    break;
-                }
-            }
-            if (actualFile == null) {
-                throw new Exception("Could not find file " + expectedFile.getName());
-            }
-
-            BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
-            BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
-
-            String lineExpected, lineActual;
-            int num = 1;
-            try {
-                while ((lineExpected = readerExpected.readLine()) != null) {
-                    lineActual = readerActual.readLine();
-                    // Assert.assertEquals(lineExpected, lineActual);
-                    if (lineActual == null) {
-                        throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< "
-                                + lineExpected + "\n> ");
-                    }
-                    if (!lineExpected.equals(lineActual)) {
-                        throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< "
-                                + lineExpected + "\n> " + lineActual);
-                    }
-                    ++num;
-                }
-                lineActual = readerActual.readLine();
-                // Assert.assertEquals(null, lineActual);
-                if (lineActual != null) {
-                    throw new Exception(
-                            "Result for " + scriptFile + " changed at line " + num + ":\n< \n> " + lineActual);
-                }
-            } finally {
-                readerExpected.close();
-                readerActual.close();
-            }
-        }
-        AsterixTestHelper.deleteRec(actualDir);
-    }
-
-    private static class AdmFileFilter implements FileFilter {
-
-        public static final AdmFileFilter INSTANCE = new AdmFileFilter();
-
-        private AdmFileFilter() {
-        }
-
-        @Override
-        public boolean accept(File path) {
-            if (path.isHidden() || !path.isFile()) {
-                return false;
-            }
-            return path.getName().endsWith(".adm");
-        }
-    }
-
-}