Merge branch 'madhusudancs/error-reporting'
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ConstantFoldingRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ConstantFoldingRule.java
index b0ce342..ae0a842 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ConstantFoldingRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ConstantFoldingRule.java
@@ -112,7 +112,7 @@
             AqlTypeTraitProvider.INSTANCE, AqlBinaryBooleanInspectorImpl.FACTORY, AqlBinaryIntegerInspector.FACTORY,
             AqlPrinterFactoryProvider.INSTANCE, AqlNullWriterFactory.INSTANCE, null,
             new LogicalExpressionJobGenToExpressionRuntimeProviderAdapter(AqlLogicalExpressionJobGen.INSTANCE),
-            AqlExpressionTypeComputer.INSTANCE, AqlNullableTypeComputer.INSTANCE, null, null, null,
+            AqlExpressionTypeComputer.INSTANCE, AqlNullableTypeComputer.INSTANCE, null, null, null, null,
             GlobalConfig.DEFAULT_FRAME_SIZE, null);
 
     private static final IOperatorSchema[] _emptySchemas = new IOperatorSchema[] {};
diff --git a/asterix-app/data/temporal/simpletemp_30.json b/asterix-app/data/temporal/simpletemp_30.json
new file mode 100644
index 0000000..f0a4582
--- /dev/null
+++ b/asterix-app/data/temporal/simpletemp_30.json
@@ -0,0 +1,3 @@
+{ "date": date("4619-11-23"), "time": time("14:29:36.786Z"), "datetime": datetime("2749-01-27T17:27:30.020Z"), "duration": duration("-P474133Y7M854630DT4H40M6.45S"), "year-month-duration": year-month-duration("P193989Y3M"), "day-time-duration": day-time-duration("P4477686DT4H49M31.87S"), "date-interval": interval-date("-9537-08-04, 9656-06-03"), "time-interval": interval-time("12:04:45.689Z, 12:41:59.002Z"), "datetime-interval": interval-datetime("-2640-10-11T17:32:15.675Z, 4104-02-01T05:59:11.902Z") }
+{ "date": date("-9971-09-24"), "time": time("11:38:17.154Z"), "datetime": datetime("1259-11-13T09:49:11.852Z"), "duration": duration("P473653Y9M4566143DT10H20M53.61S"), "year-month-duration": year-month-duration("P148233Y10M"), "day-time-duration": day-time-duration("-P7236357DT2H56M56.164S"), "date-interval": interval-date("-0255-09-06, 4925-05-03"), "time-interval": interval-time("23:10:45.169Z, 01:37:48.736Z"), "datetime-interval": interval-datetime("0534-12-08T08:20:31.487Z, 6778-02-16T22:40:21.653Z") }
+{ "date": date("7986-11-25"), "time": time("12:49:39.736Z"), "datetime": datetime("-8337-01-30T15:23:07.598Z"), "duration": duration("-P184484Y7M2241423DT10H42M49.500S"), "year-month-duration": year-month-duration("-P546031Y3M"), "day-time-duration": day-time-duration("P2623386DT10H32M31.983S"), "date-interval": interval-date("-4514-05-24, 3337-08-26"), "time-interval": interval-time("04:16:42.321Z, 02:22:56.816Z"), "datetime-interval": interval-datetime("2129-12-12T13:18:35.758Z, 8647-07-01T13:10:19.691Z") }
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
index 48737c7..d72ba6a 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
@@ -327,6 +327,7 @@
         builder.setHashFunctionFactoryProvider(format.getBinaryHashFunctionFactoryProvider());
         builder.setHashFunctionFamilyProvider(format.getBinaryHashFunctionFamilyProvider());
         builder.setNullWriterFactory(format.getNullWriterFactory());
+        builder.setPredicateEvaluatorFactoryProvider(format.getPredicateEvaluatorFactoryProvider());
 
         switch (pdf) {
             case JSON:
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
index e22c215..38e12e2 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
@@ -112,10 +112,10 @@
             throw new AlgebricksException("DROP DATASET: No metadata for dataset " + datasetName);
         }
         if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
-            return new JobSpecification();
+            return JobSpecificationUtils.createJobSpecification();
         }
 
-        JobSpecification specPrimary = new JobSpecification();
+        JobSpecification specPrimary = JobSpecificationUtils.createJobSpecification();
 
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> splitsAndConstraint = metadataProvider
                 .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(dataset.getDataverseName(), datasetName,
@@ -152,7 +152,7 @@
             throw new AsterixException("Could not find dataset " + datasetName + " in datavetse " + dataverseName);
         }
         ARecordType itemType = (ARecordType) metadata.findType(dataverseName, dataset.getItemTypeName());
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
         IBinaryComparatorFactory[] comparatorFactories = DatasetUtils.computeKeysBinaryComparatorFactories(dataset,
                 itemType, format.getBinaryComparatorFactoryProvider());
         ITypeTraits[] typeTraits = DatasetUtils.computeTupleTypeTraits(dataset, itemType);
@@ -205,7 +205,7 @@
             throw new AsterixException("Cannot load data into dataset  (" + datasetName + ")" + "of type "
                     + dataset.getDatasetType());
         }
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
 
         ARecordType itemType = (ARecordType) MetadataManager.INSTANCE.getDatatype(mdTxnCtx, dataverseName,
                 dataset.getItemTypeName()).getDatatype();
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/DataverseOperations.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/DataverseOperations.java
index 0654ff7..b71a44a 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/DataverseOperations.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/DataverseOperations.java
@@ -11,7 +11,7 @@
 
 public class DataverseOperations {
     public static JobSpecification createDropDataverseJobSpec(Dataverse dataverse, AqlMetadataProvider metadata) {
-        JobSpecification jobSpec = new JobSpecification();
+        JobSpecification jobSpec = JobSpecificationUtils.createJobSpecification();
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> splitsAndConstraint = metadata
                 .splitProviderAndPartitionConstraintsForDataverse(dataverse.getDataverseName());
         FileRemoveOperatorDescriptor frod = new FileRemoveOperatorDescriptor(jobSpec, splitsAndConstraint.first);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/FeedOperations.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/FeedOperations.java
index f9bd2d5..27b32f8 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/FeedOperations.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/FeedOperations.java
@@ -93,7 +93,7 @@
             throw new AsterixException("Operation not support for dataset type  " + dataset.getDatasetType());
         }
 
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
         IOperatorDescriptor feedMessenger;
         AlgebricksPartitionConstraint messengerPc;
 
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
index 90a1ef0..1452c04 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/IndexOperations.java
@@ -45,7 +45,7 @@
         String datasetName = indexDropStmt.getDatasetName();
         String indexName = indexDropStmt.getIndexName();
 
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
 
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> splitsAndConstraint = metadataProvider
                 .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(dataverseName, datasetName, indexName);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/JobSpecificationUtils.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/JobSpecificationUtils.java
new file mode 100644
index 0000000..fa0a40f
--- /dev/null
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/JobSpecificationUtils.java
@@ -0,0 +1,16 @@
+package edu.uci.ics.asterix.file;
+
+import edu.uci.ics.asterix.common.config.AsterixCompilerProperties;
+import edu.uci.ics.asterix.om.util.AsterixAppContextInfo;
+import edu.uci.ics.hyracks.api.job.JobSpecification;
+
+public class JobSpecificationUtils {
+    public static JobSpecification createJobSpecification() {
+        JobSpecification spec = new JobSpecification();
+        AsterixCompilerProperties compilerProperties = AsterixAppContextInfo.getInstance().getCompilerProperties();
+        int frameSize = compilerProperties.getFrameSize();
+        spec.setFrameSize(frameSize);
+
+        return spec;
+    }
+}
\ No newline at end of file
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryBTreeCreator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryBTreeCreator.java
index ebd1a9c..71a268c 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryBTreeCreator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryBTreeCreator.java
@@ -34,7 +34,7 @@
 
     @Override
     public JobSpecification buildCreationJobSpec() throws AsterixException, AlgebricksException {
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
 
         AsterixStorageProperties storageProperties = propertiesProvider.getStorageProperties();
         //prepare a LocalResourceMetadata which will be stored in NC's local resource repository
@@ -65,7 +65,7 @@
 
     @Override
     public JobSpecification buildLoadingJobSpec() throws AsterixException, AlgebricksException {
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
 
         // Create dummy key provider for feeding the primary index scan. 
         AbstractOperatorDescriptor keyProviderOp = createDummyKeyProviderOp(spec);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryInvertedIndexCreator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryInvertedIndexCreator.java
index ef94ec2..0e5612a 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryInvertedIndexCreator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryInvertedIndexCreator.java
@@ -150,7 +150,7 @@
 
     @Override
     public JobSpecification buildCreationJobSpec() throws AsterixException, AlgebricksException {
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
 
         AsterixStorageProperties storageProperties = propertiesProvider.getStorageProperties();
         //prepare a LocalResourceMetadata which will be stored in NC's local resource repository
@@ -176,7 +176,7 @@
 
     @Override
     public JobSpecification buildLoadingJobSpec() throws AsterixException, AlgebricksException {
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
 
         // Create dummy key provider for feeding the primary index scan.
         AbstractOperatorDescriptor keyProviderOp = createDummyKeyProviderOp(spec);
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryRTreeCreator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryRTreeCreator.java
index b7e4886..1e452d8 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryRTreeCreator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryRTreeCreator.java
@@ -57,7 +57,7 @@
 
     @Override
     public JobSpecification buildCreationJobSpec() throws AsterixException, AlgebricksException {
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
 
         AsterixStorageProperties storageProperties = propertiesProvider.getStorageProperties();
         //prepare a LocalResourceMetadata which will be stored in NC's local resource repository
@@ -135,7 +135,7 @@
 
     @Override
     public JobSpecification buildLoadingJobSpec() throws AsterixException, AlgebricksException {
-        JobSpecification spec = new JobSpecification();
+        JobSpecification spec = JobSpecificationUtils.createJobSpecification();
 
         // Create dummy key provider for feeding the primary index scan. 
         AbstractOperatorDescriptor keyProviderOp = createDummyKeyProviderOp(spec);
diff --git a/asterix-app/src/test/resources/metadata/queries/basic/issue_363_temporal_sec_key_4/issue_363_temporal_sec_key_4.1.ddl.aql b/asterix-app/src/test/resources/metadata/queries/basic/issue_363_temporal_sec_key_4/issue_363_temporal_sec_key_4.1.ddl.aql
index c6a8836..a935975 100644
--- a/asterix-app/src/test/resources/metadata/queries/basic/issue_363_temporal_sec_key_4/issue_363_temporal_sec_key_4.1.ddl.aql
+++ b/asterix-app/src/test/resources/metadata/queries/basic/issue_363_temporal_sec_key_4/issue_363_temporal_sec_key_4.1.ddl.aql
@@ -16,4 +16,4 @@
 }
 
 create dataset Employee(Emp) primary key id;
-create index TestSecondIndex on Employee(dt);
\ No newline at end of file
+create index TestSecondIndex on Employee(dur);
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.1.ddl.aql
new file mode 100644
index 0000000..d40df1b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.1.ddl.aql
@@ -0,0 +1,15 @@
+/*
+ * Description  : This test case is to verify the fix for issue423
+ 				  (Specifically for NLJ case)
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=423
+ * Expected Res : Success
+ * Date         : 29th May 2013
+ */
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type TestType as open { id : int32 ,fname:string, lname:string}
+
+create dataset t2(TestType) primary key fname,lname;
+create dataset t1(TestType) primary key fname,lname;
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.2.update.aql
new file mode 100644
index 0000000..ef89d7f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.2.update.aql
@@ -0,0 +1,14 @@
+/*
+ * Description  : This test case is to verify the fix for issue423
+ 				  (Specifically for NLJ case)
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=423
+ * Expected Res : Success
+ * Date         : 29th May 2013
+ */
+ 
+use dataverse test;
+
+insert into dataset t1({"id":123,"fname":"John","lname":"Doe"});
+insert into dataset t1({"id":122,"fname":"Bruce","lname":"Li"});
+insert into dataset t2({"id":23,"fname":"John","lname":"Doe"});
+insert into dataset t2({"id":24,"fname":"Ravi","lname":"Khanna"});
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.3.query.aql
new file mode 100644
index 0000000..38e7729
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423-2/query-issue423-2.3.query.aql
@@ -0,0 +1,14 @@
+/*
+ * Description  : This test case is to verify the fix for issue423
+ 				  (Specifically for NLJ case)
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=423
+ * Expected Res : Success
+ * Date         : 29th May 2013
+ */
+ 
+use dataverse test;
+
+for $l in dataset t1
+for $m in dataset t2
+	where $l.age>$m.age
+return {"l":$l,"m":$m};
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.1.ddl.aql
index 05eb126..7491fcc 100644
--- a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.1.ddl.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.1.ddl.aql
@@ -1,3 +1,11 @@
+/*
+ * Description  : This test case is to verify the fix for issue423
+ 				  (Specifically for HHJ case)
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=423
+ * Expected Res : Success
+ * Date         : 29th May 2013
+ */
+ 
 drop dataverse test if exists;
 create dataverse test;
 use dataverse test;
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.2.update.aql
index 71904f1..40ee53e 100644
--- a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.2.update.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.2.update.aql
@@ -1,3 +1,11 @@
+/*
+ * Description  : This test case is to verify the fix for issue423
+ 				  (Specifically for HHJ case)
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=423
+ * Expected Res : Success
+ * Date         : 29th May 2013
+ */
+ 
 use dataverse test;
 
 insert into dataset t1({"id":123,"fname":"John","lname":"Doe"});
diff --git a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.3.query.aql
index a07b185..d124385 100644
--- a/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/open-closed/query-issue423/query-issue423.3.query.aql
@@ -1,3 +1,11 @@
+/*
+ * Description  : This test case is to verify the fix for issue423
+ 				  (Specifically for HHJ case)
+ 				: https://code.google.com/p/asterixdb/issues/detail?id=423
+ * Expected Res : Success
+ * Date         : 29th May 2013
+ */
+ 
 use dataverse test;
 
 for $l in dataset t1
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.1.ddl.aql
index 280e52c..d595848 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.1.ddl.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.1.ddl.aql
@@ -1,6 +1,6 @@
 /*
  * Testcase Name  : substr04.aql
- * Description    : Test substring2(string,position,position) built in function.
+ * Description    : Test substring(string,position,position) built in function.
  * Success        : Yes
  * Date           : 18th April 2012
  */
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.2.update.aql
index 280e52c..d595848 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.2.update.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.2.update.aql
@@ -1,6 +1,6 @@
 /*
  * Testcase Name  : substr04.aql
- * Description    : Test substring2(string,position,position) built in function.
+ * Description    : Test substring(string,position,position) built in function.
  * Success        : Yes
  * Date           : 18th April 2012
  */
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.3.query.aql
index 0f5b1ff..69ff8ab 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr04/substr04.3.query.aql
@@ -1,19 +1,17 @@
 /*
  * Testcase Name  : substr04.aql
- * Description    : Test substring2(string,position,position) built in function.
+ * Description    : Test substring(string, position, length) built in function.
  * Success        : Yes
  * Date           : 18th April 2012
  */
 
-for $a in [ substring2("hello world",7,11),
-substring("hello world",1,11),
-substring("hello world",3,7),
-substring("ABCD",3,6),
-substring("ABCD",0,4),
-substring("UC Irvine",4,string-length("UC Irvine")),
-substring("UC Irvine",0,string-length("UC Irvine")),
-substring("UC Irvine",1,string-length("UC Irvine")),
-substring(substring("UC Irvine",4),0,string-length("Irvine")),
-substring(substring("UC Irvine",4),0,(string-length("Irvine")/2))
+for $a in [ substring("hello world", 7, 5),
+substring("hello world", 1, 11),
+substring("hello world", 3, 9),
+substring("ABCD", 3, 2),
+substring("ABCD", 1, 4),
+substring("UC Irvine", 4, string-length("UC Irvine") - 3),
+substring("UC Irvine", 1, string-length("UC Irvine")),
+substring(substring("UC Irvine", 4), 1, string-length("Irvine"))
 ]
 return $a
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.1.ddl.aql
index cd3bee1..6a77034 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.1.ddl.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.1.ddl.aql
@@ -1,6 +1,6 @@
 /*
  * Testcase Name  : substr05.aql
- * Description    : Test substring2(string,position,position) built in function.
+ * Description    : Test substring(string,position,position) built in function.
  * Success        : Yes
  * Date           : 19th April 2012
  */
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.2.update.aql
index da796c7..680f0db 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.2.update.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.2.update.aql
@@ -1,6 +1,6 @@
 /*
  * Testcase Name  : substr05.aql
- * Description    : Test substring2(string,position,position) built in function.
+ * Description    : Test substring(string,position,position) built in function.
  * Success        : Yes
  * Date           : 19th April 2012
  */
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.3.query.aql
index 1b2cfe5..5c0fa4f 100644
--- a/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substr05/substr05.3.query.aql
@@ -1,14 +1,14 @@
 /*
  * Testcase Name  : substr05.aql
- * Description    : Test substring2(string,position,position) built in function.
+ * Description    : Test substring(string,position,position) built in function.
  * Success        : Yes
  * Date           : 19th April 2012
  */
 
-// To test substring2 function with string data stored in an internal dataset.
+// To test substring function with string data stored in an internal dataset.
 
 use dataverse test;
 
 for $a in dataset('testdst')
 order by $a.name
-return substring($a.name,4,string-length($a.name));
+return substring($a.name, 4, string-length($a.name) - 3);
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.ddl.aql
new file mode 100644
index 0000000..66d955c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.ddl.aql
@@ -0,0 +1,25 @@
+/*
+ * Test case name: insert_from_ext_ds_2
+ * Description: verify external data loading on temporal types
+ * Expected result: success
+ */
+ 
+drop dataverse timeTest if exists;
+create dataverse timeTest;
+use dataverse timeTest;
+
+create type timesType as open {
+    date: date,
+    time: time,
+    datetime: datetime,
+    duration: duration,
+    year-month-duration: year-month-duration,
+    day-time-duration: day-time-duration,
+	date-interval: interval,
+	time-interval: interval,
+	datetime-interval: interval
+}
+
+create dataset timeData(timesType)
+primary key date;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.2.update.aql
new file mode 100644
index 0000000..daff7c6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.2.update.aql
@@ -0,0 +1,4 @@
+use dataverse timeTest;
+
+load dataset timeData using localfs
+(("path"="nc1://data/temporal/simpletemp_30.json"),("format"="adm"));
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.3.query.aql
new file mode 100644
index 0000000..28549c8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.3.query.aql
@@ -0,0 +1,5 @@
+use dataverse timeTest;
+
+for $r in dataset timeData
+order by $r.date
+return $r
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/tinysocial/tinysocial-suite/tinysocial-suite.17.query.aql b/asterix-app/src/test/resources/runtimets/queries/tinysocial/tinysocial-suite/tinysocial-suite.17.query.aql
index 9b88ac4..c29c966 100644
--- a/asterix-app/src/test/resources/runtimets/queries/tinysocial/tinysocial-suite/tinysocial-suite.17.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/tinysocial/tinysocial-suite/tinysocial-suite.17.query.aql
@@ -7,7 +7,7 @@
 for $t in dataset TweetMessages
 group by $uid := $t.user.screen-name with $t
 let $c := count($t)
-order by $c desc
+order by  $c,$uid desc
 limit 3
 return {
         "user": $uid,
diff --git a/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue423-2/query-issue423-2.1.adm b/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue423-2/query-issue423-2.1.adm
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/open-closed/query-issue423-2/query-issue423-2.1.adm
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substr04/substr04.1.adm b/asterix-app/src/test/resources/runtimets/results/string/substr04/substr04.1.adm
index fcd3396..74bd0d6 100644
--- a/asterix-app/src/test/resources/runtimets/results/string/substr04/substr04.1.adm
+++ b/asterix-app/src/test/resources/runtimets/results/string/substr04/substr04.1.adm
@@ -5,6 +5,4 @@
 "ABCD"
 "Irvine"
 "UC Irvine"
-"UC Irvine"
-"Irvine"
 "Irvine"
diff --git a/asterix-app/src/test/resources/runtimets/results/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.adm b/asterix-app/src/test/resources/runtimets/results/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.adm
new file mode 100644
index 0000000..4d1cf59
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.adm
@@ -0,0 +1,3 @@
+{ "date": date("-9971-09-24"), "time": time("11:38:17.154Z"), "datetime": datetime("1259-11-13T09:49:11.852Z"), "duration": duration("P473653Y9M4566143DT10H20M53.61S"), "year-month-duration": year-month-duration("P148233Y10M"), "day-time-duration": day-time-duration("-P7236357DT2H56M56.164S"), "date-interval": interval-date("-0255-09-06, 4925-05-03"), "time-interval": interval-time("23:10:45.169Z, 01:37:48.736Z"), "datetime-interval": interval-datetime("0534-12-08T08:20:31.487Z, 6778-02-16T22:40:21.653Z") }
+{ "date": date("4619-11-23"), "time": time("14:29:36.786Z"), "datetime": datetime("2749-01-27T17:27:30.020Z"), "duration": duration("-P474133Y7M854630DT4H40M6.45S"), "year-month-duration": year-month-duration("P193989Y3M"), "day-time-duration": day-time-duration("P4477686DT4H49M31.87S"), "date-interval": interval-date("-9537-08-04, 9656-06-03"), "time-interval": interval-time("12:04:45.689Z, 12:41:59.002Z"), "datetime-interval": interval-datetime("-2640-10-11T17:32:15.675Z, 4104-02-01T05:59:11.902Z") }
+{ "date": date("7986-11-25"), "time": time("12:49:39.736Z"), "datetime": datetime("-8337-01-30T15:23:07.598Z"), "duration": duration("-P184484Y7M2241423DT10H42M49.500S"), "year-month-duration": year-month-duration("-P546031Y3M"), "day-time-duration": day-time-duration("P2623386DT10H32M31.983S"), "date-interval": interval-date("-4514-05-24, 3337-08-26"), "time-interval": interval-time("04:16:42.321Z, 02:22:56.816Z"), "datetime-interval": interval-datetime("2129-12-12T13:18:35.758Z, 8647-07-01T13:10:19.691Z") }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite/tinysocial-suite.17.adm b/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite/tinysocial-suite.17.adm
index 1dd9016..c721153 100644
--- a/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite/tinysocial-suite.17.adm
+++ b/asterix-app/src/test/resources/runtimets/results/tinysocial/tinysocial-suite/tinysocial-suite.17.adm
@@ -1,3 +1,3 @@
-{ "user": "NathanGiesen@211", "count": 6 }
-{ "user": "ColineGeyer@63", "count": 3 }
+{ "user": "OliJackson_512", "count": 1 }
 { "user": "NilaMilliron_tw", "count": 1 }
+{ "user": "ChangEwing_573", "count": 1 }
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index f609bf4..0f3e005 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -2732,6 +2732,16 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="open-closed">
+      <compilation-unit name="query-issue423">
+        <output-dir compare="Text">query-issue423</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="open-closed">
+      <compilation-unit name="query-issue423-2">
+        <output-dir compare="Text">query-issue423-2</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="open-closed">
       <compilation-unit name="query-issue442">
         <output-dir compare="Text">query-issue442</output-dir>
         <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
@@ -3523,7 +3533,6 @@
         <output-dir compare="Text">substr01</output-dir>
       </compilation-unit>
     </test-case>
-    <!-- Issue no 219
     <test-case FilePath="string">
       <compilation-unit name="substr04">
         <output-dir compare="Text">substr04</output-dir>
@@ -3534,7 +3543,6 @@
         <output-dir compare="Text">substr05</output-dir>
       </compilation-unit>
     </test-case>
-    -->
     <test-case FilePath="string">
       <compilation-unit name="substr06">
         <output-dir compare="Text">substr06</output-dir>
@@ -4264,6 +4272,11 @@
         <output-dir compare="Text">insert_from_ext_ds</output-dir>
       </compilation-unit>
   	</test-case>
+   <test-case FilePath="temporal">
+    <compilation-unit name="insert_from_ext_ds_2">
+        <output-dir compare="Text">insert_from_ext_ds_2</output-dir>
+      </compilation-unit>
+   </test-case>
   	<test-case FilePath="temporal">
   		<compilation-unit name="interval_functions">
         <output-dir compare="Text">interval_functions</output-dir>
diff --git a/asterix-aql/.gitignore b/asterix-aql/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/asterix-aql/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/asterix-common/.gitignore b/asterix-common/.gitignore
index ea8c4bf..19f2e00 100644
--- a/asterix-common/.gitignore
+++ b/asterix-common/.gitignore
@@ -1 +1,2 @@
 /target
+/target
diff --git a/asterix-common/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java b/asterix-common/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
index acb1e6a..5e599c3 100644
--- a/asterix-common/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
+++ b/asterix-common/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
@@ -396,3 +396,4 @@
 
     }
 }
+
diff --git a/asterix-doc/src/site/markdown/AdmAql101.md b/asterix-doc/src/site/markdown/AdmAql101.md
index ed4736e..994c464 100644
--- a/asterix-doc/src/site/markdown/AdmAql101.md
+++ b/asterix-doc/src/site/markdown/AdmAql101.md
@@ -211,8 +211,8 @@
 This index will be a B+ tree index; its type is unspecified and _btree_ is the default type.
 The other three illustrate how you can explicitly specify the desired type of index.
 In addition to btree, _rtree_ and inverted _keyword_ indexes are supported by AsterixDB.
-Indexes can also have composite keys, and there are more advanced flavors of text indexing
-available as well (_fuzzy keyword_ and _ngram(k)_, where _k_ is the desired gram length).
+Indexes can also have composite keys, and more advanced text indexing is available as well
+(ngram(k), where k is the desired gram length).
 
 ### Querying the Metadata Dataverse ###
 
diff --git a/asterix-doc/src/site/markdown/AsterixAlphaRelease.md b/asterix-doc/src/site/markdown/AsterixAlphaRelease.md
deleted file mode 100644
index ff9efb2..0000000
--- a/asterix-doc/src/site/markdown/AsterixAlphaRelease.md
+++ /dev/null
@@ -1,57 +0,0 @@
-# AsterixDB: A Big Data Management System _(Alpha Release)_ #
-
-## What Is AsterixDB? ##
-
-Welcome to the new home of the AsterixDB Big Data Management System (BDMS).
-The AsterixDB BDMS is the result of about 3.5 years of R&D involving researchers at UC Irvine, UC Riverside, and UC San Diego.
-The AsterixDB code base now consists of roughly 250K lines of Java code that has been co-developed at UC Irvine and UC Riverside.
-
-Initiated in 2009, the NSF-sponsored ASTERIX project has been developing new technologies for ingesting, storing, managing, indexing, querying, and analyzing vast quantities of semi-structured information.
-The project has been combining ideas from three distinct areas---semi-structured data, parallel databases, and data-intensive computing (a.k.a. today's Big Data platforms)---in order to create a next-generation, open-source software platform that scales by running on large, shared-nothing commodity computing clusters.
-The ASTERIX effort has been targeting a wide range of semi-structured information, ranging from "data" use cases---where information is well-typed and highly regular---to "content" use cases---where data tends to be irregular, much of each datum may be textual, and the ultimate schema for the various data types involved may be hard to anticipate up front.
-The ASTERIX project has been addressing technical issues including highly scalable data storage and indexing, semi-structured query processing on very large clusters, and merging time-tested parallel database techniques with modern data-intensive computing techniques to support performant yet declarative solutions to the problem of storing and analyzing semi-structured information effectively.
-The first fruits of this labor have been captured in the AsterixDB system that is now being released in preliminary or "Alpha" release form.
-We are hoping that the arrival of AsterixDB will mark the beginning of the "BDMS era", and we hope that both the Big Data community and the database community will find the AsterixDB system to be interesting and useful for a much broader class of problems than can be addressed with any one of today's current Big Data platforms and related technologies (e.g., Hadoop, Pig, Hive, HBase, MongoDB, and so on).  One of our project mottos has been "one size fits a bunch"---at least that has been our aim.  For more information about the research effort that led to the birth of AsterixDB, please refer to our NSF project web site: [http://asterix.ics.uci.edu/](http://asterix.ics.uci.edu/).
-
-In a nutshell, AsterixDB is a full-function BDMS with a rich feature set that distinguishes it from pretty much any other Big Data platform that's out and available today.  We believe that its feature set makes it well-suited to modern needs such as web data warehousing and social data storage and analysis.  AsterixDB has:
-
- * A semistructured NoSQL style data model (ADM) resulting from extending JSON with object database ideas
- * An expressive and declarative query language (AQL) that supports a broad range of queries and analysis over semistructured data
- * A parallel runtime query execution engine, Hyracks, that has been scale-tested on up to 1000+ cores and 500+ disks
- * Partitioned LSM-based data storage and indexing to support efficient ingestion and management of semistructured data
- * Support for query access to externally stored data (e.g., data in HDFS) as well as to data stored natively by AsterixDB
- * A rich set of primitive data types, including spatial and temporal data in addition to integer, floating point, and textual data
- * Secondary indexing options that include B+ trees, R trees, and inverted keyword (exact and fuzzy) index types
- * Support for fuzzy and spatial queries as well as for more traditional parametric queries
- * Basic transactional (concurrency and recovery) capabilities akin to those of a NoSQL store
-
-## Getting and Using AsterixDB ##
-
-You are most likely here because you are interested in getting your hands on AsterixDB---so you would like to know how to get it, how to set it up, and how to use it.
-Someday our plan is to have comprehensive documentation for AsterixDB and its data model (ADM) and query language (AQL) here on this wiki.
-For the Alpha release, we've got a start; for the Beta release a month or so from now, we will hopefully have much more.
-The following is a list of the wiki pages and supporting documents that we have available today:
-
-1. [InstallingAsterixUsingManagix](InstallingAsterixUsingManagix.html) :
-This is our installation guide, and it is where you should start.
-This document will tell you how to obtain, install, and manage instances of [AsterixDB](https://asterixdb.googlecode.com/files/asterix-installer-0.0.4-binary-assembly.zip), including both single-machine setup (for developers) as well as cluster installations (for deployment in its intended form).
-
-2. [AdmAql101](AdmAql101.html) :
-This is a first-timers introduction to the user model of the AsterixDB BDMS, by which we mean the view of AsterixDB as seen from the perspective of an "average user" or Big Data application developer.
-The AsterixDB user model consists of its data modeling features (ADM) and its query capabilities (AQL).
-This document presents a tiny "social data warehousing" example and uses it as a backdrop for describing, by example, the key features of AsterixDB.
-By working through this document, you will learn how to define the artifacts needed to manage data in AsterixDB, how to load data into the system, how to use most of the basic features of its query language, and how to insert and delete data dynamically.
-
-3. [AsterixDataTypesAndFunctions](AsterixDataTypesAndFunctions.html) :
-This is a reference document that catalogs the primitive data types and built-in functions available for use in AsterixDB schemas (in ADM) and queries (in AQL).
-
-4. [AQL Reference](AsterixQueryLanguageReference.html) :
-This is the AQL language reference manual.
-
-5. [AsterixDBRestAPI](AsterixDBRestAPI.html) :
-Access to data in an AsterixDB instance is provided via a REST-based API.
-This is a short document that describes the REST API entry points and their URL syntax.
-
-To all who have now come this far: Thanks for your interest in AsterixDB, and for kicking its tires in its Alpha form
-In addition to getting the system and trying it out, please sign up as a member of the AsterixDB user mailing list (asterixdb-users (at) googlegroups.com) so that you can contact us easily with your questions, issues, and other feedback.
-We want AsterixDB to be a "big hit" some day, and we are anxious to see what users do with it and to learn from that feedback what we should be working on most urgently in the next phase of the project.
diff --git a/asterix-doc/src/site/markdown/AsterixDBDataModel.md b/asterix-doc/src/site/markdown/AsterixDBDataModel.md
index ffefd09..2b3523f 100644
--- a/asterix-doc/src/site/markdown/AsterixDBDataModel.md
+++ b/asterix-doc/src/site/markdown/AsterixDBDataModel.md
@@ -1,8 +1,7 @@
 # Asterix Data Model (ADM) #
 
-# Basic data types #
 
-An instance of Asterix data model (ADM) can be a _primitive type_ (`Int32`, `Int64`, `String`, `Float`, `Double`, `Date`, `Time`, `Datetime`, etc. or `NULL`) or a _derived type_.
+An instance of Asterix data model (ADM) can be a _*primitive type*_ (`Int32`, `Int64`, `String`, `Float`, `Double`, `Date`, `Time`, `Datetime`, etc. or `NULL`) or a _*derived type*_.
 
 ## Primitive Types ##
 
@@ -139,7 +138,7 @@
 
 
 ### Circle ###
-`Circle` consists of one `point` that represents the center of the circle and a radius of type `double`.
+`Circle` consists of one point that represents the center of the circle and a radius of type `Double`.
 
  * Example:
 
diff --git a/asterix-doc/src/site/markdown/AsterixQueryLanguage.md b/asterix-doc/src/site/markdown/AsterixQueryLanguage.md
deleted file mode 100644
index af25cda..0000000
--- a/asterix-doc/src/site/markdown/AsterixQueryLanguage.md
+++ /dev/null
@@ -1,195 +0,0 @@
-`<wiki:toc max_depth="2" />`
-
-# The Asterix Query Language, Version 1.0 #
-
-# Introduction #
-
-This wiki page provides an overview of the Asterix Query language and the Asterix Data model.
-
-*WARNING:* _THIS IS AN INCOMPLETE SUSPENDED WORK IN PROGRESS...
-_  It will hopefully be resumed shortly in order to produce a legit AQL spec to go out with the Beta Release of AsterixDB.  What's here is very likely inconsistent with what's in the system as of today, as this was from an older snapshot of the world.
-
-# Asterix Data Model #
-
-Data in Asterix is represented using the Asterix Data Model (ADM). The ADM derives inspiration from prior standards such as JSON, XQuery, and the Object Data Model from ODMG.
-
-## Asterix Types ##
-
-### Primitive Types ##
-
-|| *Primitive Type* || *Description* ||
-|| int8   || Signed 8-bit integer. Valid range -128 thru 127 ||
-|| int16  || Signed 16-bit integer. Valid range -32768 thru 32767 ||
-|| int32  || Signed 32-bit integer. Valid range -2147483648 thru 2147483647 ||
-|| int64  || Signed 64-bit integer. Valid range -9223372036854775807 thru 9223372036854775808 ||
-|| uint8  || Unsigned 8-bit integer. Valid range 0 thru 255 ||
-|| uint16 || Unsigned 16-bit integer. Valid range 0 thru 65535 ||
-|| uint32 || Unsigned 32-bit integer. Valid range 0 thru 4294967295 ||
-|| uint64 || Unsigned 64-bit integer. Valid range 0 thru 18446744073709551615 ||
-|| string || String of characters ||
-|| null   || null type (Type of the null value) ||
-|| date   || Date ||
-|| time   || Time of day ||
-|| boolean || Boolean ||
-|| datetime || Date and time ||
-|| point2d || A point in 2-D space ||
-|| point3d || A point in 3-D space ||
-|| binary || Binary data ||
-|| yminterval || Year-Month interval ||
-|| dtinterval || Day-Time interval ||
-|| interval || Year-Month and Day-Time interval ||
-
-### Collection Types ###
-
-|| *Collection Type* || *Description* ||
-|| Record || A record type describes the record data item. A record contains a set of fields which can have values of any ADM type. Fields of a record must be unique. ||
-|| Union || A union type is an abstract type (A value never has a union type) that describes a set of type choices. ||
-|| Ordered List || An orderedlist instance represents a sequence of values where the order of the instances is determined by creation/insertion ||
-|| UnorderedList || An unorderedlist instance represents a collection of values where the order of the instances where the order is irrelevant ||
-|| Enumeration || An enumeration type represents a choice of string values ||
-
-# AQL Expressions #
-
-## Primary Expressions ##
-
-Primary expressions are the basic expressions that form the core of AQL.
-
-### Literals ###
-
-A Literal is a syntactic representation of a constant value. The various literals allowed in AQL are described in the table below.
-
-|| *Literal type* || *Syntax* ||
-|| StringLiteral || ` STRING_LITERAL : ("\"" ("\\\"" | ~["\""])* "\"") | ("\'"("\\\'" | ~["\'"])* "\'") ` ||
-|| IntegerLiteral || ` INTEGER_LITERAL : (["0" - "9"])+ ` ||
-|| FloatLiteral || ` FLOAT_LITERAL: ((["0" - "9"])* "." (["0" - "9"])+ ("f" | "F")) ` ||
-|| DoubleLiteral || ` DOUBLE_LITERAL: ((["0" - "9"])* "." (["0" - "9"])+) ` ||
-|| NullLiteral || ` NULL_LITERAL: "null" ` ||
-|| BooleanLiteral || ` BOOLEAN_LITERAL: "true" | "false" ` ||
-
-### Function Call ###
-
-Function Calls in AQL can be used to invoke builtin functions as well as user defined functions.
-Function Calls have the following syntax.
-
-
-            IDENTIFIER "(" ( Expression ( "," Expression )* )? ")"
-
-
-### Variable Reference ###
-
-Variables in AQL are used to bind to values. Variables can be bound to values by the For, Let, Group by clauses of the FLWOR expressions. Variables can also be bound by
-the Quantified Expressions.
-
-### Ordered List Constructor ###
-
-Constructs an ordered list. An ordered list represents a collection of values. The order of values is relevant. The collection may contain duplicate values.
-
-### Unordered List Constructor ###
-
-Constructs an unordered list. An unordered list represents a collection of values. The order of values is not relevant. The collection may contain duplicate values.
-
-### Record Constructor ###
-
-Constructs an AQL Record. A record contains fields. Each field has a name and a value. The name of the field is of type string. The value of a field may be any legal ADM data type. A record may not contain duplicate fields.
-
-## Arithmetic Expressions ##
-
-AQL allows all the standard arithmetic operators on numeric data types. The specific operators allowed are:
-
-|| *Operator* || *Description* ||
-|| + || Add ||
-|| - || Subtract ||
-|| * || Multiply ||
-|| / || Divide ||
-|| mod || Modulo ||
-
-## Comparison Expressions ##
-
-AQL provides the six standard comparison expressions listed below. In addition, AQL supports fuzzy comparisons.
-
-|| *Operator* || *Description* ||
-|| = || Equal ||
-|| = || Not Equal ||
-|| `< || Less Than ||
-|| `<= || Less Than or Equal ||
-|| >` || Greater Than ||
-|| >`= || Greater Than or Equal ||
-|| >`= || Greater Than or Equal ||
-|| ~= || Fuzzy Equals ||
-
-## Logical Expressions ##
-
-AQL provides two logical connectors:
-
-|| *Operator* || *Description* ||
-|| and || Logical AND ||
-|| or || Logical OR ||
-
-## Field Access Expressions ##
-
-The "." operator is used to access fields of a record. For example,
-
-
-            $x.name
-
-
-accesses the name field of the record bound to $x.
-
-## Indexed Expressions ##
-
-Indexed expressions are used to access values in an ordered list. For example,
-
-
-            $x[5]
-
-
-accesses the 6th item in the list bound to $x. Indexes start at 0.
-
-## FLWOR Expression ##
-
-The FLWOR expression is the most elaborate expression in AQL. It is made up of two parts -- Clauses and the Return Expression.
-
-The syntax of the FLWOR expression is:
-
-
-        
-        ( ForClause | LetClause )
-        ( ForClause | LetClause | WhereClause | OrderClause | GroupClause | LimitClause | DistinctClause )*
-        "return" ReturnExpression
-        
-
-
-* For Clause
-
-        "for" Variable "in" Expression
-
-* Let Clause
-
-        "let" Variable ":=" Expression
-
-* Where Clause
-
-        "where" Expression
-
-* Order Clause
-
-        "order" "by" Expression ("asc" | "desc") ("," Expression ("asc" | "desc"))*
-
-* Group Clause
-
-        "group" "by" ((Variable ":=")? Expression) ("," ((Variable ":=")? Expression))* "with" Variable
-
-* Limit Clause
-
-        "limit" Expression ("," Expression)?
-
-
-* If Then Else Expressions *
-
-        "if" "(" Expression ")" "then" Expression "else" Expression
-
-
-* Quantified Expressions *
-
-        ("some" | "every") Variable "in" Expression "satisfies" Expression
-
diff --git a/asterix-doc/src/site/markdown/AsterixQueryLanguageReference.md b/asterix-doc/src/site/markdown/AsterixQueryLanguageReference.md
index 1ed876e..eddc157 100644
--- a/asterix-doc/src/site/markdown/AsterixQueryLanguageReference.md
+++ b/asterix-doc/src/site/markdown/AsterixQueryLanguageReference.md
@@ -1,14 +1,39 @@
 # The Asterix Query Language, Version 1.0
 ## 1. Introduction
 
-This document provides an overview of the Asterix Query language.
-
+This document is intended as a reference guide to the full syntax
+and semantics of the Asterix Query Language (AQL), the language for talking to AsterixDB.
+This guide covers both the data manipulation language (DML) aspects of AQL, including
+its support for queries and data modification, as well as its data definition language
+(DDL) aspects.
+ New AsterixDB users are encouraged to read and work through the (friendlier) guide
+"AsterixDB 101: An ADM and AQL Primer" before attempting to make use of this document.
+In addition, readers are advised to read and understand the Asterix Data Model (ADM)
+reference guide since a basic understanding of ADM concepts is a prerequisite to understanding AQL.  
+In what follows, we detail the features of the AQL language in a grammar-guided manner:
+We list and briefly explain each of the productions in the AQL grammar, offering 
+examples for clarity in cases where doing so seems needed or helpful.
 
 ## 2. Expressions
 
-    Expression ::= ( OperatorExpr | IfThenElse | FLWOGR | QuantifiedExpression )
+    Expression ::= ( OperatorExpr | IfThenElse | FLWOR | QuantifiedExpression )
 
+AQL is a fully composable expression language.
+Each AQL expression returns zero or more Asterix Data Model (ADM) instances.
+There are four major kinds of expressions in AQL.
+At the topmost level, an AQL expression can be an
+OperatorExpr (similar to a mathematical expression),
+an IfThenElse (to choose between two alternative values),
+a FLWOR expression (the heart of AQL, pronounced "flower expression"),
+or a QuantifiedExpression (which yields a boolean value).
+Each will be detailed as we explore the full AQL grammar.
 
+### Queries
+
+    Query ::= Expression
+
+An AQL query can be any legal AQL expression.
+    
 ### Primary Expressions
 
     PrimaryExpr ::= Literal
@@ -18,7 +43,15 @@
                   | DatasetAccessExpression
                   | ListConstructor
                   | RecordConstructor
-                  
+
+The most basic building block for any AQL expression is the PrimaryExpr.
+This can be a simple literal (constant) value,
+a reference to a query variable that is in scope,
+a parenthesized expression,
+a function call,
+an expression accessing the ADM contents of a dataset,
+a newly constructed list of ADM instances,
+or a newly constructed ADM record.
 
 #### Literals
 
@@ -31,50 +64,88 @@
               | "false"
     StringLiteral ::= <STRING_LITERAL>
 
+Literals (constants) in AQL can be strings, integers, floating point values,
+double values, boolean constants, or the constant value null.
+The null value in AQL has "unknown" or "missing" value semantics, similar to
+(though not identical to) nulls in the relational query language SQL.
+
+The following are some simple examples of AQL literals.
+Since AQL is an expression language, each example is also a complete, legal AQL query (!).
+
 ##### Examples
 
     "a string"
     42
 
-
 #### Variable References
 
     VariableRef ::= <VARIABLE>
 
-##### Example
+A variable in AQL can be bound to any legal ADM value.
+A variable reference refers to the value to which an in-scope variable is bound.
+(E.g., a variable binding may originate from one of the for or let clauses of a
+FLWOR expression or from an input parameter in the context of an AQL function body.)
 
-    $id  
-    
+##### Examples
+
+    $tweet
+    $id
 
 #### Parenthesized Expressions
-    
+
     ParenthesizedExpression ::= "(" Expression ")"
 
+As in most languages, an expression may be parenthesized.
+
+Since AQL is an expression language, the following example expression is
+actually also a complete, legal AQL query whose result is the value 2.
+(As such, you can have Big Fun explaining to your boss how AsterixDB and AQL can turn
+your 1000-node shared-nothing Big Data cluster into a $5M calculator in its spare time.)
+
 ##### Example
 
     ( 1 + 1 )
 
-
 #### Function Calls
 
     FunctionCallExpr ::= FunctionOrTypeName "(" ( Expression ( "," Expression )* )? ")"
 
+Functions are included in AQL, like most languages, as a way to package useful
+functionality or to componentize complicated or reusable AQL computations.
+A function call is a legal AQL query expression that represents the ADM value
+resulting from the evaluation of its body expression with the given parameter
+bindings; the parameter value bindings can themselves be any AQL expressions.
+
+The following example is a (built-in) function call expression whose value is 8.
+
 ##### Example
 
     string-length("a string")
 
-
 #### Dataset Access
 
     DatasetAccessExpression ::= "dataset" ( ( Identifier ( "." Identifier )? )
                               | ( "(" Expression ")" ) )
     Identifier              ::= <IDENTIFIER> | StringLiteral
 
+Querying Big Data is the main point of AsterixDB and AQL.
+Data in AsterixDB reside in datasets (collections of ADM records),
+each of which in turn resides in some namespace known as a dataverse (data universe).
+Data access in a query expression is accomplished via a DatasetAccessExpression.
+Dataset access expressions are most commonly used in FLWOR expressions, where variables
+are bound to their contents.
+
+
+The following are three examples of legal dataset access expressions.
+The first one accesses a dataset called Customers in the dataverse called SalesDV.
+The second one accesses the Customers dataverse in whatever the current dataverse is.
+The third one does the same thing as the second but uses a slightly older AQL syntax.
+
 ##### Examples
 
-    dataset customers
-    dataset (string-join("customers", $country))
-    
+    dataset SalesDV.Customers
+    dataset Customers
+    dataset("Customers")
 
 #### Constructors
 
@@ -84,17 +155,31 @@
     RecordConstructor        ::= "{" ( FieldBinding ( "," FieldBinding )* )? "}"
     FieldBinding             ::= Expression ":" Expression
 
+A major feature of AQL is its ability to construct new ADM data instances.
+This is accomplished using its constructors for each of the major ADM complex object structures,
+namely lists (ordered or unordered) and records.
+Ordered lists are like JSON arrays, while unordered lists have bag (multiset) semantics.
+Records are built from attributes that are field-name/field-value pairs, again like JSON.
+(See the AsterixDB Data Model document for more details on each.)
+
+The following examples illustrate how to construct a new ordered list with 3 items,
+a new unordered list with 4 items, and a new record with 2 fields, respectively.
+List elements can be homogeneous (as in the first example), which is the common case,
+or they may be heterogeneous (as in the second example).
+The data values and field name values used to construct lists and records in constructors are all simply AQL expressions.
+Thus the list elements, field names, and field values used in constructors can be simple literals (as in these three examples)
+or they can come from query variable references or even arbitrarily complex AQL expressions.
+
 ##### Examples
 
     [ "a", "b", "c" ]
-    
-    {{ 42, "forty-two", "AsterixDB!" }}
-    
-    {
-      "project name"    : "AsterixDB"
-      "project members" : {{ "vinayakb", "dtabass", "chenli" }}
-    } 
 
+    {{ 42, "forty-two", "AsterixDB!", 3.14f }}
+
+    {
+      "project name": "AsterixDB"
+      "project members": {{ "vinayakb", "dtabass", "chenli" }}
+    }
 
 ### Path Expressions
 
@@ -102,48 +187,69 @@
     Field     ::= "." Identifier
     Index     ::= "[" ( Expression | "?" ) "]"
 
+Components of complex types in ADM are accessed via path expressions.
+Path access can be applied to the result of an AQL expression that yields an instance of such a type, e.g., a record or list instance.
+For records, path access is based on field names.
+For ordered lists, path access is based on (zero-based) array-style indexing.
+AQL also supports an "I'm feeling lucky" style index accessor, [?], for selecting an arbitrary element from an ordered list.
+Attempts to access non-existent fields or list elements produce a null (i.e., missing information) result as opposed to signaling a runtime error.
+
+The following examples illustrate field access for a record, index-based element access for an ordered list, and also a composition thereof.
+
 ##### Examples
 
-    { "list" : [ "a", "b", "c"] }.list
-    
-    [ "a", "b", "c"][2]
-    
-    { "list" : [ "a", "b", "c"] }.list[2]
+    ({"list": [ "a", "b", "c"]}).list
 
+    (["a", "b", "c"])[2]
+
+    ({ "list": [ "a", "b", "c"]}).list[2]
 
 ### Logical Expressions
 
     OperatorExpr ::= AndExpr ( "or" AndExpr )*
     AndExpr      ::= RelExpr ( "and" RelExpr )*
-    
+
+As in most languages, boolean expressions can be built up from smaller expressions by combining them with the logical connectives and/or.
+Legal boolean values in AQL are true, false, and null.
+(Nulls in AQL are treated much like SQL treats its unknown truth value in boolean expressions.)
+
+The following is an example of a conjuctive range predicate in AQL.
+It will yield true if $a is bound to 4, null if $a is bound to null, and false otherwise.
+
 ##### Example
 
     $a > 3 and $a < 5
-    
 
 ### Comparison Expressions
 
     RelExpr ::= AddExpr ( ( "<" | ">" | "<=" | ">=" | "=" | "!=" | "~=" ) AddExpr )?
-    
+
+AQL has the usual list of suspects, plus one, for comparing pairs of atomic values.
+The "plus one" is the last operator listed above, which is the "roughly equal" operator provided for similarity queries.
+(See the separate document on AsterixDB Similarity Queries for more details on similarity matching.)
+
+An example comparison expression (which yields the boolean value true) is shown below.
+
 ##### Example
 
     5 > 3
 
-
 ### Arithmetic Expressions
 
     AddExpr  ::= MultExpr ( ( "+" | "-" ) MultExpr )*
     MultExpr ::= UnaryExpr ( ( "*" | "/" | "%" | <CARET> | "idiv" ) UnaryExpr )*
     UnaryExpr ::= ( ( "+" | "-" ) )? ValueExpr
 
+AQL also supports the usual cast of characters for arithmetic expressions.
+The example below evaluates to 25.
+
 ##### Example
 
     3 ^ 2 + 4 ^ 2
 
+###  FLWOR Expression
 
-###  FLWOGR Expression   
-    
-    FLWOGR         ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
+    FLWOR         ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
     Clause         ::= ForClause | LetClause | WhereClause | OrderbyClause
                      | GroupClause | LimitClause | DistinctClause
     ForClause      ::= "for" Variable ( "at" Variable )? "in" ( Expression )
@@ -151,19 +257,46 @@
     WhereClause    ::= "where" Expression
     OrderbyClause  ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? 
                        ( "," Expression ( ( "asc" ) | ( "desc" ) )? )*
-    GroupClause    ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )*          
+    GroupClause    ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )*
                        "with" VariableRef ( "," VariableRef )*
     LimitClause    ::= "limit" Expression ( "offset" Expression )?
     DistinctClause ::= "distinct" "by" Expression ( "," Expression )*
     Variable       ::= <VARIABLE>
 
+The heart of AQL is the FLWOR (for-let-where-orderby-return) expression.
+The roots of this expression were borrowed from the expression of the same name in XQuery.
+A FLWOR expression starts with one or more clauses that establish variable bindings.
+A for clause binds a variable incrementally to each element of its associated expression;
+it includes an optional positional variable for counting/numbering the bindings.
+By default no ordering is implied or assumed by a for clause.
+A let clause binds a variable to the collection of elements computed by its associated expression.
+
+Following the initial for or let clause(s), a FLWOR expression may contain an arbitrary sequence of other clauses.
+The where clause in a FLWOR expression filters the preceding bindings via a boolean expression, much like a where clause does in a SQL query.
+The order by clause in a FLWOR expression induces an ordering on the data.
+The group by clause, discussed further below, forms groups based on its group by expressions,
+optionally naming the expressions' values (which together form the grouping key for the expression).
+The with subclause of a group by clause specifies the variable(s) whose values should be grouped based
+on the grouping key(s); following the grouping clause, only the grouping key(s) and the variables named
+in the with subclause remain in scope, and the named grouping variables now contain lists formed from their input values.
+The limit clause caps the number of values returned, optionally starting its result count from a specified offset.
+(Web applications can use this feature for doing pagination.)
+The distinct clause is similar to the group-by clause, but it forms no groups; it serves only to eliminate duplicate values.
+As indicated by the grammar, the clauses in an AQL query can appear in any order.
+To interpret a query, one can think of data as flowing down through the query from the first clause to the return clause.
+
+The following example shows a FLWOR expression that selects and returns one user from the dataset FacebookUsers.
 
 ##### Example
 
     for $user in dataset FacebookUsers
     where $user.id = 8
     return $user
-    
+
+The next example shows a FLWOR expression that joins two datasets, FacebookUsers and FacebookMessages,
+returning user/message pairs.
+The results contain one record per pair, with result records containing the user's name and an entire message.
+
 ##### Example
 
     for $user in dataset FacebookUsers
@@ -173,8 +306,11 @@
       {
         "uname": $user.name,
         "message": $message.message
-      }; 
-    
+      };
+
+In the next example, a let clause is used to bind a variable to all of a user's FacebookMessages.
+The query returns one record per user, with result records containing the user's name and the set of all messages by that user.
+
 ##### Example
 
     for $user in dataset FacebookUsers
@@ -186,15 +322,22 @@
       {
         "uname": $user.name,
         "messages": $messages
-      }; 
-      
+      };
+
+The following example returns all TwitterUsers ordered by their followers count (most followers first) and language.
+Null is treated as being smaller than any other value if nulls are encountered in the ordering key(s).
+
 ##### Example
-      
+
       for $user in dataset TwitterUsers
       order by $user.followers_count desc, $user.lang asc
       return $user
-      
-* null is smaller than any other value
+
+The next example illustrates the use of the group by clause in AQL.
+After the group by clause in the query, only variables that are either in the group by list or in the with list are in scope.
+The variables in the clause's with list will each contain a collection of items following the group by clause;
+the collected items are the values that the source variable was bound to in the tuples that formed the group.
+Null is handled as a single value for grouping.
 
 ##### Example
 
@@ -207,9 +350,7 @@
           "message" : $messages
         }
 
-* after group by only variables that are either in the group-by-list or in the with-list are in scope
-* the variables in the with-clause contain a collection of items after the group by clause  (all the values that the variable was bound to in the tuples that make up the group)
-* null is handled as a single value for grouping
+The use of the limit clause is illustrated in the next example.
 
 ##### Example
 
@@ -218,8 +359,15 @@
       limit 2
       return $user
 
-##### Example (currently not working)
-    
+The final example shows how AQL's distinct by clause works.
+Each variable in scope before the distinct clause is also in scope after the distinct clause.
+This clause works similarly to group by, but for each variable that contains more than
+one value after the distinct by clause, one value is picked nondeterministically.
+(If the variable is in the distinct by list, then its value will be deterministic.)
+Nulls are treated as a single value when they occur in a grouping field.
+
+##### Example
+
       for $x in dataset FacebookMessages
       distinct by $x.sender-location
       return
@@ -228,25 +376,33 @@
           "message" : $x.message
         }
 
-* every variable that is in-scope before the distinct clause is also in scope after the distinct clause
-* works a lot like group by, but for every variable that contains more than one value after the distinct-by clause, one value is picked non-deterministically
-* if the variable is in the disctict-by list, then value is deterministic
-* null is a single value
-    
 ### Conditional Expression
-    
+
     IfThenElse ::= "if" "(" Expression ")" "then" Expression "else" Expression
 
+A conditional expression is useful for choosing between two alternative values based on a
+boolean condition.  If its first (if) expression is true, its second (then) expression's
+value is returned, and otherwise its third (else) expression is returned.
+
+The following example illustrates the form of a conditional expression.
 ##### Example
 
     if (2 < 3) then "yes" else "no"
 
-
 ### Quantified Expressions
-    
-    QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression 
+
+    QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression
                              ( "," Variable "in" Expression )* "satisfies" Expression
-                             
+      
+Quantified expressions are used for expressing existential or universal predicates involving the elements of a collection.
+
+The following pair of examples, each of which returns true, illustrate the use of a quantified
+expression to test that every (or some) element in the set [1, 2, 3] of integers is less than three.
+
+It is useful to note that if the set were instead the empty set, the first expression would yield true
+("every" value in an empty set satisfies the condition) while the second expression would yield false
+(since there isn't "some" value, as there are no values in the set, that satisfies the condition).
+
 ##### Examples
 
     every $x in [ 1, 2, 3] satisfies $x < 3
@@ -264,28 +420,45 @@
                       | InsertStatement
                       | DeleteStatement
                       | Query
-    
-### Declarations    
-    
+
+In addition to expresssions for queries, AQL supports a variety of statements for data
+definition and manipulation purposes as well as controlling the context to be used in
+evaluating AQL  expressions.  This section details the statement side of the AQL language.
+
+### Declarations
+ 
     DataverseDeclaration ::= "use" "dataverse" Identifier
-    SetStatement         ::= "set" Identifier StringLiteral
-    FunctionDeclaration  ::= "declare" "function" Identifier ParameterList "{" Expression "}"
-    ParameterList        ::= "(" ( <VARIABLE> ( "," <VARIABLE> )* )? ")"
+
+The world of data in an AsterixDB cluster is organized into data namespaces called dataverses.
+To set the default dataverse for a series of statements, the use dataverse statement is provided.
+
+As an example, the following statement sets the default dataverse to be TinySocial.
 
 ##### Example
 
     use dataverse TinySocial;
-    
+
+    SetStatement         ::= "set" Identifier StringLiteral
+
+The set statement in AQL is used to control aspects of the expression evalation context for queries.
+
+As an example, the following set statements request that Jaccard similarity with a similarity threshold 0.6
+be used for set similarity matching when the ~= operator is used in a query expression.
+
 ##### Example
 
     set simfunction "jaccard";
     set simthreshold "0.6f"; 
 
-##### Example
+    FunctionDeclaration  ::= "declare" "function" Identifier ParameterList "{" Expression "}"
+    ParameterList        ::= "(" ( <VARIABLE> ( "," <VARIABLE> )* )? ")"
 
-    set simfunction "jaccard";    
-    set simthreshold "0.6f"; 
-    
+When writing a complex AQL query, it can sometimes be helpful to define one or more
+auxilliary functions that each address a sub-piece of the overall query.
+The declare function statement supports the creation of such helper functions.
+
+The following is a very simple example of a temporary AQL function definition.
+
 ##### Example
     
     declare function add($a, $b) {
@@ -303,10 +476,20 @@
     QualifiedName       ::= Identifier ( "." Identifier )?
     DoubleQualifiedName ::= Identifier "." Identifier ( "." Identifier )?
 
+The create statement in AQL is used for creating persistent artifacts in the context of dataverses.
+It can be used to create new dataverses, datatypes, datasets, indexes, and user-defined AQL functions.
+
 #### Dataverses
 
     DataverseSpecification ::= "dataverse" Identifier IfNotExists ( "with format" StringLiteral )?
-    
+
+The create dataverse statement is used to create new dataverses.
+To ease the authoring of reusable AQL scripts, its optional IfNotExists clause allows creation
+to be requested either unconditionally or only if the the dataverse does not already exist.
+If this clause is absent, an error will be returned if the specified dataverse already exists.
+The with format clause is a placeholder for future functionality that can safely be ignored.
+
+The following example creates a dataverse named TinySocial.
 
 ##### Example
 
@@ -324,6 +507,20 @@
     OrderedListTypeDef   ::= "[" ( TypeExpr ) "]"
     UnorderedListTypeDef ::= "{{" ( TypeExpr ) "}}"
 
+The create type statement is used to create a new named ADM datatype.
+This type can then be used to create datasets or utilized when defining one or more other ADM datatypes.
+Much more information about the Asterix Data Model (ADM) is available in the data model reference guide to ADM.
+A new type can be a record type, a renaming of another type, an ordered list type, or an unordered list type.
+A record type can be defined as being either open or closed.
+Instances of a closed record type are not permitted to contain fields other than those specified in the create type statement.
+Instances of an open record type may carry additional fields, and open is the default for a new type (if neither option is specified).
+
+The following example creates a new ADM record type called FacebookUser type.
+Since it is closed, its instances will contain only what is specified in the type definition.
+The first four fields are traditional typed name/value pairs.
+The friend-ids field is an unordered list of 32-bit integers.
+The employment field is an ordered list of instances of another named record type, EmploymentType.
+
 ##### Example
 
     create type FacebookUserType as closed {
@@ -335,7 +532,6 @@
       employment: [EmploymentType]
     }
 
-
 #### Datasets
 
     DatasetSpecification ::= "internal"? "dataset" QualifiedName "(" Identifier ")" IfNotExists
@@ -347,14 +543,33 @@
     KeyValuePair         ::= "(" StringLiteral "=" StringLiteral ")"
     Properties           ::= ( "(" Property ( "," Property )* ")" )?
     Property             ::= Identifier "=" ( StringLiteral | <INTEGER_LITERAL> )
-    ApplyFunction        ::= "apply" "function" FunctionSignature
     FunctionSignature    ::= FunctionOrTypeName "@" <INTEGER_LITERAL>
     PrimaryKey           ::= "primary" "key" Identifier ( "," Identifier )*
 
+The create dataset statement is used to create a new dataset.
+Datasets are named, unordered collections of ADM record instances; they
+are where data lives persistently and are the targets for queries in AsterixDB.
+Datasets are typed, and AsterixDB will ensure that their contents conform to their type definitions.
+An Internal dataset (the default) is a dataset that is stored in and managed by AsterixDB.
+It must have a specified unique primary key that can be used to partition data across nodes of an AsterixDB cluster.
+The primary key is also used in secondary indexes to uniquely identify the indexed primary data records.
+An External dataset is stored outside of AsterixDB, e.g., in HDFS or in the local filesystem(s) of the cluster's nodes.
+External dataset support allows AQL queries to treat external data as though it were stored in AsterixDB,
+making it possible to query "legacy" file data (e.g., Hive data) without having to physically import it into AsterixDB.
+For an external dataset, an appropriate adaptor must be selected to handle the nature of the desired external data.
+(See the guide to external data for more information on the available adaptors.)
+
+The following example creates an internal dataset for storing FacefookUserType records.
+It specifies that their id field is their primary key.
 
 ##### Example
     create internal dataset FacebookUsers(FacebookUserType) primary key id;
 
+The next example creates an external dataset for storing LineitemType records.
+The choice of the localfs adaptor means that its data will reside in the local filesystem of the cluster nodes.
+The create statement provides several parameters used by the localfs adaptor;
+e.g., the file format is delimited text with vertical bar being the field delimiter.
+
 ##### Example
 
     create external dataset Lineitem(LineitemType) using localfs (
@@ -369,26 +584,46 @@
     IndexType          ::= "btree"
                          | "rtree"
                          | "keyword"
-                         | "fuzzy keyword"
                          | "ngram" "(" <INTEGER_LITERAL> ")"
-                         | "fuzzy ngram" "(" <INTEGER_LITERAL> ")"
+
+The create index statement creates a secondary index on one or more fields of a specified dataset.
+Supported index types include btree for totally ordered datatypes,
+rtree for spatial data,
+and keyword and ngram for textual (string) data.
+AsterixDB currently requires indexed fields to be part of the named type associated with a dataset.
+(Future plans include support for indexing of open fields as well.)
+
+The following example creates a btree index called fbAuthorIdx on the author-id field of the FacebookMessages dataset.
+This index can be useful for accelerating exact-match queries, range search queries, and joins involving the author-id field.
 
 ##### Example
 
     create index fbAuthorIdx on FacebookMessages(author-id) type btree;
 
+The following example creates an rtree index called fbSenderLocIdx on the sender-location field of the FacebookMessages dataset.
+This index can be useful for accelerating spatial searches involving the sender-loction field.
+
 ##### Example
 
     create index fbSenderLocIndex on FacebookMessages(sender-location) type rtree;
 
+The following example creates a keyword index called fbMessageIdx on the message field of the FacebookMessages dataset.
+This index can be useful for accelerating text searches involving the message field.
+
 ##### Example
 
     create index fbMessageIdx on FacebookMessages(message) type keyword;
 
-
 #### Functions
 
+The create function statement creates a named function that can then be used and reused in AQL queries.
+The body of a function can be any AQL expression involving the function's parameters.
+
     FunctionSpecification ::= "function" FunctionOrTypeName IfNotExists ParameterList "{" Expression "}"
+
+The following is a very simple example of a create function statement.
+It differs from the declare function example shown previously in that it results in a function that is
+persistently registered by name in the specified dataverse.
     
 ##### Example
     
@@ -396,7 +631,6 @@
       $a + $b
     };
     
-
 #### Removal
 
     DropStatement       ::= "drop" ( "dataverse" Identifier IfExists
@@ -405,7 +639,12 @@
                                    | "index" DoubleQualifiedName IfExists
                                    | "function" FunctionSignature IfExists )
     IfExists            ::= ( "if" "exists" )?
-    
+
+The drop statement in AQL is the inverse of the create statement.
+It can be used to drop dataverses, datatypes, datasets, indexes, and functions.
+
+The following examples illustrate uses of the drop statement.
+ 
 ##### Example
 
     drop dataset FacebookUsers if exists;
@@ -425,38 +664,66 @@
 ##### Example
 
     drop function add;
-    
 
 ### Import/Export Statements
 
     LoadStatement  ::= "load" "dataset" QualifiedName "using" AdapterName Configuration ( "pre-sorted" )?
     
+The load statement is used to initially populate a dataset via bulk loading of data from an external file.
+An appropriate adaptor must be selected to handle the nature of the desired external data.
+(See the guide to external data for more information on the available adaptors.)
+
+The following example shows how to bulk load the FacebookUsers dataset from an external file containing
+data that has been prepared in ADM format.
+
 ##### Example
 
     load dataset FacebookUsers using localfs
     (("path"="localhost:///Users/zuck/AsterixDB/load/fbu.adm"),("format"="adm"));
 
-
 ### Modification Statements
 
     InsertStatement ::= "insert" "into" "dataset" QualifiedName Query
-    DeleteStatement ::= "delete" Variable "from" "dataset" QualifiedName ( "where" Expression )?
+
+The AQL insert statement is used to insert data into a dataset.
+The data to be inserted comes from an AQL query expression.
+The expression can be as simple as a constant expression, or in general it can be any legal AQL query.
+Inserts in AsterixDB are processed transactionally, with the scope of each insert transaction
+being the insertion of a single object plus its affiliated secondary index entries (if any).
+If the query part of an insert returns a single object, then the insert statement itself will
+be a single, atomic transaction.
+If the query part returns multiple objects, then each object inserted will be handled independently
+as a tranaction.
+
+The following example illustrates a query-based insertion.
     
 ##### Example
 
     insert into dataset UsersCopy (for $user in dataset FacebookUsers return $user)
 
+    DeleteStatement ::= "delete" Variable "from" "dataset" QualifiedName ( "where" Expression )?
+
+The AQL delete statement is used to delete data from a target dataset.
+The data to be deleted is identified by a boolean expression involving the variable bound to the
+target dataset in the delete statement.
+Deletes in AsterixDB are processed transactionally, with the scope of each delete transaction
+being the deletion of a single object plus its affiliated secondary index entries (if any).
+If the boolean expression for a delete identifies a single object, then the delete statement itself
+will be a single, atomic transaction.
+If the expression identifies multiple objects, then each object deleted will be handled independently
+as a tranaction.
+
+The following example illustrates a single-object deletion.
+
 ##### Example
     
     delete $user from dataset FacebookUsers where $user.id = 8;
-    
 
-### Queries
-
-    Query ::= Expression
+We close this guide to AQL with one final example of a query expression.
     
 ##### Example
     
     for $praise in {{ "great", "brilliant", "awesome" }}
     return
-       string-concat(["AsterixDB is ", $praise])
+       string-concat(["AsterixDB is ", $praise]
+
diff --git a/asterix-doc/src/site/markdown/index.md b/asterix-doc/src/site/markdown/index.md
index cba2fdc..ff9efb2 100644
--- a/asterix-doc/src/site/markdown/index.md
+++ b/asterix-doc/src/site/markdown/index.md
@@ -1 +1,57 @@
-# AsterixDB
+# AsterixDB: A Big Data Management System _(Alpha Release)_ #
+
+## What Is AsterixDB? ##
+
+Welcome to the new home of the AsterixDB Big Data Management System (BDMS).
+The AsterixDB BDMS is the result of about 3.5 years of R&D involving researchers at UC Irvine, UC Riverside, and UC San Diego.
+The AsterixDB code base now consists of roughly 250K lines of Java code that has been co-developed at UC Irvine and UC Riverside.
+
+Initiated in 2009, the NSF-sponsored ASTERIX project has been developing new technologies for ingesting, storing, managing, indexing, querying, and analyzing vast quantities of semi-structured information.
+The project has been combining ideas from three distinct areas---semi-structured data, parallel databases, and data-intensive computing (a.k.a. today's Big Data platforms)---in order to create a next-generation, open-source software platform that scales by running on large, shared-nothing commodity computing clusters.
+The ASTERIX effort has been targeting a wide range of semi-structured information, ranging from "data" use cases---where information is well-typed and highly regular---to "content" use cases---where data tends to be irregular, much of each datum may be textual, and the ultimate schema for the various data types involved may be hard to anticipate up front.
+The ASTERIX project has been addressing technical issues including highly scalable data storage and indexing, semi-structured query processing on very large clusters, and merging time-tested parallel database techniques with modern data-intensive computing techniques to support performant yet declarative solutions to the problem of storing and analyzing semi-structured information effectively.
+The first fruits of this labor have been captured in the AsterixDB system that is now being released in preliminary or "Alpha" release form.
+We are hoping that the arrival of AsterixDB will mark the beginning of the "BDMS era", and we hope that both the Big Data community and the database community will find the AsterixDB system to be interesting and useful for a much broader class of problems than can be addressed with any one of today's current Big Data platforms and related technologies (e.g., Hadoop, Pig, Hive, HBase, MongoDB, and so on).  One of our project mottos has been "one size fits a bunch"---at least that has been our aim.  For more information about the research effort that led to the birth of AsterixDB, please refer to our NSF project web site: [http://asterix.ics.uci.edu/](http://asterix.ics.uci.edu/).
+
+In a nutshell, AsterixDB is a full-function BDMS with a rich feature set that distinguishes it from pretty much any other Big Data platform that's out and available today.  We believe that its feature set makes it well-suited to modern needs such as web data warehousing and social data storage and analysis.  AsterixDB has:
+
+ * A semistructured NoSQL style data model (ADM) resulting from extending JSON with object database ideas
+ * An expressive and declarative query language (AQL) that supports a broad range of queries and analysis over semistructured data
+ * A parallel runtime query execution engine, Hyracks, that has been scale-tested on up to 1000+ cores and 500+ disks
+ * Partitioned LSM-based data storage and indexing to support efficient ingestion and management of semistructured data
+ * Support for query access to externally stored data (e.g., data in HDFS) as well as to data stored natively by AsterixDB
+ * A rich set of primitive data types, including spatial and temporal data in addition to integer, floating point, and textual data
+ * Secondary indexing options that include B+ trees, R trees, and inverted keyword (exact and fuzzy) index types
+ * Support for fuzzy and spatial queries as well as for more traditional parametric queries
+ * Basic transactional (concurrency and recovery) capabilities akin to those of a NoSQL store
+
+## Getting and Using AsterixDB ##
+
+You are most likely here because you are interested in getting your hands on AsterixDB---so you would like to know how to get it, how to set it up, and how to use it.
+Someday our plan is to have comprehensive documentation for AsterixDB and its data model (ADM) and query language (AQL) here on this wiki.
+For the Alpha release, we've got a start; for the Beta release a month or so from now, we will hopefully have much more.
+The following is a list of the wiki pages and supporting documents that we have available today:
+
+1. [InstallingAsterixUsingManagix](InstallingAsterixUsingManagix.html) :
+This is our installation guide, and it is where you should start.
+This document will tell you how to obtain, install, and manage instances of [AsterixDB](https://asterixdb.googlecode.com/files/asterix-installer-0.0.4-binary-assembly.zip), including both single-machine setup (for developers) as well as cluster installations (for deployment in its intended form).
+
+2. [AdmAql101](AdmAql101.html) :
+This is a first-timers introduction to the user model of the AsterixDB BDMS, by which we mean the view of AsterixDB as seen from the perspective of an "average user" or Big Data application developer.
+The AsterixDB user model consists of its data modeling features (ADM) and its query capabilities (AQL).
+This document presents a tiny "social data warehousing" example and uses it as a backdrop for describing, by example, the key features of AsterixDB.
+By working through this document, you will learn how to define the artifacts needed to manage data in AsterixDB, how to load data into the system, how to use most of the basic features of its query language, and how to insert and delete data dynamically.
+
+3. [AsterixDataTypesAndFunctions](AsterixDataTypesAndFunctions.html) :
+This is a reference document that catalogs the primitive data types and built-in functions available for use in AsterixDB schemas (in ADM) and queries (in AQL).
+
+4. [AQL Reference](AsterixQueryLanguageReference.html) :
+This is the AQL language reference manual.
+
+5. [AsterixDBRestAPI](AsterixDBRestAPI.html) :
+Access to data in an AsterixDB instance is provided via a REST-based API.
+This is a short document that describes the REST API entry points and their URL syntax.
+
+To all who have now come this far: Thanks for your interest in AsterixDB, and for kicking its tires in its Alpha form
+In addition to getting the system and trying it out, please sign up as a member of the AsterixDB user mailing list (asterixdb-users (at) googlegroups.com) so that you can contact us easily with your questions, issues, and other feedback.
+We want AsterixDB to be a "big hit" some day, and we are anxious to see what users do with it and to learn from that feedback what we should be working on most urgently in the next phase of the project.
diff --git a/asterix-doc/src/site/site.xml b/asterix-doc/src/site/site.xml
index 6724153..4953eb4 100644
--- a/asterix-doc/src/site/site.xml
+++ b/asterix-doc/src/site/site.xml
@@ -29,7 +29,6 @@
     </links>
 
     <menu name="Documentation">
-      <item name="AsterixDB: A Big Data Management System" href="AsterixAlphaRelease.html"/>
       <item name="Installing Asterix using Managix" href="InstallingAsterixUsingManagix.html"/>
       <item name="AsterixDB 101: An ADM and AQL Primer" href="AdmAql101.html"/>
       <item name="Asterix Data Model (ADM)" href="AsterixDBDataModel.html"/>
@@ -38,7 +37,6 @@
       <item name="AsterixDB Support of Similarity Queries" href="AsterixSimilarityQueries.html"/>
       <item name="Accessing External Data in AsterixDB" href="AccessingExternalDataInAsterixDB.html"/>
       <item name="REST API to AsterixDB" href="AsterixDBRestAPI.html"/>
-      <item name="(old AQL doc)" href="AsterixQueryLanguage.html"/>      
     </menu>
 
     <menu ref="reports"/>
diff --git a/asterix-events/.gitignore b/asterix-events/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/asterix-events/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/asterix-installer/.gitignore b/asterix-installer/.gitignore
new file mode 100644
index 0000000..19f2e00
--- /dev/null
+++ b/asterix-installer/.gitignore
@@ -0,0 +1,2 @@
+/target
+/target
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AlterCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AlterCommand.java
index 814f3c9..32918a7 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AlterCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AlterCommand.java
@@ -30,7 +30,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         String instanceName = ((AlterConfig) config).name;
         InstallerUtil.validateAsterixInstanceExists(instanceName, State.INACTIVE);
         ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/BackupCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/BackupCommand.java
index 261de22..a0014f6 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/BackupCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/BackupCommand.java
@@ -35,7 +35,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         String asterixInstanceName = ((BackupConfig) config).name;
         AsterixInstance instance = InstallerUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
         List<BackupInfo> backupInfo = instance.getBackupInfo();
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java
index 01a409e..a99b530 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java
@@ -39,7 +39,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         ValidateCommand validateCommand = new ValidateCommand();
         boolean valid = validateCommand.validateCluster(((CreateConfig) config).clusterPath);
         if (!valid) {
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DeleteCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DeleteCommand.java
index 2279d8f..4c2bb09 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DeleteCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DeleteCommand.java
@@ -28,7 +28,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         String asterixInstanceName = ((DeleteConfig) config).name;
         AsterixInstance instance = InstallerUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
         PatternCreator pc = new PatternCreator();
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DescribeCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DescribeCommand.java
index 9306a56..66c6e77 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DescribeCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DescribeCommand.java
@@ -31,7 +31,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         String asterixInstanceName = ((DescribeConfig) config).name;
         boolean adminView = ((DescribeConfig) config).admin;
         if (asterixInstanceName != null) {
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/RestoreCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/RestoreCommand.java
index 9ef925a..d4d9de3 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/RestoreCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/RestoreCommand.java
@@ -30,7 +30,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         String asterixInstanceName = ((RestoreConfig) config).name;
         AsterixInstance instance = InstallerUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
         int backupId = ((RestoreConfig) config).backupId;
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ShutdownCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ShutdownCommand.java
index b9dd23d..f38184d 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ShutdownCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ShutdownCommand.java
@@ -22,7 +22,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(false);
         ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
         lookupService.stopService(InstallerDriver.getConfiguration());
     }
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java
index 1180a4e..9d3cb64 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java
@@ -33,7 +33,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         String asterixInstanceName = ((StartConfig) config).name;
         AsterixInstance instance = InstallerUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
         InstallerUtil.createAsterixZip(instance);
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StopCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StopCommand.java
index dfd8c5e..f78cfbc 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StopCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StopCommand.java
@@ -35,7 +35,7 @@
 
     @Override
     protected void execCommand() throws Exception {
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         String asterixInstanceName = ((StopConfig) config).name;
         AsterixInstance asterixInstance = InstallerUtil.validateAsterixInstanceExists(asterixInstanceName,
                 State.ACTIVE, State.UNUSABLE);
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/InstallerDriver.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/InstallerDriver.java
index 08249ee..a9ab53b 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/InstallerDriver.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/InstallerDriver.java
@@ -55,7 +55,7 @@
         return conf;
     }
 
-    public static void initConfig() throws Exception {
+    public static void initConfig(boolean ensureLookupServiceIsRunning) throws Exception {
         File configFile = new File(managixHome + File.separator + MANAGIX_CONF_XML);
         JAXBContext configCtx = JAXBContext.newInstance(Configuration.class);
         Unmarshaller unmarshaller = configCtx.createUnmarshaller();
@@ -63,7 +63,7 @@
         asterixZip = initBinary("asterix-server");
 
         ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
-        if (!lookupService.isRunning(conf)) {
+        if (ensureLookupServiceIsRunning && !lookupService.isRunning(conf)) {
             lookupService.startService(conf);
         }
     }
diff --git a/asterix-installer/src/test/java/edu/uci/ics/asterix/installer/test/AsterixInstallerIntegrationUtil.java b/asterix-installer/src/test/java/edu/uci/ics/asterix/installer/test/AsterixInstallerIntegrationUtil.java
index dc6f643..c7beb28 100644
--- a/asterix-installer/src/test/java/edu/uci/ics/asterix/installer/test/AsterixInstallerIntegrationUtil.java
+++ b/asterix-installer/src/test/java/edu/uci/ics/asterix/installer/test/AsterixInstallerIntegrationUtil.java
@@ -87,7 +87,7 @@
         cmdHandler.processCommand(command.split(" "));
 
         startZookeeper();
-        InstallerDriver.initConfig();
+        InstallerDriver.initConfig(true);
         createInstance();
         hcc = new HyracksConnection(CC_IP_ADDRESS, DEFAULT_HYRACKS_CC_CLIENT_PORT);
     }
diff --git a/asterix-om/.gitignore b/asterix-om/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/asterix-om/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/comparators/AObjectAscBinaryComparatorFactory.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/comparators/AObjectAscBinaryComparatorFactory.java
index f795b17..a6ac8f2 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/comparators/AObjectAscBinaryComparatorFactory.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/comparators/AObjectAscBinaryComparatorFactory.java
@@ -51,7 +51,7 @@
 
             @Override
             public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
-
+            	
                 if (b1[s1] == ATypeTag.NULL.serialize()) {
                     if (b2[s2] == ATypeTag.NULL.serialize())
                         return 0;
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
index 327faf1..b7df6ff 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
@@ -1,9 +1,11 @@
 package edu.uci.ics.asterix.dataflow.data.nontagged.printers;
 
+import java.io.IOException;
 import java.io.PrintStream;
 
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.data.IPrinter;
 
@@ -22,22 +24,22 @@
     public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
         long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;
 
-        int year = gCalInstance.getYear(chrononTime);
-        int month = gCalInstance.getMonthOfYear(chrononTime, year);
-
         ps.print("date(\"");
-        ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
-                .append("-").append(String.format("%02d", gCalInstance.getDayOfMonthYear(chrononTime, year, month)));
+        try {
+            gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, Fields.YEAR, Fields.DAY, false);
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
+        }
         ps.print("\")");
     }
 
     public void printString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
         long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;
 
-        int year = gCalInstance.getYear(chrononTime);
-        int month = gCalInstance.getMonthOfYear(chrononTime, year);
-
-        ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
-                .append("-").append(String.format("%02d", gCalInstance.getDayOfMonthYear(chrononTime, year, month)));
+        try {
+            gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, Fields.YEAR, Fields.DAY, false);
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
+        }
     }
 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
index 7cf1478..a412cb1 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
@@ -1,9 +1,11 @@
 package edu.uci.ics.asterix.dataflow.data.nontagged.printers;
 
+import java.io.IOException;
 import java.io.PrintStream;
 
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.data.IPrinter;
 
@@ -21,30 +23,25 @@
     public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
         long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
 
-        int year = gCalInstance.getYear(chrononTime);
-        int month = gCalInstance.getMonthOfYear(chrononTime, year);
-
         ps.print("datetime(\"");
-        ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
-                .append("-").append(String.format("%02d", gCalInstance.getDayOfMonthYear(chrononTime, year, month)))
-                .append("T").append(String.format("%02d", gCalInstance.getHourOfDay(chrononTime))).append(":")
-                .append(String.format("%02d", gCalInstance.getMinOfHour(chrononTime))).append(":")
-                .append(String.format("%02d", gCalInstance.getSecOfMin(chrononTime))).append(".")
-                .append(String.format("%03d", gCalInstance.getMillisOfSec(chrononTime))).append("Z");
+
+        try {
+            gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, Fields.YEAR, Fields.MILLISECOND, true);
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
+        }
+
         ps.print("\")");
     }
 
     public void printString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
         long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
 
-        int year = gCalInstance.getYear(chrononTime);
-        int month = gCalInstance.getMonthOfYear(chrononTime, year);
-
-        ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
-                .append("-").append(String.format("%02d", gCalInstance.getDayOfMonthYear(chrononTime, year, month)))
-                .append("T").append(String.format("%02d", gCalInstance.getHourOfDay(chrononTime))).append(":")
-                .append(String.format("%02d", gCalInstance.getMinOfHour(chrononTime))).append(":")
-                .append(String.format("%02d", gCalInstance.getSecOfMin(chrononTime))).append(".")
-                .append(String.format("%03d", gCalInstance.getMillisOfSec(chrononTime))).append("Z");
+        try {
+            gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, Fields.YEAR, Fields.MILLISECOND, true);
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
+        }
+        
     }
 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
index aba6a4b..6550906 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
@@ -1,9 +1,11 @@
 package edu.uci.ics.asterix.dataflow.data.nontagged.printers;
 
+import java.io.IOException;
 import java.io.PrintStream;
 
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
 import edu.uci.ics.hyracks.algebricks.data.IPrinter;
 
@@ -22,21 +24,24 @@
         int time = AInt32SerializerDeserializer.getInt(b, s + 1);
 
         ps.print("time(\"");
-        ps.append(String.format("%02d", gCalInstance.getHourOfDay(time))).append(":")
-                .append(String.format("%02d", gCalInstance.getMinOfHour(time))).append(":")
-                .append(String.format("%02d", gCalInstance.getSecOfMin(time))).append(".")
-                .append(String.format("%03d", gCalInstance.getMillisOfSec(time))).append("Z");
+
+        try {
+            gCalInstance.getExtendStringRepUntilField(time, 0, ps, Fields.HOUR, Fields.MILLISECOND, true);
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
+        }
 
         ps.print("\")");
     }
-    
+
     public void printString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
         int time = AInt32SerializerDeserializer.getInt(b, s + 1);
 
-        ps.append(String.format("%02d", gCalInstance.getHourOfDay(time))).append(":")
-                .append(String.format("%02d", gCalInstance.getMinOfHour(time))).append(":")
-                .append(String.format("%02d", gCalInstance.getSecOfMin(time))).append(".")
-                .append(String.format("%03d", gCalInstance.getMillisOfSec(time))).append("Z");
+        try {
+            gCalInstance.getExtendStringRepUntilField(time, 0, ps, Fields.HOUR, Fields.MILLISECOND, true);
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
+        }
     }
 
 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/formats/base/IDataFormat.java b/asterix-om/src/main/java/edu/uci/ics/asterix/formats/base/IDataFormat.java
index 11f65dc..51e0413 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/formats/base/IDataFormat.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/formats/base/IDataFormat.java
@@ -22,6 +22,7 @@
 import edu.uci.ics.hyracks.algebricks.data.ITypeTraitProvider;
 import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.INullWriterFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.IPredicateEvaluatorFactoryProvider;
 import edu.uci.ics.hyracks.dataflow.std.file.ITupleParserFactory;
 
 public interface IDataFormat {
@@ -68,4 +69,6 @@
     public INormalizedKeyComputerFactoryProvider getNormalizedKeyComputerFactoryProvider();
 
     public IBinaryHashFunctionFamilyProvider getBinaryHashFunctionFamilyProvider();
+    
+    public IPredicateEvaluatorFactoryProvider getPredicateEvaluatorFactoryProvider();
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/formats/nontagged/AqlPredicateEvaluatorFactoryProvider.java b/asterix-om/src/main/java/edu/uci/ics/asterix/formats/nontagged/AqlPredicateEvaluatorFactoryProvider.java
new file mode 100644
index 0000000..f4fa74e
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/formats/nontagged/AqlPredicateEvaluatorFactoryProvider.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ * 
+ *     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 edu.uci.ics.asterix.formats.nontagged;
+
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.hyracks.api.comm.IFrameTupleAccessor;
+import edu.uci.ics.hyracks.api.dataflow.value.IPredicateEvaluator;
+import edu.uci.ics.hyracks.api.dataflow.value.IPredicateEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.IPredicateEvaluatorFactoryProvider;
+
+/*
+Provides PredicateEvaluator for equi-join cases to properly take care of NULL fields, being compared with each other.
+If any of the join keys, from either side, is NULL, record should not pass equi-join condition.
+*/
+public class AqlPredicateEvaluatorFactoryProvider implements IPredicateEvaluatorFactoryProvider{
+	
+	private static final long serialVersionUID = 1L;
+	public static final AqlPredicateEvaluatorFactoryProvider INSTANCE = new AqlPredicateEvaluatorFactoryProvider();
+	
+	@Override
+	public IPredicateEvaluatorFactory getPredicateEvaluatorFactory(final int[] keys0, final int[] keys1) {
+		
+		return new IPredicateEvaluatorFactory() {
+			private static final long serialVersionUID = 1L;
+			@Override
+			public IPredicateEvaluator createPredicateEvaluator() {
+				return new IPredicateEvaluator() {
+					
+					@Override
+					public boolean evaluate(IFrameTupleAccessor fta0, int tupId0,
+							IFrameTupleAccessor fta1, int tupId1) {
+						
+						int tStart0 = fta0.getTupleStartOffset(tupId0);
+				        int fStartOffset0 = fta0.getFieldSlotsLength() + tStart0;
+						
+						for(int k0 : keys0){
+							int fieldStartIx = fta0.getFieldStartOffset(tupId0, k0);
+							ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(fta0.getBuffer().array()[fieldStartIx + fStartOffset0]);
+							if(typeTag == ATypeTag.NULL){
+								return false;
+							}
+						}
+						
+						int tStart1 = fta1.getTupleStartOffset(tupId1);
+				        int fStartOffset1 = fta1.getFieldSlotsLength() + tStart1;
+				        
+						for(int k1 : keys1){
+							int fieldStartIx = fta1.getFieldStartOffset(tupId1, k1);
+							ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(fta1.getBuffer().array()[fieldStartIx + fStartOffset1]);
+							if(typeTag == ATypeTag.NULL){
+								return false;
+							}
+						}
+						
+						return true;	//none of the fields (from both sides) is NULL
+					}
+				};
+			}
+		};
+	}
+
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
index 0ef170e..28008b2 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
@@ -14,6 +14,8 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import java.io.IOException;
+
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -75,9 +77,12 @@
     public String toString() {
         StringBuilder sbder = new StringBuilder();
         sbder.append("ADate: { ");
-        GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(
-                chrononTimeInDay * CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR,
-                GregorianCalendarSystem.Fields.DAY);
+        try {
+            GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(chrononTimeInDay * CHRONON_OF_DAY, 0,
+                    sbder, GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.DAY, false);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
         sbder.append(" }");
         return sbder.toString();
     }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
index 081fa63..10d49aa 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
@@ -14,6 +14,8 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import java.io.IOException;
+
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -106,8 +108,12 @@
     public String toString() {
         StringBuilder sbder = new StringBuilder();
         sbder.append("ADateTime: { ");
-        GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(chrononTime, 0, sbder,
-                GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND);
+        try {
+            GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(chrononTime, 0, sbder,
+                    GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
         sbder.append(" }");
         return sbder.toString();
     }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInterval.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInterval.java
index f1352f1..e3c5213 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInterval.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInterval.java
@@ -14,6 +14,8 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import java.io.IOException;
+
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -100,33 +102,38 @@
     public String toString() {
         StringBuilder sbder = new StringBuilder();
         sbder.append("AInterval: { ");
-        if (typetag == ATypeTag.DATE.serialize()) {
-            sbder.append("ADate: { ");
-            GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(
-                    intervalStart * ADate.CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR,
-                    GregorianCalendarSystem.Fields.DAY);
-            sbder.append(" }, ADate: {");
-            GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(
-                    intervalEnd * ADate.CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR,
-                    GregorianCalendarSystem.Fields.DAY);
-            sbder.append(" }");
-        } else if (typetag == ATypeTag.TIME.serialize()) {
-            sbder.append("ATime: { ");
-            GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(intervalStart, 0, sbder,
-                    GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND);
-            sbder.append(" }, ATime: { ");
+        try {
+            if (typetag == ATypeTag.DATE.serialize()) {
+                sbder.append("ADate: { ");
 
-            GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(intervalEnd, 0, sbder,
-                    GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND);
-            sbder.append(" }");
-        } else if (typetag == ATypeTag.DATETIME.serialize()) {
-            sbder.append("ADateTime: { ");
-            GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(intervalStart, 0, sbder,
-                    GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND);
-            sbder.append(" }, ADateTime: { ");
-            GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(intervalEnd, 0, sbder,
-                    GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND);
-            sbder.append(" }");
+                GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(
+                        intervalStart * ADate.CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR,
+                        GregorianCalendarSystem.Fields.DAY, false);
+
+                sbder.append(" }, ADate: {");
+                GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalEnd * ADate.CHRONON_OF_DAY,
+                        0, sbder, GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.DAY, false);
+                sbder.append(" }");
+            } else if (typetag == ATypeTag.TIME.serialize()) {
+                sbder.append("ATime: { ");
+                GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalStart, 0, sbder,
+                        GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+                sbder.append(" }, ATime: { ");
+
+                GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalEnd, 0, sbder,
+                        GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+                sbder.append(" }");
+            } else if (typetag == ATypeTag.DATETIME.serialize()) {
+                sbder.append("ADateTime: { ");
+                GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalStart, 0, sbder,
+                        GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+                sbder.append(" }, ADateTime: { ");
+                GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalEnd, 0, sbder,
+                        GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+                sbder.append(" }");
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
         }
         sbder.append(" }");
         return sbder.toString();
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
index b97ed51..edbf007 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
@@ -14,6 +14,8 @@
  */
 package edu.uci.ics.asterix.om.base;
 
+import java.io.IOException;
+
 import org.json.JSONException;
 import org.json.JSONObject;
 
@@ -90,8 +92,12 @@
     public String toString() {
         StringBuilder sbder = new StringBuilder();
         sbder.append("ATime: { ");
-        GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(chrononTime, 0, sbder,
-                GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND);
+        try {
+            GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(chrononTime, 0, sbder,
+                    GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
         sbder.append(" }");
         return sbder.toString();
 
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParserFactory.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParserFactory.java
index 84e2386..a651716 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParserFactory.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParserFactory.java
@@ -248,18 +248,30 @@
             throw new HyracksDataException(durationErrorMessage + ": no time fields after time separator.");
         }
 
+        int totalMonths = sign * (year * 12 + month);
+        long totalMilliseconds = sign
+                * (day * GregorianCalendarSystem.CHRONON_OF_DAY + hour * GregorianCalendarSystem.CHRONON_OF_HOUR
+                        + minute * GregorianCalendarSystem.CHRONON_OF_MINUTE + second
+                        * GregorianCalendarSystem.CHRONON_OF_SECOND + millisecond);
+
+        if (sign > 0) {
+            if (totalMonths < 0) {
+                throw new HyracksDataException(durationErrorMessage
+                        + ": total number of months is beyond its max value (-2147483647 to 2147483647).");
+            }
+            if (totalMilliseconds < 0) {
+                throw new HyracksDataException(
+                        durationErrorMessage
+                                + ": total number of milliseconds is beyond its max value (-9223372036854775808 to 9223372036854775807).");
+            }
+        }
+
         if (mutableObject instanceof AMutableDuration) {
-            ((AMutableDuration) mutableObject)
-                    .setValue(sign * (year * 12 + month),
-                            sign
-                                    * (day * 24 * 3600 * 1000L + 3600 * 1000L * hour + 60 * minute * 1000L + second
-                                            * 1000L + millisecond));
+            ((AMutableDuration) mutableObject).setValue(totalMonths, totalMilliseconds);
         } else if (mutableObject instanceof AMutableYearMonthDuration) {
-            ((AMutableYearMonthDuration) mutableObject).setMonths(sign * (year * 12 + month));
+            ((AMutableYearMonthDuration) mutableObject).setMonths(totalMonths);
         } else if (mutableObject instanceof AMutableDayTimeDuration) {
-            ((AMutableDayTimeDuration) mutableObject)
-                    .setMilliseconds(sign
-                            * (day * 24 * 3600 * 1000L + 3600 * 1000L * hour + 60 * minute * 1000L + second * 1000L + millisecond));
+            ((AMutableDayTimeDuration) mutableObject).setMilliseconds(totalMilliseconds);
         }
     }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
index f74af9b..8c21bad 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
@@ -30,6 +30,8 @@
  */
 package edu.uci.ics.asterix.om.base.temporal;
 
+import java.io.IOException;
+
 /**
  * A simple implementation of the Gregorian calendar system.
  * <p/>
@@ -53,9 +55,9 @@
 
     public static final int[] DAYS_SINCE_MONTH_BEGIN_ORDI = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
 
-    public static final int CHRONON_OF_SECOND = 1000;
-    public static final int CHRONON_OF_MINUTE = 60 * CHRONON_OF_SECOND;
-    public static final int CHRONON_OF_HOUR = 60 * CHRONON_OF_MINUTE;
+    public static final long CHRONON_OF_SECOND = 1000;
+    public static final long CHRONON_OF_MINUTE = 60 * CHRONON_OF_SECOND;
+    public static final long CHRONON_OF_HOUR = 60 * CHRONON_OF_MINUTE;
     public static final long CHRONON_OF_DAY = 24 * CHRONON_OF_HOUR;
     public static final int MONTHS_IN_A_YEAR = 12;
 
@@ -234,9 +236,9 @@
      */
     public int getChronon(int hour, int min, int sec, int millis, int timezone) {
         // Added milliseconds for all fields but month and day
-        int chrononTime = (hour - timezone / 4) * CHRONON_OF_HOUR + (min - (timezone % 4) * 15) * CHRONON_OF_MINUTE
+        long chrononTime = (hour - timezone / 4) * CHRONON_OF_HOUR + (min - (timezone % 4) * 15) * CHRONON_OF_MINUTE
                 + sec * CHRONON_OF_SECOND + millis;
-        return chrononTime;
+        return (int)chrononTime;
     }
 
     public long adjustChrononByTimezone(long chronon, int timezone) {
@@ -268,8 +270,8 @@
      * @param sbder
      * @param untilField
      */
-    public void getExtendStringRepWithTimezoneUntilField(long chrononTime, int timezone, StringBuilder sbder,
-            Fields startField, Fields untilField) {
+    public void getExtendStringRepUntilField(long chrononTime, int timezone, Appendable sbder, Fields startField,
+            Fields untilField, boolean withTimezone) throws IOException {
 
         int year = getYear(chrononTime);
         int month = getMonthOfYear(chrononTime, year);
@@ -323,16 +325,18 @@
                 break;
         }
 
-        if (timezone == 0) {
-            sbder.append("Z");
-        } else {
-            short tzMin = (short) ((timezone % 4) * 15);
-            if (tzMin < 0) {
-                tzMin = (short) (-1 * tzMin);
+        if (withTimezone) {
+            if (timezone == 0) {
+                sbder.append("Z");
+            } else {
+                short tzMin = (short) ((timezone % 4) * 15);
+                if (tzMin < 0) {
+                    tzMin = (short) (-1 * tzMin);
+                }
+                short tzHr = (short) (timezone / 4);
+                sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr)))
+                        .append(":").append(String.format("%02d", tzMin));
             }
-            short tzHr = (short) (timezone / 4);
-            sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr))).append(":")
-                    .append(String.format("%02d", tzMin));
         }
     }
 
@@ -343,8 +347,8 @@
      * @param timezone
      * @param sbder
      */
-    public void getBasicStringRepWithTimezoneUntilField(long chrononTime, int timezone, StringBuilder sbder,
-            Fields startField, Fields untilField) {
+    public void getBasicStringRepUntilField(long chrononTime, int timezone, Appendable sbder, Fields startField,
+            Fields untilField, boolean withTimezone) throws IOException {
         int year = getYear(chrononTime);
         int month = getMonthOfYear(chrononTime, year);
 
@@ -382,16 +386,18 @@
                 break;
         }
 
-        if (timezone == 0) {
-            sbder.append("Z");
-        } else {
-            short tzMin = (short) ((timezone % 4) * 15);
-            if (tzMin < 0) {
-                tzMin = (short) (-1 * tzMin);
+        if (withTimezone) {
+            if (timezone == 0) {
+                sbder.append("Z");
+            } else {
+                short tzMin = (short) ((timezone % 4) * 15);
+                if (tzMin < 0) {
+                    tzMin = (short) (-1 * tzMin);
+                }
+                short tzHr = (short) (timezone / 4);
+                sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr)))
+                        .append(String.format("%02d", tzMin));
             }
-            short tzHr = (short) (timezone / 4);
-            sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr)))
-                    .append(String.format("%02d", tzMin));
         }
     }
 
@@ -480,8 +486,7 @@
      * Get the year for the given chronon time.
      * <p/>
      * This code is directly from the Joda library BadicChronology.java.<br/>
-     * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May
-     * 7th, 2012.
+     * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012.
      * 
      * @param chrononTime
      * @return
@@ -528,8 +533,7 @@
      * Get the month of the year for the given chronon time and the year.
      * <p/>
      * This code is directly from the Joda library BasicGJChronology.java.<br/>
-     * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May
-     * 7th, 2012 and commented by Theodoros Ioannou on July 2012.
+     * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012 and commented by Theodoros Ioannou on July 2012.
      * <p/>
      * 
      * @param millis
@@ -593,8 +597,7 @@
      * Get the day of the given month and year for the input chronon time.
      * <p/>
      * This function is directly from Joda Library BasicChronology.java.<br/>
-     * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May
-     * 7th, 2012.
+     * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012.
      * <p/>
      * 
      * @param millis
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
index 037cd29..7d20886 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
@@ -254,6 +254,8 @@
                 throw new AlgebricksException("A field with this name  \"" + fieldName + "\" could not be found.");
             }
             switch (fieldType.getTypeTag()) {
+                case INT8:
+                case INT16:
                 case INT32:
                 case INT64:
                 case FLOAT:
@@ -305,6 +307,8 @@
                         case TIME:
                         case DATETIME:
                         case UNION:
+                        case YEARMONTHDURATION:
+                        case DAYTIMEDURATION:
                             break;
                         default:
                             throw new AlgebricksException("The field \"" + fieldName + "\" which is of type "
diff --git a/asterix-runtime/.gitignore b/asterix-runtime/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/asterix-runtime/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
index ce9ecd2..2bd874f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
@@ -6,7 +6,6 @@
 
 import java.io.DataOutput;
 import java.util.Arrays;
-import java.util.regex.Pattern;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.AMutableString;
@@ -24,9 +23,6 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
-/**
- * @author ilovesoup
- */
 public abstract class AbstractQuadStringStringEval implements ICopyEvaluator {
 
     private DataOutput dout;
@@ -138,7 +134,7 @@
             } else if (c == '_') {
                 sb.append(".");
             } else {
-                if (Arrays.binarySearch(reservedRegexChars, c) >= 0) {
+                if (Arrays.binarySearch(StringEvaluatorUtils.reservedRegexChars, c) >= 0) {
                     sb.append('\\');
                 }
                 sb.append(c);
@@ -147,33 +143,4 @@
         return sb.toString();
     }
 
-    protected int toFlag(AString pattern) {
-        String str = pattern.getStringValue();
-        int flag = 0;
-        for (int i = 0; i < str.length(); i++) {
-            char c = str.charAt(i);
-            switch (c) {
-                case 's':
-                    flag |= Pattern.DOTALL;
-                    break;
-                case 'm':
-                    flag |= Pattern.MULTILINE;
-                    break;
-                case 'i':
-                    flag |= Pattern.CASE_INSENSITIVE;
-                    break;
-                case 'x':
-                    flag |= Pattern.COMMENTS;
-                    break;
-            }
-        }
-        return flag;
-    }
-
-    private final static char[] reservedRegexChars = new char[] { '\\', '(', ')', '[', ']', '{', '}', '.', '^', '$',
-            '*', '|' };
-
-    static {
-        Arrays.sort(reservedRegexChars);
-    }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
index a3be797..7d0a01f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
@@ -2,7 +2,6 @@
 
 import java.io.DataOutput;
 import java.util.Arrays;
-import java.util.regex.Pattern;
 
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.ABoolean;
@@ -19,9 +18,6 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
-/**
- * @author Xiaoyu Ma
- */
 public abstract class AbstractTripleStringBoolEval implements ICopyEvaluator {
 
     private DataOutput dout;
@@ -118,7 +114,7 @@
             } else if (c == '_') {
                 sb.append(".");
             } else {
-                if (Arrays.binarySearch(reservedRegexChars, c) >= 0) {
+                if (Arrays.binarySearch(StringEvaluatorUtils.reservedRegexChars, c) >= 0) {
                     sb.append('\\');
                 }
                 sb.append(c);
@@ -126,34 +122,4 @@
         }
         return sb.toString();
     }
-
-    protected int toFlag(AString pattern) {
-        String str = pattern.getStringValue();
-        int flag = 0;
-        for (int i = 0; i < str.length(); i++) {
-            char c = str.charAt(i);
-            switch (c) {
-                case 's':
-                    flag |= Pattern.DOTALL;
-                    break;
-                case 'm':
-                    flag |= Pattern.MULTILINE;
-                    break;
-                case 'i':
-                    flag |= Pattern.CASE_INSENSITIVE;
-                    break;
-                case 'x':
-                    flag |= Pattern.COMMENTS;
-                    break;
-            }
-        }
-        return flag;
-    }
-
-    private final static char[] reservedRegexChars = new char[] { '\\', '(', ')', '[', ']', '{', '}', '.', '^', '$',
-            '*', '|' };
-
-    static {
-        Arrays.sort(reservedRegexChars);
-    }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
index 41d0b3d..4833f16 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
@@ -20,9 +20,6 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
-/**
- * @author Xiaoyu Ma
- */
 public abstract class AbstractTripleStringStringEval implements ICopyEvaluator {
 
     private DataOutput dout;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
index 1a3e1b8..14651fe 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
@@ -21,9 +21,6 @@
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import edu.uci.ics.hyracks.dataflow.common.data.util.StringUtils;
 
-/**
- * @author Xiaoyu Ma
- */
 public class CodePointToStringDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodepointIterator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodepointIterator.java
index f103e0f..1365277 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodepointIterator.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodepointIterator.java
@@ -2,10 +2,6 @@
 
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
 
-/**
- *
- * @author Xiaoyu Ma
- */
 public class CodepointIterator {
     public void reset(byte [] buf, int startPos) {
         this.buf = buf;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAddDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAddDescriptor.java
index 0181698..10aea29 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAddDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAddDescriptor.java
@@ -27,7 +27,7 @@
             if (y > 0 && z < 0)
                 throw new ArithmeticException("Overflow adding " + x + " + " + y);
         } else if (y < 0 && z > 0)
-            throw new ArithmeticException("Overflow adding " + x + " + " + y);
+            throw new ArithmeticException("Underflow adding " + x + " + " + y);
         return z;
     }
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringConcatDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
index bcd199c..5ffcb29 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
@@ -25,9 +25,6 @@
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import edu.uci.ics.hyracks.dataflow.common.data.util.StringUtils;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringConcatDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEndWithDescrtiptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEndWithDescrtiptor.java
index 6d0eaad..3e08fa3 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEndWithDescrtiptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEndWithDescrtiptor.java
@@ -18,9 +18,6 @@
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringEndWithDescrtiptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEqualDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
index e921e45..e778f3e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
@@ -14,9 +14,6 @@
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringEqualDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEvaluatorUtils.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEvaluatorUtils.java
new file mode 100644
index 0000000..98a70b4
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEvaluatorUtils.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ * 
+ *     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 edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.util.regex.Pattern;
+
+import edu.uci.ics.asterix.om.base.AString;
+
+public class StringEvaluatorUtils {
+
+    public static int toFlag(AString pattern) {
+        String str = pattern.getStringValue();
+        int flag = 0;
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            switch (c) {
+                case 's':
+                    flag |= Pattern.DOTALL;
+                    break;
+                case 'm':
+                    flag |= Pattern.MULTILINE;
+                    break;
+                case 'i':
+                    flag |= Pattern.CASE_INSENSITIVE;
+                    break;
+                case 'x':
+                    flag |= Pattern.COMMENTS;
+                    break;
+            }
+        }
+        return flag;
+    }
+
+    public final static char[] reservedRegexChars = new char[] { '$', '(', ')', '*', '.', '[', '\\', ']', '^', '{',
+            '|', '}' };
+    
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringJoinDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
index 9c2f960..7742ccc 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
@@ -21,9 +21,6 @@
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import edu.uci.ics.hyracks.dataflow.common.data.util.StringUtils;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringJoinDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
index 5e188d3..d8d0b55 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
@@ -23,9 +23,6 @@
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 import edu.uci.ics.hyracks.dataflow.common.data.util.StringUtils;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringLowerCaseDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
index 03a3545..e26a0c6 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
@@ -26,9 +26,6 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringMatchesDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
index 93dc342..6da320b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
@@ -30,9 +30,6 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringMatchesWithFlagDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
@@ -112,7 +109,7 @@
                                 DataInputStream di = new DataInputStream(new ByteArrayInputStream(
                                         lastFlags.getByteArray()));
                                 astrFlags = (AString) stringSerde.deserialize(di);
-                                flags = toFlag(astrFlags);
+                                flags = StringEvaluatorUtils.toFlag(astrFlags);
                             }
 
                             pattern = Pattern.compile(strPattern, flags);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
index 230eb34..c8917dc 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
@@ -26,9 +26,6 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringReplaceDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
index 4f18863..74c30e7 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
@@ -26,9 +26,6 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringReplaceWithFlagsDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
@@ -130,7 +127,7 @@
                                 DataInputStream di = new DataInputStream(new ByteArrayInputStream(
                                         lastFlags.getByteArray()));
                                 astrFlags = (AString) stringSerde.deserialize(di);
-                                flags = toFlag(astrFlags);
+                                flags = StringEvaluatorUtils.toFlag(astrFlags);
                             }
 
                             if (newPattern || newFlags)
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java
index 601c3d0..c852fbc 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java
@@ -14,9 +14,6 @@
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringStartWithDescrtiptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
index e001d9e..d34280e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
@@ -25,18 +25,10 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
-/**
- * @author Xiaoyu Ma
- */
 public class StringToCodePointDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
 
-    public static final IFunctionDescriptorFactory FACTORY1 = new IFunctionDescriptorFactory() {
-        public IFunctionDescriptor createFunctionDescriptor() {
-            return new StringToCodePointDescriptor();
-        }
-    };
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new StringToCodePointDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
index 77911af..61d5d72 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
@@ -72,8 +72,7 @@
                         int posPattern = 3;
 
                         int offset = 0;
-                        while (posSrc - 3 < srcLen - patternLen) {
-                            // offset = 0;                        
+                        while (posSrc - 3 < srcLen - patternLen) {                       
                             while (posPattern + offset - 3 < patternLen && posSrc + offset - 3 < srcLen) {
                                 char c1 = UTF8StringPointable.charAt(src, posSrc + offset);
                                 char c2 = UTF8StringPointable.charAt(pattern, posPattern + offset);
@@ -82,7 +81,6 @@
                                 offset++;
                             }
                             if (offset == patternLen) {
-                                // found = true;
                                 break;
                             }
                             posSrc += UTF8StringPointable.charSize(src, posSrc);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
index 441d20a..55b9663 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
@@ -120,8 +120,8 @@
 
                             StringBuilder sbder = new StringBuilder();
 
-                            calInstance.getExtendStringRepWithTimezoneUntilField(chronon, timezone, sbder, Fields.YEAR,
-                                    Fields.MILLISECOND);
+                            calInstance.getExtendStringRepUntilField(chronon, timezone, sbder, Fields.YEAR,
+                                    Fields.MILLISECOND, true);
 
                             out.writeByte(SER_STRING_TYPE_TAG);
                             out.writeUTF(sbder.toString());
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
index 1ca64c6..340545d 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
@@ -120,8 +120,8 @@
 
                             StringBuilder sbder = new StringBuilder();
 
-                            calInstance.getExtendStringRepWithTimezoneUntilField(chronon, timezone, sbder, Fields.HOUR,
-                                    Fields.MILLISECOND);
+                            calInstance.getExtendStringRepUntilField(chronon, timezone, sbder, Fields.HOUR,
+                                    Fields.MILLISECOND, true);
 
                             out.writeByte(SER_STRING_TYPE_TAG);
                             out.writeUTF(sbder.toString());
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
index c6da17e..b343f63 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDuartionFromDateDescriptor.java
@@ -187,8 +187,9 @@
 
                                 if (day < 0) {
                                     boolean isLeapYear = calInstanct.isLeapYear(year1);
-                                    day += (isLeapYear) ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[month1 - 2])
-                                            : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[month1 - 2]);
+                                    // need to "borrow" the days in previous month to make the day positive; when month is 1 (Jan), Dec will be borrowed
+                                    day += (isLeapYear) ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[(12 + month1 - 2) % 12])
+                                            : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[(12 + month1 - 2) % 12]);
                                     month -= 1;
                                 }
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDurationFromDateTimeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDurationFromDateTimeDescriptor.java
index e09f1da..a934473 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDurationFromDateTimeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CalendarDurationFromDateTimeDescriptor.java
@@ -201,8 +201,9 @@
 
                                 if (day < 0) {
                                     boolean isLeapYear = calInstanct.isLeapYear(year1);
-                                    day += (isLeapYear) ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[month1 - 2])
-                                            : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[month1 - 2]);
+                                    // need to "borrow" the days in previous month to make the day positive; when month is 1 (Jan), Dec will be borrowed
+                                    day += (isLeapYear) ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[(12 + month1 - 2) % 12])
+                                            : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[(12 + month1 - 2) % 12]);
                                     month -= 1;
                                 }
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
index af647e9..a5cb0f1 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
@@ -21,6 +21,7 @@
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryIntegerInspector;
 import edu.uci.ics.asterix.formats.nontagged.AqlJSONPrinterFactoryProvider;
 import edu.uci.ics.asterix.formats.nontagged.AqlNormalizedKeyComputerFactoryProvider;
+import edu.uci.ics.asterix.formats.nontagged.AqlPredicateEvaluatorFactoryProvider;
 import edu.uci.ics.asterix.formats.nontagged.AqlPrinterFactoryProvider;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.formats.nontagged.AqlTypeTraitProvider;
@@ -274,6 +275,7 @@
 import edu.uci.ics.hyracks.algebricks.runtime.evaluators.ColumnAccessEvalFactory;
 import edu.uci.ics.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory;
 import edu.uci.ics.hyracks.api.dataflow.value.INullWriterFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.IPredicateEvaluatorFactoryProvider;
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 import edu.uci.ics.hyracks.dataflow.common.data.parsers.DoubleParserFactory;
@@ -937,4 +939,9 @@
         return AqlBinaryHashFunctionFamilyProvider.INSTANCE;
     }
 
+	@Override
+	public IPredicateEvaluatorFactoryProvider getPredicateEvaluatorFactoryProvider() {
+		return AqlPredicateEvaluatorFactoryProvider.INSTANCE;
+	}
+
 }
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/PersistentLocalResourceRepository.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
index 2361bac..a8f129a 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
@@ -153,16 +153,26 @@
                     if (indexFileList != null) {
                         for (File indexFile : indexFileList) {
                             if (indexFile.isDirectory()) {
-                                File[] metadataFiles = indexFile.listFiles(filter);
-                                if (metadataFiles != null) {
-                                    for (File metadataFile : metadataFiles) {
-                                        LocalResource localResource = readLocalResource(metadataFile);
-                                        id2ResourceMap.put(localResource.getResourceId(), localResource);
-                                        name2ResourceMap.put(localResource.getResourceName(), localResource);
-                                        maxResourceId = Math.max(localResource.getResourceId(), maxResourceId);
-                                        if (LOGGER.isLoggable(Level.INFO)) {
-                                            LOGGER.info("loaded local resource - [id: " + localResource.getResourceId()
-                                                    + ", name: " + localResource.getResourceName() + "]");
+                                File[] ioDevicesList = indexFile.listFiles();
+                                if (ioDevicesList != null) {
+                                    for (File ioDeviceFile : ioDevicesList) {
+                                        if (ioDeviceFile.isDirectory()) {
+                                            File[] metadataFiles = ioDeviceFile.listFiles(filter);
+                                            if (metadataFiles != null) {
+                                                for (File metadataFile : metadataFiles) {
+                                                    LocalResource localResource = readLocalResource(metadataFile);
+                                                    id2ResourceMap.put(localResource.getResourceId(), localResource);
+                                                    name2ResourceMap
+                                                            .put(localResource.getResourceName(), localResource);
+                                                    maxResourceId = Math.max(localResource.getResourceId(),
+                                                            maxResourceId);
+                                                    if (LOGGER.isLoggable(Level.INFO)) {
+                                                        LOGGER.info("loaded local resource - [id: "
+                                                                + localResource.getResourceId() + ", name: "
+                                                                + localResource.getResourceName() + "]");
+                                                    }
+                                                }
+                                            }
                                         }
                                     }
                                 }