Merge release-0.8.9 branch into master

Change-Id: Id4353716267d45ce21580ac2856e6a751d05d1f8
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
index dc9ff17..d14b8e2 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
@@ -197,7 +197,7 @@
 import org.apache.asterix.runtime.evaluators.functions.NumericTruncDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.NumericUnaryMinusDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.OrDescriptor;
-import org.apache.asterix.runtime.evaluators.functions.OrderedListConstructorDescriptor;
+import org.apache.asterix.runtime.evaluators.constructors.OrderedListConstructorDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.PrefixLenJaccardDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.SimilarityJaccardCheckDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.SimilarityJaccardDescriptor;
@@ -244,7 +244,7 @@
 import org.apache.asterix.runtime.evaluators.functions.SubstringDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.SwitchCaseDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.UUIDDescriptor;
-import org.apache.asterix.runtime.evaluators.functions.UnorderedListConstructorDescriptor;
+import org.apache.asterix.runtime.evaluators.constructors.UnorderedListConstructorDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.WordTokensDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.binary.BinaryConcatDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.binary.BinaryLengthDescriptor;
diff --git a/asterixdb/asterix-app/pom.xml b/asterixdb/asterix-app/pom.xml
index 80f1320..f5cd6d9 100644
--- a/asterixdb/asterix-app/pom.xml
+++ b/asterixdb/asterix-app/pom.xml
@@ -307,6 +307,7 @@
       <groupId>com.e-movimento.tinytools</groupId>
       <artifactId>privilegedaccessor</artifactId>
       <version>1.2.2</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>commons-io</groupId>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
index 4140f9a..90a8599 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
@@ -35,7 +35,9 @@
 import org.apache.asterix.app.result.ResultUtil;
 import org.apache.asterix.common.config.CompilerProperties;
 import org.apache.asterix.common.config.ExternalProperties;
+import org.apache.asterix.common.config.IPropertyInterpreter;
 import org.apache.asterix.common.config.OptimizationConfUtil;
+import org.apache.asterix.common.config.PropertyInterpreters;
 import org.apache.asterix.common.exceptions.ACIDException;
 import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
@@ -59,9 +61,9 @@
 import org.apache.asterix.runtime.job.listener.JobEventListenerFactory;
 import org.apache.asterix.runtime.util.AppContextInfo;
 import org.apache.asterix.transaction.management.service.transaction.JobIdFactory;
+import org.apache.asterix.translator.SessionConfig;
 import org.apache.asterix.translator.CompiledStatements.ICompiledDmlStatement;
 import org.apache.asterix.translator.IStatementExecutor.Stats;
-import org.apache.asterix.translator.SessionConfig;
 import org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint;
 import org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -208,9 +210,13 @@
 
         CompilerProperties compilerProperties = AppContextInfo.INSTANCE.getCompilerProperties();
         int frameSize = compilerProperties.getFrameSize();
-        int sortFrameLimit = (int) (compilerProperties.getSortMemorySize() / frameSize);
-        int groupFrameLimit = (int) (compilerProperties.getGroupMemorySize() / frameSize);
-        int joinFrameLimit = (int) (compilerProperties.getJoinMemorySize() / frameSize);
+        Map<String, String> querySpecificConfig = metadataProvider.getConfig();
+        int sortFrameLimit = getFrameLimit(querySpecificConfig.get(CompilerProperties.COMPILER_SORTMEMORY_KEY),
+                compilerProperties.getSortMemorySize(), frameSize);
+        int groupFrameLimit = getFrameLimit(querySpecificConfig.get(CompilerProperties.COMPILER_GROUPMEMORY_KEY),
+                compilerProperties.getGroupMemorySize(), frameSize);
+        int joinFrameLimit = getFrameLimit(querySpecificConfig.get(CompilerProperties.COMPILER_JOINMEMORY_KEY),
+                compilerProperties.getJoinMemorySize(), frameSize);
         OptimizationConfUtil.getPhysicalOptimizationConfig().setFrameSize(frameSize);
         OptimizationConfUtil.getPhysicalOptimizationConfig().setMaxFramesExternalSort(sortFrameLimit);
         OptimizationConfUtil.getPhysicalOptimizationConfig().setMaxFramesExternalGroupBy(groupFrameLimit);
@@ -230,7 +236,8 @@
         builder.setMissableTypeComputer(MissableTypeComputer.INSTANCE);
         builder.setConflictingTypeResolver(ConflictingTypeResolver.INSTANCE);
 
-        int parallelism = compilerProperties.getParallelism();
+        int parallelism = getParallelism(querySpecificConfig.get(CompilerProperties.COMPILER_PARALLELISM_KEY),
+                compilerProperties.getParallelism());
         builder.setClusterLocations(parallelism == CompilerProperties.COMPILER_PARALLELISM_AS_STORAGE
                 ? metadataProvider.getClusterLocations() : getComputationLocations(clusterInfoCollector, parallelism));
 
@@ -404,4 +411,19 @@
             throw new AlgebricksException(e);
         }
     }
+
+    // Gets the frame limit.
+    private int getFrameLimit(String parameter, long memBudgetInConfiguration, int frameSize) {
+        IPropertyInterpreter<Long> longBytePropertyInterpreter = PropertyInterpreters.getLongBytePropertyInterpreter();
+        long memBudget = parameter == null ? memBudgetInConfiguration
+                : longBytePropertyInterpreter.interpret(parameter);
+        return (int) (memBudget / frameSize);
+    }
+
+    // Gets the parallelism parameter.
+    private int getParallelism(String parameter, int parallelismInConfiguration) {
+        IPropertyInterpreter<Integer> integerIPropertyInterpreter = PropertyInterpreters
+                .getIntegerPropertyInterpreter();
+        return parameter == null ? parallelismInConfiguration : integerIPropertyInterpreter.interpret(parameter);
+    }
 }
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/AQLAPIServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/FullAPIServlet.java
similarity index 93%
rename from asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/AQLAPIServlet.java
rename to asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/FullAPIServlet.java
index bbb9dde..0f86ec6 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/AQLAPIServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/FullAPIServlet.java
@@ -24,14 +24,14 @@
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.translator.IStatementExecutorFactory;
 
-public class AQLAPIServlet extends RESTAPIServlet {
+public class FullAPIServlet extends RESTAPIServlet {
 
     private static final long serialVersionUID = 1L;
     private static final String AQL_STMT_PARAM_NAME = "aql";
     private static final byte ALLOWED_CATEGORIES = Statement.Category.QUERY | Statement.Category.UPDATE
             | Statement.Category.DDL | Statement.Category.PROCEDURE;
 
-    public AQLAPIServlet(ILangCompilationProvider compilationProvider,
+    public FullAPIServlet(ILangCompilationProvider compilationProvider,
             IStatementExecutorFactory statementExecutorFactory) {
         super(compilationProvider, statementExecutorFactory);
     }
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalIndexingOperations.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalIndexingOperations.java
index 1a74e17..a2518ec 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalIndexingOperations.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/external/ExternalIndexingOperations.java
@@ -39,7 +39,7 @@
 import org.apache.asterix.common.ioopcallbacks.LSMBTreeWithBuddyIOOperationCallbackFactory;
 import org.apache.asterix.common.ioopcallbacks.LSMRTreeIOOperationCallbackFactory;
 import org.apache.asterix.common.transactions.IResourceFactory;
-import org.apache.asterix.dataflow.data.nontagged.valueproviders.AqlPrimitiveValueProviderFactory;
+import org.apache.asterix.dataflow.data.nontagged.valueproviders.PrimitiveValueProviderFactory;
 import org.apache.asterix.external.api.IAdapterFactory;
 import org.apache.asterix.external.indexing.ExternalFile;
 import org.apache.asterix.external.indexing.FilesIndexDescription;
@@ -601,7 +601,7 @@
             secondaryComparatorFactories[i] = BinaryComparatorFactoryProvider.INSTANCE
                     .getBinaryComparatorFactory(nestedKeyType, true);
             secondaryTypeTraits[i] = TypeTraitProvider.INSTANCE.getTypeTrait(nestedKeyType);
-            valueProviderFactories[i] = AqlPrimitiveValueProviderFactory.INSTANCE;
+            valueProviderFactories[i] = PrimitiveValueProviderFactory.INSTANCE;
         }
         // Add serializers and comparators for primary index fields.
         for (int i = 0; i < numPrimaryKeys; i++) {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/file/SecondaryIndexOperationsHelper.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/file/SecondaryIndexOperationsHelper.java
index 78e0679..c362e2e 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/file/SecondaryIndexOperationsHelper.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/file/SecondaryIndexOperationsHelper.java
@@ -402,7 +402,7 @@
 
     protected AlgebricksMetaOperatorDescriptor createCastOp(JobSpecification spec, DatasetType dsType) {
         CastTypeDescriptor castFuncDesc = (CastTypeDescriptor) CastTypeDescriptor.FACTORY.createFunctionDescriptor();
-        castFuncDesc.reset(enforcedItemType, itemType);
+        castFuncDesc.setImmutableStates(enforcedItemType, itemType);
 
         int[] outColumns = new int[1];
         int[] projectionList = new int[(dataset.hasMetaPart() ? 2 : 1) + numPrimaryKeys];
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/file/SecondaryRTreeOperationsHelper.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/file/SecondaryRTreeOperationsHelper.java
index d6352b7..c96ba4c 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/file/SecondaryRTreeOperationsHelper.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/file/SecondaryRTreeOperationsHelper.java
@@ -31,7 +31,7 @@
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.common.ioopcallbacks.LSMRTreeIOOperationCallbackFactory;
 import org.apache.asterix.common.transactions.IResourceFactory;
-import org.apache.asterix.dataflow.data.nontagged.valueproviders.AqlPrimitiveValueProviderFactory;
+import org.apache.asterix.dataflow.data.nontagged.valueproviders.PrimitiveValueProviderFactory;
 import org.apache.asterix.external.indexing.IndexingConstants;
 import org.apache.asterix.external.operators.ExternalDataScanOperatorDescriptor;
 import org.apache.asterix.formats.nontagged.BinaryComparatorFactoryProvider;
@@ -212,7 +212,7 @@
             secondaryComparatorFactories[i] =
                     BinaryComparatorFactoryProvider.INSTANCE.getBinaryComparatorFactory(nestedKeyType, true);
             secondaryTypeTraits[i] = TypeTraitProvider.INSTANCE.getTypeTrait(nestedKeyType);
-            valueProviderFactories[i] = AqlPrimitiveValueProviderFactory.INSTANCE;
+            valueProviderFactories[i] = PrimitiveValueProviderFactory.INSTANCE;
 
         }
         // Add serializers and comparators for primary index fields.
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java
index 25a5418..19c00db 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java
@@ -30,7 +30,7 @@
 
 import org.apache.asterix.active.ActiveLifecycleListener;
 import org.apache.asterix.api.http.servlet.APIServlet;
-import org.apache.asterix.api.http.servlet.AQLAPIServlet;
+import org.apache.asterix.api.http.servlet.FullAPIServlet;
 import org.apache.asterix.api.http.servlet.ClusterAPIServlet;
 import org.apache.asterix.api.http.servlet.ClusterCCDetailsAPIServlet;
 import org.apache.asterix.api.http.servlet.ClusterNodeDetailsAPIServlet;
@@ -261,7 +261,7 @@
     protected Servlet createServlet(Servlets key) {
         switch (key) {
             case AQL:
-                return new AQLAPIServlet(ccExtensionManager.getAqlCompilationProvider(),
+                return new FullAPIServlet(ccExtensionManager.getAqlCompilationProvider(),
                         ccExtensionManager.getQueryTranslatorFactory());
             case AQL_QUERY:
                 return new QueryAPIServlet(ccExtensionManager.getAqlCompilationProvider(),
@@ -273,7 +273,7 @@
                 return new DDLAPIServlet(ccExtensionManager.getAqlCompilationProvider(),
                         ccExtensionManager.getQueryTranslatorFactory());
             case SQLPP:
-                return new AQLAPIServlet(ccExtensionManager.getSqlppCompilationProvider(),
+                return new FullAPIServlet(ccExtensionManager.getSqlppCompilationProvider(),
                         ccExtensionManager.getQueryTranslatorFactory());
             case SQLPP_QUERY:
                 return new QueryAPIServlet(ccExtensionManager.getSqlppCompilationProvider(),
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.2.update.aql
index f384e96..39842e4 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.2.update.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.2.update.aql
@@ -26,8 +26,8 @@
 use dataverse testdv2;
 
 
-set hash_merge "true"
+set "compiler.sortmemory" "64MB"
 
 load dataset testds
 using localfs
-(("path"="asterix_nc1://target/data/big-object/big_object_20M.adm"),("format"="adm")) pre-sorted;
+(("path"="asterix_nc1://target/data/big-object/big_object_20M.adm"),("format"="adm"));
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.1.ddl.sqlpp
similarity index 67%
copy from asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.1.ddl.sqlpp
index b17fc20..e81fa19 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.1.ddl.sqlpp
@@ -16,17 +16,21 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+/*
+ * Test case Name  : big_object_bulkload.aql
+ * Description     : bulkload insert of large objects
+ * Expected Result : Success
+ * Date            : 20th April 2016
+ */
 
-package org.apache.asterix.metadata.declared;
+drop dataverse testdv2 if exists;
+create dataverse testdv2;
+use testdv2;
 
-public class AqlMetadataImplConfig {
-    private final boolean useInstantLock;
-
-    public AqlMetadataImplConfig(boolean useInstantLock) {
-        this.useInstantLock = useInstantLock;
-    }
-
-    public boolean isInstantLock() {
-        return useInstantLock;
-    }
+create type testtype as closed {
+  id: int64,
+  name: string,
+  hobbies: {{string}}
 }
+
+create dataset testds(testtype) primary key id;
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.2.update.sqlpp
similarity index 71%
rename from asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
rename to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.2.update.sqlpp
index b17fc20..09f3a69 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.2.update.sqlpp
@@ -16,17 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+/**
+ *
+ * Big object (20 MB) loading test
+ * Expected result: success
+ *
+ */
 
-package org.apache.asterix.metadata.declared;
+use testdv2;
 
-public class AqlMetadataImplConfig {
-    private final boolean useInstantLock;
+set `compiler.sortmemory` "64MB"
 
-    public AqlMetadataImplConfig(boolean useInstantLock) {
-        this.useInstantLock = useInstantLock;
-    }
-
-    public boolean isInstantLock() {
-        return useInstantLock;
-    }
-}
+load dataset testds
+using localfs
+(("path"="asterix_nc1://target/data/big-object/big_object_20M.adm"),("format"="adm"));
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.3.query.sqlpp
similarity index 71%
copy from asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.3.query.sqlpp
index b17fc20..4730ac8 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/big-object/big_object_load_20M/big_object_load_20M.3.query.sqlpp
@@ -17,16 +17,8 @@
  * under the License.
  */
 
-package org.apache.asterix.metadata.declared;
+use testdv2;
 
-public class AqlMetadataImplConfig {
-    private final boolean useInstantLock;
-
-    public AqlMetadataImplConfig(boolean useInstantLock) {
-        this.useInstantLock = useInstantLock;
-    }
-
-    public boolean isInstantLock() {
-        return useInstantLock;
-    }
-}
+select value d
+from testds d
+where d.id=1;
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/like/like.1.query.sqlpp
similarity index 71%
copy from asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/like/like.1.query.sqlpp
index b17fc20..d6a1408 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/comparison/like/like.1.query.sqlpp
@@ -17,16 +17,4 @@
  * under the License.
  */
 
-package org.apache.asterix.metadata.declared;
-
-public class AqlMetadataImplConfig {
-    private final boolean useInstantLock;
-
-    public AqlMetadataImplConfig(boolean useInstantLock) {
-        this.useInstantLock = useInstantLock;
-    }
-
-    public boolean isInstantLock() {
-        return useInstantLock;
-    }
-}
+SELECT VALUE "ab"||"c" LIKE "%c" = TRUE;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.1.ddl.sqlpp
new file mode 100644
index 0000000..92698ab
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.1.ddl.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+drop  dataverse tpch if exists;
+create  dataverse tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : bigint,
+  l_partkey : bigint,
+  l_suppkey : bigint,
+  l_linenumber : bigint,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create  dataset LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.2.update.sqlpp
similarity index 71%
copy from asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.2.update.sqlpp
index b17fc20..5fe734c 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataImplConfig.java
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.2.update.sqlpp
@@ -17,16 +17,8 @@
  * under the License.
  */
 
-package org.apache.asterix.metadata.declared;
+use tpch;
 
-public class AqlMetadataImplConfig {
-    private final boolean useInstantLock;
 
-    public AqlMetadataImplConfig(boolean useInstantLock) {
-        this.useInstantLock = useInstantLock;
-    }
+load  dataset LineItem using localfs ((`path`=`asterix_nc1://data/tpch0.001/lineitem.tbl`),(`format`=`delimited-text`),(`delimiter`=`|`)) pre-sorted;
 
-    public boolean isInstantLock() {
-        return useInstantLock;
-    }
-}
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.3.query.sqlpp
new file mode 100644
index 0000000..a4876a2d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/tpch-sql-sugar/q01_pricing_summary_report_parallelism/q01_pricing_summary_report_parallelism.3.query.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+USE tpch;
+
+SET `compiler.parallelism` "5"
+
+SELECT  l_returnflag,
+        l_linestatus,
+        sum(l_quantity) AS sum_qty,
+        sum(l_extendedprice) AS sum_base_price,
+        sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price,
+        sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,
+        avg(l_quantity) AS ave_qty,
+        avg(l_extendedprice) AS ave_price,
+        avg(l_discount) AS ave_disc,
+        count(1) AS count_order
+FROM  LineItem
+WHERE l_shipdate <= '1998-09-02'
+/* +hash */
+GROUP BY l_returnflag, l_linestatus
+ORDER BY l_returnflag, l_linestatus
+;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/like/like.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/like/like.1.adm
new file mode 100644
index 0000000..f32a580
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/comparison/like/like.1.adm
@@ -0,0 +1 @@
+true
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 0aaf8c3..e5c5bdd 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1063,6 +1063,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="comparison">
+      <compilation-unit name="like">
+        <output-dir compare="Text">like</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="comparison">
       <compilation-unit name="lt_01">
         <output-dir compare="Text">lt_01</output-dir>
       </compilation-unit>
@@ -6822,6 +6827,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="tpch-sql-sugar">
+      <compilation-unit name="q01_pricing_summary_report_parallelism">
+        <output-dir compare="Text">q01_pricing_summary_report_nt</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="tpch-sql-sugar">
       <compilation-unit name="q20_potential_part_promotion">
         <output-dir compare="Text">q20_potential_part_promotion</output-dir>
       </compilation-unit>
@@ -7824,6 +7834,11 @@
         <output-dir compare="Text">big_object_join</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="big-object">
+      <compilation-unit name="big_object_load_20M">
+        <output-dir compare="Text">big_object_load_20M</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="external-indexing">
     <test-case FilePath="external-indexing">
diff --git a/asterixdb/asterix-client-helper/pom.xml b/asterixdb/asterix-client-helper/pom.xml
index 02d3f9a..be9693f 100644
--- a/asterixdb/asterix-client-helper/pom.xml
+++ b/asterixdb/asterix-client-helper/pom.xml
@@ -134,6 +134,34 @@
         </configuration>
       </plugin>
     </plugins>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.eclipse.m2e</groupId>
+          <artifactId>lifecycle-mapping</artifactId>
+          <version>1.0.0</version>
+          <configuration>
+            <lifecycleMappingMetadata>
+              <pluginExecutions>
+                <pluginExecution>
+                  <pluginExecutionFilter>
+                    <groupId>org.apache.hyracks</groupId>
+                    <artifactId>license-automation-plugin</artifactId>
+                    <versionRange>${hyracks.version}</versionRange>
+                    <goals>
+                      <goal>generate</goal>
+                    </goals>
+                  </pluginExecutionFilter>
+                  <action>
+                    <ignore />
+                  </action>
+                </pluginExecution>
+              </pluginExecutions>
+            </lifecycleMappingMetadata>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
   </build>
   <dependencies>
     <dependency>
diff --git a/asterixdb/asterix-common/pom.xml b/asterixdb/asterix-common/pom.xml
index b27cfde..277f94a 100644
--- a/asterixdb/asterix-common/pom.xml
+++ b/asterixdb/asterix-common/pom.xml
@@ -311,6 +311,10 @@
       <groupId>org.apache.hyracks</groupId>
       <artifactId>hyracks-data-std</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-annotations</artifactId>
+    </dependency>
   </dependencies>
 
 </project>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java
index 4e18bde..3710e54b0 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/config/CompilerProperties.java
@@ -25,19 +25,19 @@
 
 public class CompilerProperties extends AbstractProperties {
 
-    private static final String COMPILER_SORTMEMORY_KEY = "compiler.sortmemory";
+    public static final String COMPILER_SORTMEMORY_KEY = "compiler.sortmemory";
     private static final long COMPILER_SORTMEMORY_DEFAULT = StorageUtil.getSizeInBytes(32, MEGABYTE);
 
-    private static final String COMPILER_GROUPMEMORY_KEY = "compiler.groupmemory";
+    public static final String COMPILER_GROUPMEMORY_KEY = "compiler.groupmemory";
     private static final long COMPILER_GROUPMEMORY_DEFAULT = StorageUtil.getSizeInBytes(32, MEGABYTE);
 
-    private static final String COMPILER_JOINMEMORY_KEY = "compiler.joinmemory";
+    public static final String COMPILER_JOINMEMORY_KEY = "compiler.joinmemory";
     private static final long COMPILER_JOINMEMORY_DEFAULT = StorageUtil.getSizeInBytes(32, MEGABYTE);
 
     private static final String COMPILER_FRAMESIZE_KEY = "compiler.framesize";
     private static final int COMPILER_FRAMESIZE_DEFAULT = StorageUtil.getSizeInBytes(32, KILOBYTE);
 
-    private static final String COMPILER_PARALLELISM_KEY = "compiler.parallelism";
+    public static final String COMPILER_PARALLELISM_KEY = "compiler.parallelism";
     public static final int COMPILER_PARALLELISM_AS_STORAGE = 0;
 
     private static final String COMPILER_PREGELIX_HOME = "compiler.pregelix.home";
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java
index 8bbdab7..a74898e 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Checkpoint.java
@@ -18,11 +18,16 @@
  */
 package org.apache.asterix.common.transactions;
 
-import java.io.Serializable;
+import java.io.IOException;
 
-public class Checkpoint implements Serializable, Comparable<Checkpoint> {
+import org.apache.hyracks.api.exceptions.HyracksDataException;
 
-    private static final long serialVersionUID = 1L;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class Checkpoint implements Comparable<Checkpoint> {
 
     private final long checkpointLsn;
     private final long minMCTFirstLsn;
@@ -31,8 +36,11 @@
     private final boolean sharp;
     private final int storageVersion;
 
-    public Checkpoint(long checkpointLsn, long minMCTFirstLsn, int maxJobId, long timeStamp, boolean sharp,
-            int storageVersion) {
+    @JsonCreator
+    public Checkpoint(@JsonProperty("checkpointLsn") long checkpointLsn,
+            @JsonProperty("minMCTFirstLsn") long minMCTFirstLsn, @JsonProperty("maxJobId") int maxJobId,
+            @JsonProperty("timeStamp") long timeStamp, @JsonProperty("sharp") boolean sharp,
+            @JsonProperty("storageVersion") int storageVersion) {
         this.checkpointLsn = checkpointLsn;
         this.minMCTFirstLsn = minMCTFirstLsn;
         this.maxJobId = maxJobId;
@@ -107,4 +115,20 @@
         result = prime * result + (int) (timeStamp ^ (timeStamp >>> 32));
         return result;
     }
-}
+
+    public String asJson() throws HyracksDataException {
+        try {
+            return new ObjectMapper().writeValueAsString(this);
+        } catch (JsonProcessingException e) {
+            throw new HyracksDataException(e);
+        }
+    }
+
+    public static Checkpoint fromJson(String json) throws HyracksDataException {
+        try {
+            return new ObjectMapper().readValue(json, Checkpoint.class);
+        } catch (IOException e) {
+            throw new HyracksDataException(e);
+        }
+    }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-installer/pom.xml b/asterixdb/asterix-installer/pom.xml
index 2cfabf1..efd1106 100644
--- a/asterixdb/asterix-installer/pom.xml
+++ b/asterixdb/asterix-installer/pom.xml
@@ -282,9 +282,9 @@
               <pluginExecutions>
                 <pluginExecution>
                   <pluginExecutionFilter>
-                    <groupId>org.apache.asterix</groupId>
+                    <groupId>org.apache.hyracks</groupId>
                     <artifactId>license-automation-plugin</artifactId>
-                    <versionRange>${project.version}</versionRange>
+                    <versionRange>${hyracks.version}</versionRange>
                     <goals>
                       <goal>generate</goal>
                     </goals>
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 047fcc4..81f00ee 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -1828,7 +1828,7 @@
     operand = BetweenExpr()
 
     (
-      LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> | <LG> |<SIMILAR> | (<NOT> { not = true; })? (<LIKE>|<IN>))
+      LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> | <LG> |<SIMILAR> | (<NOT> { not = true; })? <IN>)
         {
           String mhint = getHint(token);
           if (mhint != null) {
@@ -1874,6 +1874,7 @@
      }
 }
 
+
 Expression BetweenExpr()throws ParseException:
 {
   boolean not = false;
@@ -1938,7 +1939,7 @@
     boolean not = false;
 }
 {
-    operand = ConcatExpr()
+    operand = LikeExpr()
     ( <IS> (<NOT> { not = true; })? (<NULL> | <MISSING> | <UNKOWN>)
       {
         String functionName = "is-" + token.image.toLowerCase();
@@ -1955,6 +1956,45 @@
     }
 }
 
+
+Expression LikeExpr()throws ParseException:
+{
+  boolean not = false;
+  OperatorExpr op = null;
+  Expression operand = null;
+}
+{
+    operand = ConcatExpr()
+    (
+        LOOKAHEAD(2)
+        (<NOT> { not = true; })? <LIKE>
+        {
+          op = new OperatorExpr();
+          op.addOperand(operand);
+          op.setCurrentop(true);
+
+          String operator = token.image.toLowerCase();
+          if (not) {
+            operator = "not_" + operator;
+          }
+          try{
+            op.addOperator(operator);
+          } catch (CompilationException e){
+            throw new ParseException(e.getMessage());
+          }
+        }
+
+        operand = ConcatExpr()
+        {
+          op.addOperand(operand);
+        }
+     )?
+
+     {
+       return op == null ? operand : op;
+     }
+}
+
 Expression ConcatExpr()throws ParseException:
 {
   OperatorExpr op = null;
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlLogicalPlanAndMetadataImpl.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlLogicalPlanAndMetadataImpl.java
deleted file mode 100644
index 39e2781..0000000
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlLogicalPlanAndMetadataImpl.java
+++ /dev/null
@@ -1,50 +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.metadata.declared;
-
-import org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint;
-import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan;
-import org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlanAndMetadata;
-
-public class AqlLogicalPlanAndMetadataImpl implements ILogicalPlanAndMetadata {
-
-    private ILogicalPlan plan;
-    private MetadataProvider metadataProvider;
-
-    public AqlLogicalPlanAndMetadataImpl(ILogicalPlan plan, MetadataProvider metadataProvider) {
-        this.plan = plan;
-        this.metadataProvider = metadataProvider;
-    }
-
-    @Override
-    public ILogicalPlan getPlan() {
-        return plan;
-    }
-
-    @Override
-    public MetadataProvider getMetadataProvider() {
-        return metadataProvider;
-    }
-
-    @Override
-    public AlgebricksPartitionConstraint getClusterLocations() {
-        return metadataProvider.getClusterLocations();
-    }
-}
diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
index 26706c6..bd991fc 100644
--- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
+++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/MetadataProvider.java
@@ -47,7 +47,7 @@
 import org.apache.asterix.common.transactions.IRecoveryManager.ResourceType;
 import org.apache.asterix.common.transactions.JobId;
 import org.apache.asterix.common.utils.StoragePathUtil;
-import org.apache.asterix.dataflow.data.nontagged.valueproviders.AqlPrimitiveValueProviderFactory;
+import org.apache.asterix.dataflow.data.nontagged.valueproviders.PrimitiveValueProviderFactory;
 import org.apache.asterix.external.adapter.factory.LookupAdapterFactory;
 import org.apache.asterix.external.api.IAdapterFactory;
 import org.apache.asterix.external.api.IDataSourceAdapter;
@@ -632,7 +632,7 @@
             IPrimitiveValueProviderFactory[] valueProviderFactories =
                     new IPrimitiveValueProviderFactory[numNestedSecondaryKeyFields];
             for (int i = 0; i < numNestedSecondaryKeyFields; i++) {
-                valueProviderFactories[i] = AqlPrimitiveValueProviderFactory.INSTANCE;
+                valueProviderFactories[i] = PrimitiveValueProviderFactory.INSTANCE;
             }
 
             RecordDescriptor outputRecDesc = JobGenHelper.mkRecordDescriptor(typeEnv, opSchema, context);
@@ -1729,7 +1729,7 @@
                 comparatorFactories[i] = BinaryComparatorFactoryProvider.INSTANCE
                         .getBinaryComparatorFactory(nestedKeyType, true);
                 typeTraits[i] = TypeTraitProvider.INSTANCE.getTypeTrait(nestedKeyType);
-                valueProviderFactories[i] = AqlPrimitiveValueProviderFactory.INSTANCE;
+                valueProviderFactories[i] = PrimitiveValueProviderFactory.INSTANCE;
             }
             List<List<String>> partitioningKeys = DatasetUtils.getPartitioningKeys(dataset);
             for (List<String> partitioningKey : partitioningKeys) {
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/valueproviders/AqlPrimitiveValueProviderFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/valueproviders/PrimitiveValueProviderFactory.java
similarity index 85%
rename from asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/valueproviders/AqlPrimitiveValueProviderFactory.java
rename to asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/valueproviders/PrimitiveValueProviderFactory.java
index 6944708..62f3312 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/valueproviders/AqlPrimitiveValueProviderFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/valueproviders/PrimitiveValueProviderFactory.java
@@ -27,13 +27,13 @@
 import org.apache.hyracks.storage.am.rtree.impls.FloatPrimitiveValueProviderFactory;
 import org.apache.hyracks.storage.am.rtree.impls.IntegerPrimitiveValueProviderFactory;
 
-public class AqlPrimitiveValueProviderFactory implements IPrimitiveValueProviderFactory {
+public class PrimitiveValueProviderFactory implements IPrimitiveValueProviderFactory {
 
     private static final long serialVersionUID = 1L;
 
-    public static final AqlPrimitiveValueProviderFactory INSTANCE = new AqlPrimitiveValueProviderFactory();
+    public static final PrimitiveValueProviderFactory INSTANCE = new PrimitiveValueProviderFactory();
 
-    private AqlPrimitiveValueProviderFactory() {
+    private PrimitiveValueProviderFactory() {
     }
 
     @Override
@@ -48,21 +48,16 @@
 
             @Override
             public double getValue(byte[] bytes, int offset) {
-
                 ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
                 switch (tag) {
-                    case INT32: {
+                    case INT32:
                         return intProvider.getValue(bytes, offset + 1);
-                    }
-                    case FLOAT: {
+                    case FLOAT:
                         return floatProvider.getValue(bytes, offset + 1);
-                    }
-                    case DOUBLE: {
+                    case DOUBLE:
                         return doubleProvider.getValue(bytes, offset + 1);
-                    }
-                    default: {
+                    default:
                         throw new NotImplementedException("Value provider for type " + tag + " is not implemented");
-                    }
                 }
             }
         };
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/IFunctionDescriptor.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/IFunctionDescriptor.java
index 322adda..d9bb73a 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/IFunctionDescriptor.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/IFunctionDescriptor.java
@@ -30,22 +30,26 @@
 import org.apache.hyracks.algebricks.runtime.base.IUnnestingEvaluatorFactory;
 
 public interface IFunctionDescriptor extends Serializable {
-    public FunctionIdentifier getIdentifier();
 
-    public FunctionDescriptorTag getFunctionDescriptorTag();
+    default void setImmutableStates(Object... states) {
+    }
 
-    public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) throws AlgebricksException;
+    FunctionIdentifier getIdentifier();
 
-    public IRunningAggregateEvaluatorFactory createRunningAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+    FunctionDescriptorTag getFunctionDescriptorTag();
+
+    IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) throws AlgebricksException;
+
+    IRunningAggregateEvaluatorFactory createRunningAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args)
             throws AlgebricksException;
 
-    public ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
+    ISerializedAggregateEvaluatorFactory createSerializableAggregateEvaluatorFactory(
             final IScalarEvaluatorFactory[] args) throws AlgebricksException;
 
-    public IUnnestingEvaluatorFactory createUnnestingEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+    IUnnestingEvaluatorFactory createUnnestingEvaluatorFactory(final IScalarEvaluatorFactory[] args)
             throws AlgebricksException;
 
-    public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args)
+    IAggregateEvaluatorFactory createAggregateEvaluatorFactory(final IScalarEvaluatorFactory[] args)
             throws AlgebricksException;
 
 }
diff --git a/asterixdb/asterix-runtime/pom.xml b/asterixdb/asterix-runtime/pom.xml
index dd9c3af..1ccdc76 100644
--- a/asterixdb/asterix-runtime/pom.xml
+++ b/asterixdb/asterix-runtime/pom.xml
@@ -137,11 +137,6 @@
       <version>5.1</version>
     </dependency>
     <dependency>
-      <groupId>com.e-movimento.tinytools</groupId>
-      <artifactId>privilegedaccessor</artifactId>
-      <version>1.2.2</version>
-    </dependency>
-    <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-databind</artifactId>
     </dependency>
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/collections/ListifyAggregateDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/collections/ListifyAggregateDescriptor.java
index 54f598d..f117d14 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/collections/ListifyAggregateDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/aggregates/collections/ListifyAggregateDescriptor.java
@@ -39,8 +39,9 @@
 
     private AOrderedListType oltype;
 
-    public void reset(AOrderedListType orderedListType) {
-        this.oltype = orderedListType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.oltype = (AOrderedListType) states[0];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ClosedRecordConstructorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ClosedRecordConstructorDescriptor.java
index 57d50fd..5cac892 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ClosedRecordConstructorDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/ClosedRecordConstructorDescriptor.java
@@ -39,8 +39,9 @@
 
     private ARecordType recType;
 
-    public void reset(ARecordType recType) {
-        this.recType = recType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.recType = (ARecordType) states[0];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
index 24cb5e3..0b26583 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OpenRecordConstructorDescriptor.java
@@ -50,9 +50,10 @@
     private ARecordType recType;
     private boolean[] openFields;
 
-    public void reset(ARecordType recType, boolean[] openFields) {
-        this.recType = recType;
-        this.openFields = openFields;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.recType = (ARecordType) states[0];
+        this.openFields = (boolean[]) states[1];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OrderedListConstructorDescriptor.java
similarity index 95%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
rename to asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OrderedListConstructorDescriptor.java
index a9cb442..977101a 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/OrderedListConstructorDescriptor.java
@@ -7,7 +7,7 @@
  * "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
+ *    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
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.asterix.runtime.evaluators.functions;
+package org.apache.asterix.runtime.evaluators.constructors;
 
 import java.io.DataOutput;
 import java.io.IOException;
@@ -50,8 +50,9 @@
 
     private AOrderedListType oltype;
 
-    public void reset(AOrderedListType orderedListType) {
-        this.oltype = orderedListType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.oltype = (AOrderedListType) states[0];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/UnorderedListConstructorDescriptor.java
similarity index 95%
rename from asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
rename to asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/UnorderedListConstructorDescriptor.java
index 076a789..50b7699 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/UnorderedListConstructorDescriptor.java
@@ -7,7 +7,7 @@
  * "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
+ *    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
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.asterix.runtime.evaluators.functions;
+package org.apache.asterix.runtime.evaluators.constructors;
 
 import java.io.DataOutput;
 import java.io.IOException;
@@ -25,6 +25,7 @@
 import org.apache.asterix.om.functions.BuiltinFunctions;
 import org.apache.asterix.om.functions.IFunctionDescriptor;
 import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.AUnorderedListType;
 import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
@@ -50,8 +51,9 @@
 
     private AUnorderedListType ultype;
 
-    public void reset(AUnorderedListType unorderedListType) {
-        this.ultype = unorderedListType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.ultype = (AUnorderedListType) states[0];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastTypeDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastTypeDescriptor.java
index aa276cc..95eaac6 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastTypeDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/CastTypeDescriptor.java
@@ -62,7 +62,10 @@
     private CastTypeDescriptor() {
     }
 
-    public void reset(IAType reqType, IAType inputType) {
+    @Override
+    public void setImmutableStates(Object... states) {
+        reqType = (IAType) states[0];
+        inputType = (IAType) states[1];
         // If reqType or inputType is null, or they are the same, it indicates there is a bug in the compiler.
         if (reqType == null || inputType == null || reqType.equals(inputType)) {
             throw new IllegalStateException(
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/DeepEqualityDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/DeepEqualityDescriptor.java
index bb6efb8..150c28e 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/DeepEqualityDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/DeepEqualityDescriptor.java
@@ -54,11 +54,13 @@
     private IAType inputTypeLeft;
     private IAType inputTypeRight;
 
-    public void reset(IAType inTypeLeft, IAType inTypeRight) {
-        this.inputTypeLeft = inTypeLeft;
-        this.inputTypeRight = inTypeRight;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.inputTypeLeft = (IAType) states[0];
+        this.inputTypeRight = (IAType) states[1];
     }
 
+
     @Override
     public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
         final IScalarEvaluatorFactory evalFactoryLeft = args[0];
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java
index 859d8c3..7ce7dec 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessByIndexDescriptor.java
@@ -37,8 +37,9 @@
 
     private ARecordType recType;
 
-    public void reset(ARecordType recType) {
-        this.recType = recType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.recType = (ARecordType) states[0];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedDescriptor.java
index cf8a781..95b06f7 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/FieldAccessNestedDescriptor.java
@@ -40,9 +40,10 @@
     private ARecordType recType;
     private List<String> fldName;
 
-    public void reset(ARecordType recType, List<String> fldName) {
-        this.recType = recType;
-        this.fldName = fldName;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.recType = (ARecordType) states[0];
+        this.fldName = (List<String>) states[1];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueDescriptor.java
index 97d92fd..3419b68 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldValueDescriptor.java
@@ -37,8 +37,9 @@
 
     private ARecordType recType;
 
-    public void reset(ARecordType recType) {
-        this.recType = recType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.recType = (ARecordType) states[0];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsDescriptor.java
index 98fc8ed..6205d77 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/GetRecordFieldsDescriptor.java
@@ -37,8 +37,9 @@
 
     private ARecordType recType;
 
-    public void reset(ARecordType recType) {
-        this.recType = recType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.recType = (ARecordType) states[0];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java
index 5f2a730..8d4f8c2 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordAddFieldsDescriptor.java
@@ -74,10 +74,11 @@
     private AOrderedListType inListType;
     private IAType inputFieldListItemType;
 
-    public void reset(IAType outType, IAType inType0, IAType inType1) {
-        outRecType = TypeComputeUtils.extractRecordType(outType);
-        inRecType = TypeComputeUtils.extractRecordType(inType0);
-        inListType = TypeComputeUtils.extractOrderedListType(inType1);
+    @Override
+    public void setImmutableStates(Object... states) {
+        outRecType = TypeComputeUtils.extractRecordType((IAType) states[0]);
+        inRecType = TypeComputeUtils.extractRecordType((IAType) states[1]);
+        inListType = TypeComputeUtils.extractOrderedListType((IAType) states[2]);
         inputFieldListItemType = inListType.getItemType();
         if (inputFieldListItemType == null || inputFieldListItemType.getTypeTag() == ATypeTag.ANY) {
             inputFieldListItemType = DefaultOpenFieldType.NESTED_OPEN_RECORD_TYPE;
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
index 7a1e69f..650581b 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordMergeDescriptor.java
@@ -74,10 +74,11 @@
     private ARecordType inRecType0;
     private ARecordType inRecType1;
 
-    public void reset(IAType outType, IAType inType0, IAType inType1) {
-        outRecType = TypeComputeUtils.extractRecordType(outType);
-        inRecType0 = TypeComputeUtils.extractRecordType(inType0);
-        inRecType1 = TypeComputeUtils.extractRecordType(inType1);
+    @Override
+    public void setImmutableStates(Object... states) {
+        outRecType = TypeComputeUtils.extractRecordType((IAType) states[0]);
+        inRecType0 = TypeComputeUtils.extractRecordType((IAType) states[1]);
+        inRecType1 = TypeComputeUtils.extractRecordType((IAType) states[2]);
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java
index 09b644a..8ecdca7 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordPairsDescriptor.java
@@ -58,8 +58,9 @@
     private static final long serialVersionUID = 1L;
     private ARecordType recType;
 
-    public void reset(ARecordType recType) {
-        this.recType = recType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        this.recType = (ARecordType) states[0];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java
index 8550a9b..092fbfb 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/functions/records/RecordRemoveFieldsDescriptor.java
@@ -44,10 +44,11 @@
     private ARecordType inputRecType;
     private AOrderedListType inputListType;
 
-    public void reset(IAType outType, IAType inType, IAType inListType) {
-        outputRecordType = (ARecordType) outType;
-        inputRecType = (ARecordType) inType;
-        inputListType = (AOrderedListType) inListType;
+    @Override
+    public void setImmutableStates(Object... states) {
+        outputRecordType = (ARecordType) states[0];
+        inputRecType = (ARecordType) states[1];
+        inputListType = (AOrderedListType) states[2];
     }
 
     @Override
diff --git a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
index 00a147c..ad43a48 100644
--- a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
+++ b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/formats/NonTaggedDataFormat.java
@@ -55,20 +55,13 @@
 import org.apache.asterix.om.functions.IFunctionManager;
 import org.apache.asterix.om.pointables.base.DefaultOpenFieldType;
 import org.apache.asterix.om.typecomputer.base.TypeCastUtils;
-import org.apache.asterix.om.types.AOrderedListType;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.AUnionType;
-import org.apache.asterix.om.types.AUnorderedListType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.om.util.ConstantExpressionUtil;
-import org.apache.asterix.runtime.aggregates.collections.ListifyAggregateDescriptor;
 import org.apache.asterix.runtime.evaluators.common.CreateMBREvalFactory;
 import org.apache.asterix.runtime.evaluators.common.FunctionManagerImpl;
-import org.apache.asterix.runtime.evaluators.constructors.ClosedRecordConstructorDescriptor;
-import org.apache.asterix.runtime.evaluators.constructors.OpenRecordConstructorDescriptor;
-import org.apache.asterix.runtime.evaluators.functions.OrderedListConstructorDescriptor;
-import org.apache.asterix.runtime.evaluators.functions.UnorderedListConstructorDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByIndexEvalFactory;
 import org.apache.asterix.runtime.evaluators.functions.records.FieldAccessByNameDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.records.FieldAccessNestedEvalFactory;
@@ -112,8 +105,6 @@
 import org.apache.hyracks.dataflow.common.data.parsers.LongParserFactory;
 import org.apache.hyracks.dataflow.common.data.parsers.UTF8StringParserFactory;
 
-import junit.extensions.PA;
-
 public class NonTaggedDataFormat implements IDataFormat {
 
     private static boolean registered = false;
@@ -372,7 +363,7 @@
             @Override
             public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context)
                     throws AlgebricksException {
-                ((ListifyAggregateDescriptor) fd).reset((AOrderedListType) context.getType(expr));
+                fd.setImmutableStates(context.getType(expr));
             }
         });
         functionTypeInferers.put(BuiltinFunctions.RECORD_MERGE, new FunctionTypeInferer() {
@@ -383,8 +374,7 @@
                 IAType outType = (IAType) context.getType(expr);
                 IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue());
                 IAType type1 = (IAType) context.getType(f.getArguments().get(1).getValue());
-                PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.IAType, org.apache.asterix.om.types.IAType, "
-                        + " org.apache.asterix.om.types.IAType)", outType, type0, type1);
+                fd.setImmutableStates(outType, type0, type1);
             }
         });
 
@@ -396,8 +386,7 @@
                 AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
                 IAType type0 = (IAType) context.getType(f.getArguments().get(0).getValue());
                 IAType type1 = (IAType) context.getType(f.getArguments().get(1).getValue());
-                PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.IAType, org.apache.asterix.om.types.IAType)",
-                        type0, type1);
+                fd.setImmutableStates(type0, type1);
             }
         });
 
@@ -417,8 +406,7 @@
                 if (type1.getTypeTag().equals(ATypeTag.ANY)) {
                     type1 = DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE;
                 }
-                PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.IAType, org.apache.asterix.om.types.IAType,"
-                        + " org.apache.asterix.om.types.IAType)", outType, type0, type1);
+                fd.setImmutableStates(outType, type0, type1);
             }
         });
 
@@ -438,8 +426,7 @@
                 if (type1.getTypeTag().equals(ATypeTag.ANY)) {
                     type1 = DefaultOpenFieldType.NESTED_OPEN_AORDERED_LIST_TYPE;
                 }
-                PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.IAType, org.apache.asterix.om.types.IAType,"
-                        + " org.apache.asterix.om.types.IAType)", outType, type0, type1);
+                fd.setImmutableStates(outType, type0, type1);
             }
         });
         functionTypeInferers.put(BuiltinFunctions.CAST_TYPE, new FunctionTypeInferer() {
@@ -449,8 +436,7 @@
                 AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
                 IAType rt = TypeCastUtils.getRequiredType(funcExpr);
                 IAType it = (IAType) context.getType(funcExpr.getArguments().get(0).getValue());
-                PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.IAType, org.apache.asterix.om.types.IAType)", rt,
-                        it);
+                fd.setImmutableStates(rt, it);
             }
         });
         functionTypeInferers.put(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR, new FunctionTypeInferer() {
@@ -458,8 +444,7 @@
             public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context)
                     throws AlgebricksException {
                 ARecordType rt = (ARecordType) context.getType(expr);
-                ((OpenRecordConstructorDescriptor) fd).reset(rt,
-                        computeOpenFields((AbstractFunctionCallExpression) expr, rt));
+                fd.setImmutableStates(rt, computeOpenFields((AbstractFunctionCallExpression) expr, rt));
             }
 
             private boolean[] computeOpenFields(AbstractFunctionCallExpression expr, ARecordType recType) {
@@ -486,21 +471,21 @@
             @Override
             public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context)
                     throws AlgebricksException {
-                ((ClosedRecordConstructorDescriptor) fd).reset((ARecordType) context.getType(expr));
+                fd.setImmutableStates(context.getType(expr));
             }
         });
         functionTypeInferers.put(BuiltinFunctions.ORDERED_LIST_CONSTRUCTOR, new FunctionTypeInferer() {
             @Override
             public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context)
                     throws AlgebricksException {
-                ((OrderedListConstructorDescriptor) fd).reset((AOrderedListType) context.getType(expr));
+                fd.setImmutableStates(context.getType(expr));
             }
         });
         functionTypeInferers.put(BuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR, new FunctionTypeInferer() {
             @Override
             public void infer(ILogicalExpression expr, IFunctionDescriptor fd, IVariableTypeEnvironment context)
                     throws AlgebricksException {
-                ((UnorderedListConstructorDescriptor) fd).reset((AUnorderedListType) context.getType(expr));
+                fd.setImmutableStates(context.getType(expr));
             }
         });
         functionTypeInferers.put(BuiltinFunctions.FIELD_ACCESS_BY_INDEX, new FunctionTypeInferer() {
@@ -511,8 +496,7 @@
                 IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue());
                 switch (t.getTypeTag()) {
                     case RECORD: {
-                        ARecordType recType = (ARecordType) t;
-                        PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType)", recType);
+                        fd.setImmutableStates(t);
                         break;
                     }
                     case UNION: {
@@ -520,8 +504,7 @@
                         if (unionT.isUnknownableType()) {
                             IAType t2 = unionT.getActualType();
                             if (t2.getTypeTag() == ATypeTag.RECORD) {
-                                ARecordType recType = (ARecordType) t2;
-                                PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType)", recType);
+                                fd.setImmutableStates(t2);
                                 break;
                             }
                         }
@@ -548,14 +531,11 @@
 
                 switch (t.getTypeTag()) {
                     case RECORD: {
-                        ARecordType recType = (ARecordType) t;
-                        PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType, java.util.List)", recType,
-                                listFieldPath);
+                        fd.setImmutableStates(t, listFieldPath);
                         break;
                     }
                     case ANY:
-                        PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType, java.util.List)",
-                                ARecordType.FULLY_OPEN_RECORD_TYPE, listFieldPath);
+                        fd.setImmutableStates(ARecordType.FULLY_OPEN_RECORD_TYPE, listFieldPath);
                         break;
                     default: {
                         throw new NotImplementedException("field-access-nested for data of type " + t);
@@ -571,11 +551,9 @@
                 IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue());
                 ATypeTag typeTag = t.getTypeTag();
                 if (typeTag.equals(ATypeTag.RECORD)) {
-                    ARecordType recType = (ARecordType) t;
-                    PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType)", recType);
+                    fd.setImmutableStates(t);
                 } else if (typeTag.equals(ATypeTag.ANY)) {
-                    PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType)",
-                            ARecordType.FULLY_OPEN_RECORD_TYPE);
+                    fd.setImmutableStates(ARecordType.FULLY_OPEN_RECORD_TYPE);
                 } else {
                     throw new NotImplementedException("get-record-fields for data of type " + t);
                 }
@@ -589,11 +567,9 @@
                 IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue());
                 ATypeTag typeTag = t.getTypeTag();
                 if (typeTag.equals(ATypeTag.RECORD)) {
-                    ARecordType recType = (ARecordType) t;
-                    PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType)", recType);
+                    fd.setImmutableStates(t);
                 } else if (typeTag.equals(ATypeTag.ANY)) {
-                    PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType)",
-                            ARecordType.FULLY_OPEN_RECORD_TYPE);
+                    fd.setImmutableStates(ARecordType.FULLY_OPEN_RECORD_TYPE);
                 } else {
                     throw new NotImplementedException("get-record-field-value for data of type " + t);
                 }
@@ -607,11 +583,9 @@
                 IAType t = (IAType) context.getType(fce.getArguments().get(0).getValue());
                 ATypeTag typeTag = t.getTypeTag();
                 if (typeTag.equals(ATypeTag.RECORD)) {
-                    ARecordType recType = (ARecordType) t;
-                    PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType)", recType);
+                    fd.setImmutableStates(t);
                 } else if (typeTag.equals(ATypeTag.ANY)) {
-                    PA.invokeMethod(fd, "reset(org.apache.asterix.om.types.ARecordType)",
-                            ARecordType.FULLY_OPEN_RECORD_TYPE);
+                    fd.setImmutableStates(ARecordType.FULLY_OPEN_RECORD_TYPE);
                 } else {
                     throw new NotImplementedException("record-fields with data of type " + t);
                 }
diff --git a/asterixdb/asterix-server/pom.xml b/asterixdb/asterix-server/pom.xml
index 77aa0f0..bf04282 100644
--- a/asterixdb/asterix-server/pom.xml
+++ b/asterixdb/asterix-server/pom.xml
@@ -366,9 +366,9 @@
               <pluginExecutions>
                 <pluginExecution>
                   <pluginExecutionFilter>
-                    <groupId>org.apache.asterix</groupId>
+                    <groupId>org.apache.hyracks</groupId>
                     <artifactId>license-automation-plugin</artifactId>
-                    <versionRange>${project.version}</versionRange>
+                    <versionRange>${hyracks.version}</versionRange>
                     <goals>
                       <goal>generate</goal>
                     </goals>
diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java
index 0b86ea5..d2650e9 100644
--- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java
+++ b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/service/recovery/AbstractCheckpointManager.java
@@ -18,14 +18,14 @@
  */
 package org.apache.asterix.transaction.management.service.recovery;
 
+import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -84,15 +84,12 @@
         if (checkpoints == null || checkpoints.length == 0) {
             return null;
         }
-
-        Checkpoint checkpointObject;
         List<Checkpoint> checkpointObjectList = new ArrayList<>();
         for (File file : checkpoints) {
-            try (FileInputStream fis = new FileInputStream(file);
-                    ObjectInputStream oisFromFis = new ObjectInputStream(fis)) {
-                checkpointObject = (Checkpoint) oisFromFis.readObject();
-                checkpointObjectList.add(checkpointObject);
-            } catch (IOException | ClassNotFoundException e) {
+            try {
+                String jsonString = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
+                checkpointObjectList.add(Checkpoint.fromJson(jsonString));
+            } catch (IOException e) {
                 throw new ACIDException("Failed to read a checkpoint file", e);
             }
         }
@@ -139,12 +136,10 @@
         // Construct checkpoint file name
         String fileName = checkpointDir.getAbsolutePath() + File.separator + CHECKPOINT_FILENAME_PREFIX
                 + Long.toString(checkpoint.getTimeStamp());
-        //TODO: replace java serialization
         // Write checkpoint file to disk
-        try (FileOutputStream fos = new FileOutputStream(fileName);
-                ObjectOutputStream oosToFos = new ObjectOutputStream(fos)) {
-            oosToFos.writeObject(checkpoint);
-            oosToFos.flush();
+        Path path = Paths.get(fileName);
+        try (BufferedWriter writer = Files.newBufferedWriter(path)) {
+            writer.write(checkpoint.asJson());
         } catch (IOException e) {
             throw new HyracksDataException("Failed to write checkpoint to disk", e);
         }
diff --git a/asterixdb/asterix-yarn/pom.xml b/asterixdb/asterix-yarn/pom.xml
index 067ef8b..120f665 100644
--- a/asterixdb/asterix-yarn/pom.xml
+++ b/asterixdb/asterix-yarn/pom.xml
@@ -230,9 +230,9 @@
               <pluginExecutions>
                 <pluginExecution>
                   <pluginExecutionFilter>
-                    <groupId>org.apache.asterix</groupId>
+                    <groupId>org.apache.hyracks</groupId>
                     <artifactId>license-automation-plugin</artifactId>
-                    <versionRange>${project.version}</versionRange>
+                    <versionRange>${hyracks.version}</versionRange>
                     <goals>
                       <goal>generate</goal>
                     </goals>
diff --git a/asterixdb/pom.xml b/asterixdb/pom.xml
index 1955af2..93e2598 100644
--- a/asterixdb/pom.xml
+++ b/asterixdb/pom.xml
@@ -1011,6 +1011,11 @@
         <version>2.8.4</version>
       </dependency>
       <dependency>
+        <groupId>com.fasterxml.jackson.core</groupId>
+        <artifactId>jackson-annotations</artifactId>
+        <version>2.8.4</version>
+      </dependency>
+      <dependency>
         <groupId>com.google.guava</groupId>
         <artifactId>guava</artifactId>
         <version>18.0</version>
diff --git a/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java b/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java
index 6e53e2a..92bc076 100644
--- a/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java
+++ b/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java
@@ -20,6 +20,7 @@
 
 import java.io.Serializable;
 
+import org.apache.hyracks.api.exceptions.ErrorCode;
 import org.apache.hyracks.api.util.ErrorMessageUtil;
 
 public class AlgebricksException extends Exception {
@@ -41,6 +42,10 @@
         this.params = params;
     }
 
+    public static AlgebricksException create(int errorCode, Serializable... params) {
+        return new AlgebricksException(ErrorCode.HYRACKS, errorCode, ErrorCode.getErrorMessage(errorCode), params);
+    }
+
     public AlgebricksException(String message) {
         this(ErrorMessageUtil.NONE, UNKNOWN, message, null, null);
     }
diff --git a/hyracks-fullstack/algebricks/algebricks-compiler/pom.xml b/hyracks-fullstack/algebricks/algebricks-compiler/pom.xml
index 6f98102..c326f86 100644
--- a/hyracks-fullstack/algebricks/algebricks-compiler/pom.xml
+++ b/hyracks-fullstack/algebricks/algebricks-compiler/pom.xml
@@ -66,5 +66,34 @@
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <version>1.10.19</version>
+      <scope>test</scope>
+    </dependency>
+   <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-api-mockito</artifactId>
+      <version>1.6.6</version>
+      <scope>test</scope>
+   </dependency>
+   <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-core</artifactId>
+      <version>1.6.6</version>
+      <scope>test</scope>
+   </dependency>
+   <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-module-junit4</artifactId>
+      <version>1.6.6</version>
+      <scope>test</scope>
+   </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
diff --git a/hyracks-fullstack/algebricks/algebricks-compiler/src/main/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleController.java b/hyracks-fullstack/algebricks/algebricks-compiler/src/main/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleController.java
new file mode 100644
index 0000000..9446756
--- /dev/null
+++ b/hyracks-fullstack/algebricks/algebricks-compiler/src/main/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleController.java
@@ -0,0 +1,91 @@
+/*
+ * 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.hyracks.algebricks.compiler.rewriter.rulecontrollers;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.rewriter.base.AbstractRuleController;
+import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+import org.apache.hyracks.api.exceptions.ErrorCode;
+
+/**
+ * If the first rule in the given collection is fired during the first iteration, it also runs the other rules
+ * sequentially (round-robin) until one iteration over all rules produces no change. Except the case where the first
+ * rule in the first iteration fails, all rules will be checked for each iteration.
+ * An example scenario:
+ * Suppose there are three rules - R1, R2, and R3.
+ * During the first iteration, if R1, the first rule, is not fired, then R2 and R3 will not be checked.
+ * If R1, the first rule, is fired, then R2 and R3 will be checked. Since the first iteration returns at least one true
+ * (the first rule), there will be an another iteration. In the second iteration, we don't care whether R1 is fired or
+ * not. This enforcement of 'first rule returns true' check is only executed in the first iteration.
+ * So, if any of rules in the collection (R1, R2, and R3) is fired, then there will be another iteration(s) until
+ * an iteration doesn't produce any change (no true from all rules).
+ */
+public class SequentialFirstRuleCheckFixpointRuleController extends AbstractRuleController {
+
+    private boolean fullDfs;
+
+    public SequentialFirstRuleCheckFixpointRuleController(boolean fullDfs) {
+        super();
+        this.fullDfs = fullDfs;
+    }
+
+    @Override
+    public boolean rewriteWithRuleCollection(Mutable<ILogicalOperator> root,
+            Collection<IAlgebraicRewriteRule> ruleCollection) throws AlgebricksException {
+        List<IAlgebraicRewriteRule> rules;
+
+        // This rule controller can only be applied for a list since it needs to enforce the "first" rule check.
+        if (ruleCollection instanceof List) {
+            rules = (List<IAlgebraicRewriteRule>) ruleCollection;
+        } else {
+            throw AlgebricksException.create(ErrorCode.COMPILATION_RULECOLLECTION_NOT_INSTANCE_OF_LIST,
+                    this.getClass().getName());
+        }
+
+        if (rules.isEmpty()) {
+            return false;
+        }
+
+        boolean anyRuleFired = false;
+        boolean anyChange;
+        boolean firstRuleChecked = false;
+        do {
+            anyChange = false;
+            for (int i = 0; i < rules.size(); i++) {
+                boolean ruleFired = rewriteOperatorRef(root, rules.get(i), true, fullDfs);
+                // If the first rule returns false in the first iteration, stops applying the rules at all.
+                if (!firstRuleChecked && i == 0 && !ruleFired) {
+                    return ruleFired;
+                }
+                if (ruleFired) {
+                    anyChange = true;
+                    anyRuleFired = true;
+                }
+            }
+            firstRuleChecked = true;
+        } while (anyChange);
+
+        return anyRuleFired;
+    }
+}
diff --git a/hyracks-fullstack/algebricks/algebricks-compiler/src/test/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleControllerTest.java b/hyracks-fullstack/algebricks/algebricks-compiler/src/test/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleControllerTest.java
new file mode 100644
index 0000000..339cb15
--- /dev/null
+++ b/hyracks-fullstack/algebricks/algebricks-compiler/src/test/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleControllerTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.hyracks.algebricks.compiler.rewriter.rulecontrollers;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
+import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ SequentialFirstRuleCheckFixpointRuleController.class, AbstractLogicalOperator.class })
+public class SequentialFirstRuleCheckFixpointRuleControllerTest {
+
+    @Test
+    public void testRewriteWithRuleCollection() throws Exception {
+        SequentialFirstRuleCheckFixpointRuleController ruleController =
+                new SequentialFirstRuleCheckFixpointRuleController(true);
+
+        // Specifies three rules - R1, R2, and R3.
+        IAlgebraicRewriteRule firstRule = mock(IAlgebraicRewriteRule.class);
+        IAlgebraicRewriteRule secondRule = mock(IAlgebraicRewriteRule.class);
+        IAlgebraicRewriteRule thirdRule = mock(IAlgebraicRewriteRule.class);
+        List<IAlgebraicRewriteRule> ruleList = new LinkedList<>();
+        ruleList.add(firstRule);
+        ruleList.add(secondRule);
+        ruleList.add(thirdRule);
+
+        @SuppressWarnings("unchecked")
+        Mutable<ILogicalOperator> root = PowerMockito.mock(Mutable.class);
+        AbstractLogicalOperator rootOp = PowerMockito.mock(AbstractLogicalOperator.class);
+        List<Mutable<ILogicalOperator>> emptyList = new ArrayList<>();
+        PowerMockito.when(root.getValue()).thenReturn(rootOp);
+        PowerMockito.when(rootOp.getInputs()).thenReturn(emptyList);
+
+        // Case 1: the first rule returns true in the first iteration.
+        //  Iteration1: R1 true, R2 false, R3 false
+        //  Iteration2: R1 false, R2 false, R3 false
+        PowerMockito.when(firstRule.rewritePre(any(), any())).thenReturn(true).thenReturn(false);
+        PowerMockito.when(secondRule.rewritePre(any(), any())).thenReturn(false);
+        PowerMockito.when(thirdRule.rewritePre(any(), any())).thenReturn(false);
+        ruleController.rewriteWithRuleCollection(root, ruleList);
+        // The count should be two for all rules.
+        verify(firstRule, times(2)).rewritePre(any(), any());
+        verify(secondRule, times(2)).rewritePre(any(), any());
+        verify(thirdRule, times(2)).rewritePre(any(), any());
+
+        // Case 2: the first rule returns false in the first iteration.
+        //  Iteration1: R1 false (R2 and R3 should not be invoked.)
+        reset(firstRule);
+        reset(secondRule);
+        reset(thirdRule);
+        PowerMockito.when(firstRule.rewritePre(any(), any())).thenReturn(false);
+        PowerMockito.when(secondRule.rewritePre(any(), any())).thenReturn(true);
+        PowerMockito.when(thirdRule.rewritePre(any(), any())).thenReturn(true);
+        ruleController.rewriteWithRuleCollection(root, ruleList);
+        // The count should be one for the first rule.
+        verify(firstRule, times(1)).rewritePre(any(), any());
+        verify(secondRule, times(0)).rewritePre(any(), any());
+        verify(thirdRule, times(0)).rewritePre(any(), any());
+
+        // Case 3: a mixture of returning true/false.
+        //  Iteration1: R1 true, R2 true, R3 false
+        //  Iteration2: R1 false, R2 true, R3 false
+        //  Iteration3: R1 false, R2 false, R3 false
+        // So, the iteration should be stopped after the iteration 3.
+        reset(firstRule);
+        reset(secondRule);
+        reset(thirdRule);
+        PowerMockito.when(firstRule.rewritePre(any(), any())).thenReturn(true).thenReturn(false);
+        PowerMockito.when(secondRule.rewritePre(any(), any())).thenReturn(true).thenReturn(true).thenReturn(false);
+        PowerMockito.when(thirdRule.rewritePre(any(), any())).thenReturn(false);
+        ruleController.rewriteWithRuleCollection(root, ruleList);
+        // The count should be three for all rules.
+        verify(firstRule, times(3)).rewritePre(any(), any());
+        verify(secondRule, times(3)).rewritePre(any(), any());
+        verify(thirdRule, times(3)).rewritePre(any(), any());
+    }
+
+}
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java
index 888f82a..5a67188 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java
@@ -25,7 +25,10 @@
 import org.apache.hyracks.api.util.ErrorMessageUtil;
 
 /**
- * A registry of runtime error codes
+ * A registry of runtime/compile error codes
+ * Error code:
+ * 0 --- 999: runtime errors
+ * 1000 ---- 1999: compilation errors
  */
 public class ErrorCode {
     private static final String RESOURCE_PATH = "errormsg" + File.separator + "en.properties";
@@ -36,6 +39,7 @@
     public static final int FAILURE_ON_NODE = 3;
     public static final int RUNTIME_FILE_WITH_ABSOULTE_PATH_NOT_WITHIN_ANY_IO_DEVICE = 4;
     public static final int RUNTIME_FULLTEXT_PHRASE_FOUND = 5;
+    public static final int COMPILATION_RULECOLLECTION_NOT_INSTANCE_OF_LIST = 1001;
 
     // Loads the map that maps error codes to error message templates.
     private static Map<Integer, String> errorMessageMap = null;
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties b/hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties
index 8ebafef..52367ee 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/resources/errormsg/en.properties
@@ -17,7 +17,9 @@
 # under the License.
 #
 
-1=Unsupported operation %1$s in %2$s operator
-2=Error in processing tuple %1$s in a frame
-4=The file with absolute path %1$s is not within any of the current IO devices
-5=Phrase search in Full-text is not supported. An expression should include only one word
\ No newline at end of file
+1 = Unsupported operation %1$s in %2$s operator
+2 = Error in processing tuple %1$s in a frame
+4 = The file with absolute path %1$s is not within any of the current IO devices
+5 = Phrase search in Full-text is not supported. An expression should include only one word
+
+1001 = The given rule collection %1$s is not an instance of the List class.
\ No newline at end of file
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/tokenizers/NGramUTF8StringBinaryTokenizer.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/tokenizers/NGramUTF8StringBinaryTokenizer.java
index 4c486c5..8bd0c50 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/tokenizers/NGramUTF8StringBinaryTokenizer.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/tokenizers/NGramUTF8StringBinaryTokenizer.java
@@ -110,7 +110,11 @@
         if (usePrePost) {
             totalGrams = numChars + gramLength - 1;
         } else {
-            totalGrams = numChars - gramLength + 1;
+            if (numChars >= gramLength) {
+                totalGrams = numChars - gramLength + 1;
+            } else {
+                totalGrams = 0;
+            }
         }
     }