You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by im...@apache.org on 2015/05/08 21:24:04 UTC

[1/2] incubator-asterixdb git commit: Range connector update with order by hint.

Repository: incubator-asterixdb
Updated Branches:
  refs/heads/master 561a8d428 -> d2d78adcf


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-aql/src/main/javacc/AQL.jj
----------------------------------------------------------------------
diff --git a/asterix-aql/src/main/javacc/AQL.jj b/asterix-aql/src/main/javacc/AQL.jj
index 7ed63b1..3e64da4 100644
--- a/asterix-aql/src/main/javacc/AQL.jj
+++ b/asterix-aql/src/main/javacc/AQL.jj
@@ -10,45 +10,125 @@ PARSER_BEGIN(AQLParser)
 
 package edu.uci.ics.asterix.aql.parser;
 
-import java.io.*;
-import java.util.List;
+// For AQLParserTokenManager
+import org.apache.xerces.util.IntStack;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.ArrayList;
-import java.util.Map;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 
-import org.apache.xerces.util.IntStack;
-
-import edu.uci.ics.asterix.aql.literal.FloatLiteral;
+import edu.uci.ics.asterix.aql.base.Clause;
+import edu.uci.ics.asterix.aql.base.Expression;
+import edu.uci.ics.asterix.aql.base.Literal;
+import edu.uci.ics.asterix.aql.base.Statement;
+import edu.uci.ics.asterix.aql.context.RootScopeFactory;
+import edu.uci.ics.asterix.aql.context.Scope;
+import edu.uci.ics.asterix.aql.expression.AbstractAccessor;
+import edu.uci.ics.asterix.aql.expression.CallExpr;
+import edu.uci.ics.asterix.aql.expression.CompactStatement;
+import edu.uci.ics.asterix.aql.expression.ConnectFeedStatement;
+import edu.uci.ics.asterix.aql.expression.CreateDataverseStatement;
+import edu.uci.ics.asterix.aql.expression.CreateFeedStatement;
+import edu.uci.ics.asterix.aql.expression.CreateFunctionStatement;
+import edu.uci.ics.asterix.aql.expression.CreateIndexStatement;
+import edu.uci.ics.asterix.aql.expression.DatasetDecl;
+import edu.uci.ics.asterix.aql.expression.DataverseDecl;
+import edu.uci.ics.asterix.aql.expression.DataverseDropStatement;
+import edu.uci.ics.asterix.aql.expression.DeleteStatement;
+import edu.uci.ics.asterix.aql.expression.DisconnectFeedStatement;
+import edu.uci.ics.asterix.aql.expression.DistinctClause;
+import edu.uci.ics.asterix.aql.expression.DropStatement;
+import edu.uci.ics.asterix.aql.expression.ExternalDetailsDecl;
+import edu.uci.ics.asterix.aql.expression.FLWOGRExpression;
+import edu.uci.ics.asterix.aql.expression.FeedDropStatement;
+import edu.uci.ics.asterix.aql.expression.FieldAccessor;
+import edu.uci.ics.asterix.aql.expression.FieldBinding;
+import edu.uci.ics.asterix.aql.expression.ForClause;
+import edu.uci.ics.asterix.aql.expression.FunctionDecl;
+import edu.uci.ics.asterix.aql.expression.FunctionDropStatement;
+import edu.uci.ics.asterix.aql.expression.GbyVariableExpressionPair;
+import edu.uci.ics.asterix.aql.expression.GroupbyClause;
+import edu.uci.ics.asterix.aql.expression.Identifier;
+import edu.uci.ics.asterix.aql.expression.IfExpr;
+import edu.uci.ics.asterix.aql.expression.IndexAccessor;
+import edu.uci.ics.asterix.aql.expression.IndexDropStatement;
+import edu.uci.ics.asterix.aql.expression.InsertStatement;
+import edu.uci.ics.asterix.aql.expression.InternalDetailsDecl;
+import edu.uci.ics.asterix.aql.expression.LetClause;
+import edu.uci.ics.asterix.aql.expression.LimitClause;
+import edu.uci.ics.asterix.aql.expression.ListConstructor;
+import edu.uci.ics.asterix.aql.expression.LiteralExpr;
+import edu.uci.ics.asterix.aql.expression.LoadStatement;
+import edu.uci.ics.asterix.aql.expression.NodeGroupDropStatement;
+import edu.uci.ics.asterix.aql.expression.NodegroupDecl;
+import edu.uci.ics.asterix.aql.expression.OperatorExpr;
+import edu.uci.ics.asterix.aql.expression.OrderbyClause;
+import edu.uci.ics.asterix.aql.expression.OrderedListTypeDefinition;
+import edu.uci.ics.asterix.aql.expression.QuantifiedExpression;
+import edu.uci.ics.asterix.aql.expression.QuantifiedPair;
+import edu.uci.ics.asterix.aql.expression.Query;
+import edu.uci.ics.asterix.aql.expression.RecordConstructor;
+import edu.uci.ics.asterix.aql.expression.RecordTypeDefinition;
+import edu.uci.ics.asterix.aql.expression.RefreshExternalDatasetStatement;
+import edu.uci.ics.asterix.aql.expression.RunStatement;
+import edu.uci.ics.asterix.aql.expression.SetStatement;
+import edu.uci.ics.asterix.aql.expression.TypeDecl;
+import edu.uci.ics.asterix.aql.expression.TypeDropStatement;
+import edu.uci.ics.asterix.aql.expression.TypeExpression;
+import edu.uci.ics.asterix.aql.expression.TypeReferenceExpression;
+import edu.uci.ics.asterix.aql.expression.UnaryExpr;
+import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
+import edu.uci.ics.asterix.aql.expression.UnionExpr;
+import edu.uci.ics.asterix.aql.expression.UnorderedListTypeDefinition;
+import edu.uci.ics.asterix.aql.expression.UpdateClause;
+import edu.uci.ics.asterix.aql.expression.UpdateStatement;
+import edu.uci.ics.asterix.aql.expression.VarIdentifier;
+import edu.uci.ics.asterix.aql.expression.VariableExpr;
+import edu.uci.ics.asterix.aql.expression.WhereClause;
+import edu.uci.ics.asterix.aql.expression.WriteStatement;
 import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
 import edu.uci.ics.asterix.aql.literal.FalseLiteral;
-import edu.uci.ics.asterix.aql.base.Literal;
-import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
+import edu.uci.ics.asterix.aql.literal.FloatLiteral;
 import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
 import edu.uci.ics.asterix.aql.literal.NullLiteral;
 import edu.uci.ics.asterix.aql.literal.StringLiteral;
 import edu.uci.ics.asterix.aql.literal.TrueLiteral;
-import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
-
-import edu.uci.ics.asterix.aql.base.*;
-import edu.uci.ics.asterix.aql.expression.*;
+import edu.uci.ics.asterix.aql.util.RangeMapBuilder;
+import edu.uci.ics.asterix.common.annotations.AutoDataGen;
+import edu.uci.ics.asterix.common.annotations.DateBetweenYearsDataGen;
+import edu.uci.ics.asterix.common.annotations.DatetimeAddRandHoursDataGen;
+import edu.uci.ics.asterix.common.annotations.DatetimeBetweenYearsDataGen;
+import edu.uci.ics.asterix.common.annotations.FieldIntervalDataGen;
+import edu.uci.ics.asterix.common.annotations.FieldValFileDataGen;
+import edu.uci.ics.asterix.common.annotations.FieldValFileSameIndexDataGen;
+import edu.uci.ics.asterix.common.annotations.IRecordFieldDataGen;
+import edu.uci.ics.asterix.common.annotations.InsertRandIntDataGen;
+import edu.uci.ics.asterix.common.annotations.ListDataGen;
+import edu.uci.ics.asterix.common.annotations.ListValFileDataGen;
+import edu.uci.ics.asterix.common.annotations.SkipSecondaryIndexSearchExpressionAnnotation;
+import edu.uci.ics.asterix.common.annotations.TypeDataGen;
+import edu.uci.ics.asterix.common.annotations.UndeclaredFieldsDataGen;
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
 import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
-import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor;
-import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
-import edu.uci.ics.asterix.aql.expression.TypeExpression.TypeExprKind;
-import edu.uci.ics.asterix.aql.base.Statement.Kind;
-import edu.uci.ics.asterix.aql.context.Scope;
-import edu.uci.ics.asterix.aql.context.RootScopeFactory;
-import edu.uci.ics.asterix.common.annotations.*;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
-import edu.uci.ics.asterix.om.functions.AsterixFunction;
 import edu.uci.ics.asterix.common.functions.FunctionSignature;
+import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
+import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
+import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
-import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
+import edu.uci.ics.hyracks.dataflow.common.data.partition.range.IRangeMap;
 
 
 
@@ -56,22 +136,23 @@ import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
 public class AQLParser extends ScopeChecker {
 
     // optimizer hints
-    private static final String HASH_GROUP_BY_HINT = "hash";
-    private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
+    private static final String AUTO_HINT = "auto";
     private static final String BROADCAST_JOIN_HINT = "bcast";
+    private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
+    private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
+    private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
+    private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
+    private static final String HASH_GROUP_BY_HINT = "hash";
     private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
     private static final String INMEMORY_HINT = "inmem";
-    private static final String VAL_FILE_HINT = "val-files";
-    private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
-    private static final String INTERVAL_HINT = "interval";
-    private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
     private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
-    private static final String LIST_VAL_FILE_HINT = "list-val-file";
+    private static final String INTERVAL_HINT = "interval";
     private static final String LIST_HINT = "list";
-    private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
-    private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
-    private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
-    private static final String AUTO_HINT = "auto";
+    private static final String LIST_VAL_FILE_HINT = "list-val-file";
+    private static final String RANGE_HINT = "range";
+    private static final String SKIP_SECONDARY_INDEX_SEARCH_HINT = "skip-index";
+    private static final String VAL_FILE_HINT = "val-files";
+    private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
 
     private static final String GEN_FIELDS_HINT = "gen-fields";
 
@@ -2083,24 +2164,29 @@ Clause WhereClause()throws ParseException :
 
 Clause OrderbyClause()throws ParseException :
 {
-  OrderbyClause oc = new OrderbyClause();
-  Expression orderbyExpr;
-  List<Expression> orderbyList = new ArrayList<Expression>();
-  List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
-  int numOfOrderby = 0;
+    OrderbyClause oc = new OrderbyClause();
+    Expression orderbyExpr;
+    List<Expression> orderbyList = new ArrayList<Expression>();
+    List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
+    int numOfOrderby = 0;
 }
 {
   (
     <ORDER>
       {
-         String hint = getHint(token);
-         if (hint != null && hint.startsWith(INMEMORY_HINT)) {
-           String splits[] = hint.split(" +");
-           int numFrames = Integer.parseInt(splits[1]);
-           int numTuples = Integer.parseInt(splits[2]);
-           oc.setNumFrames(numFrames);
-           oc.setNumTuples(numTuples);
-         }
+        String hint = getHint(token);
+        if (hint != null) {
+          if (hint.startsWith(INMEMORY_HINT)) {
+            String splits[] = hint.split(" +");
+            int numFrames = Integer.parseInt(splits[1]);
+            int numTuples = Integer.parseInt(splits[2]);
+            oc.setNumFrames(numFrames);
+            oc.setNumTuples(numTuples);
+          }
+          if (hint.startsWith(RANGE_HINT)) {
+            oc.setRangeMap(RangeMapBuilder.parseHint(hint.substring(RANGE_HINT.length())));
+          }
+        }
       }
     <BY> orderbyExpr = Expression()
     {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-doc/src/site/markdown/aql/functions.md
----------------------------------------------------------------------
diff --git a/asterix-doc/src/site/markdown/aql/functions.md b/asterix-doc/src/site/markdown/aql/functions.md
index d0a1e0a..a5f7961 100644
--- a/asterix-doc/src/site/markdown/aql/functions.md
+++ b/asterix-doc/src/site/markdown/aql/functions.md
@@ -2223,29 +2223,17 @@ See the [Allen's Relations](allens.html).
 
 ## <a id="OtherFunctions">Other Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font> ##
 
-### len ###
- * Syntax:
-
-    len(list_expression)
-
- * Returns the length of the list list_expression.
- * Arguments:
-    * `list_expression` : An `OrderedList`, `UnorderedList` or `null`, represents the list need to be checked.
- * Return Value:
-    * An `Int32` that represents the length of list_expression.
-
- * Example:
-
-        use dataverse TinySocial;
-
-        let $l := ["ASTERIX", "Hyracks"]
-        return len($l)
 
+### create-uuid ###
+ * Syntax:
 
- * The expected result is:
-
-        2
+        create-uuid()
 
+* Generates a `uuid`.
+* Arguments:
+    * none
+* Return Value:
+    * A generated `uuid`.
 
 
 ### is-null ###
@@ -2282,6 +2270,31 @@ See the [Allen's Relations](allens.html).
  * Return Value:
     * A `boolean` on whether the variable is a `system null` or not.
 
+
+### len ###
+ * Syntax:
+
+    len(list_expression)
+
+ * Returns the length of the list list_expression.
+ * Arguments:
+    * `list_expression` : An `OrderedList`, `UnorderedList` or `null`, represents the list need to be checked.
+ * Return Value:
+    * An `Int32` that represents the length of list_expression.
+
+ * Example:
+
+        use dataverse TinySocial;
+
+        let $l := ["ASTERIX", "Hyracks"]
+        return len($l)
+
+
+ * The expected result is:
+
+        2
+
+
 ### not ###
  * Syntax:
 
@@ -2304,17 +2317,30 @@ See the [Allen's Relations](allens.html).
         "world"
 
 
-
-### create-uuid ###
+### range ###
  * Syntax:
 
-        create-uuid()
+        range(start_numeric_expression, end_numeric_expression)
 
-* Generates a `uuid`.
+* Generates a series of `int64` values based start the `start_numeric_expression` until the `end_numeric_expression`.
+  The `range` fucntion must be used list argument of a `for` expression.
 * Arguments:
-    * none
+   * `start_numeric_expression`: A `int8`/`int16`/`int32`/`int64` value representing the start value.
+   * `end_numeric_expression`: A `int8`/`int16`/`int32`/`int64` value representing the max final value.
 * Return Value:
     * A generated `uuid`.
+* Example:
+
+        for $i in range(0, 3)
+        return $i;
+
+ * The expected result is:
+
+        [ 0
+        , 1 
+        , 2 
+        , 3
+        ]
 
 
 ### switch-case ###
@@ -2348,7 +2374,6 @@ See the [Allen's Relations](allens.html).
 
         0
 
-
  * Example 2:
 
         switch-case("a",
@@ -2357,7 +2382,8 @@ See the [Allen's Relations](allens.html).
             "z", 3
         )
 
-
  * The expected result is:
 
         3
+
+


[2/2] incubator-asterixdb git commit: Range connector update with order by hint.

Posted by im...@apache.org.
Range connector update with order by hint.

Change-Id: I1b36f6dea801950c39bf63f27a0ec70d3584c5b7
Reviewed-on: https://asterix-gerrit.ics.uci.edu/254
Reviewed-by: Ildar Absalyamov <il...@gmail.com>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Steven Jacobs <sj...@ucr.edu>


Project: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/commit/d2d78adc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/tree/d2d78adc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/diff/d2d78adc

Branch: refs/heads/master
Commit: d2d78adcffb2d90c690eb3685e7495ee276a6996
Parents: 561a8d4
Author: Eldon Carman <ec...@ucr.edu>
Authored: Thu May 7 16:23:41 2015 -0700
Committer: Ian Maxon <im...@uci.edu>
Committed: Fri May 8 10:28:25 2015 -0700

----------------------------------------------------------------------
 .../AqlExpressionToPlanTranslator.java          |   8 +-
 .../asterix/aql/translator/AqlTranslator.java   |  13 +-
 .../sort-hint-on-closed-numeric-desc.aql        |  27 ++
 .../sort-hint-on-closed-numeric.aql             |  27 ++
 .../sort-hint-on-closed-string-desc.aql         |  27 ++
 .../sort-hint-on-closed-string.aql              |  27 ++
 .../sort-hint-on-closed-numeric-desc.plan       |  12 +
 .../sort-hint-on-closed-numeric.plan            |  12 +
 .../sort-hint-on-closed-string-desc.plan        |   9 +
 .../sort-hint-on-closed-string.plan             |   7 +
 .../order-by-exception_01.1.ddl.aql             |  12 +
 .../order-by-exception_01.2.ddl.aql             |   5 +
 .../order-by-exception_01.3.update.aql          |   5 +
 .../order-by-exception_01.4.query.aql           |   6 +
 .../order-by-exception_02.1.ddl.aql             |  12 +
 .../order-by-exception_02.2.ddl.aql             |   5 +
 .../order-by-exception_02.3.update.aql          |   5 +
 .../order-by-exception_02.4.query.aql           |   6 +
 .../range-hints/order-by/order-by.1.ddl.aql     |  12 +
 .../range-hints/order-by/order-by.2.ddl.aql     |   5 +
 .../range-hints/order-by/order-by.3.update.aql  |   5 +
 .../range-hints/order-by/order-by.4.query.aql   |   6 +
 .../range-hints/order-by/order-by.5.query.aql   |   6 +
 .../range-hints/order-by/order-by.6.query.aql   |   6 +
 .../range-hints/order-by/order-by.7.query.aql   |   6 +
 .../results/range-hints/order-by/order-by.4.adm |   5 +
 .../results/range-hints/order-by/order-by.5.adm |   5 +
 .../results/range-hints/order-by/order-by.6.adm |   5 +
 .../results/range-hints/order-by/order-by.7.adm |   5 +
 .../src/test/resources/runtimets/testsuite.xml  | 485 ++++++++++---------
 asterix-aql/pom.xml                             | 247 +++++-----
 .../asterix/aql/expression/OrderbyClause.java   |  10 +
 .../CloneAndSubstituteVariablesVisitor.java     |   3 +
 .../ics/asterix/aql/util/RangeMapBuilder.java   | 171 +++++++
 asterix-aql/src/main/javacc/AQL.jj              | 178 +++++--
 asterix-doc/src/site/markdown/aql/functions.md  |  80 +--
 36 files changed, 1029 insertions(+), 436 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
index d1268e5..ef9797d 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
@@ -88,6 +88,7 @@ import edu.uci.ics.asterix.aql.expression.WhereClause;
 import edu.uci.ics.asterix.aql.expression.WriteStatement;
 import edu.uci.ics.asterix.aql.expression.visitor.IAqlExpressionVisitor;
 import edu.uci.ics.asterix.aql.util.FunctionUtils;
+import edu.uci.ics.asterix.aql.util.RangeMapBuilder;
 import edu.uci.ics.asterix.common.config.AsterixMetadataProperties;
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
@@ -910,7 +911,6 @@ public class AqlExpressionToPlanTranslator extends AbstractAqlTranslator impleme
     @Override
     public Pair<ILogicalOperator, LogicalVariable> visitOrderbyClause(OrderbyClause oc,
             Mutable<ILogicalOperator> tupSource) throws AsterixException {
-
         OrderOperator ord = new OrderOperator();
         Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
         Mutable<ILogicalOperator> topOp = tupSource;
@@ -930,6 +930,12 @@ public class AqlExpressionToPlanTranslator extends AbstractAqlTranslator impleme
         if (oc.getNumFrames() > 0) {
             ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames());
         }
+        if (oc.getRangeMap() != null) {
+            Iterator<OrderModifier> orderModifIter = oc.getModifierList().iterator();
+            boolean ascending = (orderModifIter.next() == OrderModifier.ASC);
+            RangeMapBuilder.verifyRangeOrder(oc.getRangeMap(), ascending);
+            ord.getAnnotations().put(OperatorAnnotations.USE_RANGE_CONNECTOR, oc.getRangeMap());
+        }
         return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
----------------------------------------------------------------------
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
index 0184a65..4c47c7d 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
@@ -192,8 +192,7 @@ public class AqlTranslator extends AbstractAqlTranslator {
     private Dataverse activeDefaultDataverse;
     private final List<FunctionDecl> declaredFunctions;
 
-    public AqlTranslator(List<Statement> aqlStatements, SessionConfig conf)
-            throws MetadataException, AsterixException {
+    public AqlTranslator(List<Statement> aqlStatements, SessionConfig conf) throws MetadataException, AsterixException {
         this.aqlStatements = aqlStatements;
         this.sessionConfig = conf;
         declaredFunctions = getDeclaredFunctions(aqlStatements);
@@ -1736,7 +1735,8 @@ public class AqlTranslator extends AbstractAqlTranslator {
             CompiledLoadFromFileStatement cls = new CompiledLoadFromFileStatement(dataverseName, loadStmt
                     .getDatasetName().getValue(), loadStmt.getAdapter(), loadStmt.getProperties(),
                     loadStmt.dataIsAlreadySorted());
-            JobSpecification spec = APIFramework.compileQuery(null, metadataProvider, null, 0, null, sessionConfig, cls);
+            JobSpecification spec = APIFramework
+                    .compileQuery(null, metadataProvider, null, 0, null, sessionConfig, cls);
             MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
             bActiveTxn = false;
             if (spec != null) {
@@ -1834,8 +1834,7 @@ public class AqlTranslator extends AbstractAqlTranslator {
         Pair<Query, Integer> reWrittenQuery = APIFramework.reWriteQuery(declaredFunctions, metadataProvider, query,
                 sessionConfig);
 
-        // Query Compilation (happens under the same ongoing metadata
-        // transaction)
+        // Query Compilation (happens under the same ongoing metadata transaction)
         JobSpecification spec = APIFramework.compileQuery(declaredFunctions, metadataProvider, reWrittenQuery.first,
                 reWrittenQuery.second, stmt == null ? null : stmt.getDatasetName(), sessionConfig, stmt);
 
@@ -2193,8 +2192,8 @@ public class AqlTranslator extends AbstractAqlTranslator {
                         // In this case (the normal case), we don't use the
                         // "response" JSONObject - just stream the results
                         // to the "out" PrintWriter
-                        if (sessionConfig.fmt() == OutputFormat.CSV &&
-                            sessionConfig.is(SessionConfig.FORMAT_CSV_HEADER)) {
+                        if (sessionConfig.fmt() == OutputFormat.CSV
+                                && sessionConfig.is(SessionConfig.FORMAT_CSV_HEADER)) {
                             ResultUtils.displayCSVHeader(metadataProvider.findOutputRecordType(), sessionConfig);
                         }
                         ResultUtils.displayResults(resultReader, sessionConfig);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-numeric-desc.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-numeric-desc.aql b/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-numeric-desc.aql
new file mode 100644
index 0000000..1d13a10
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-numeric-desc.aql
@@ -0,0 +1,27 @@
+/*
+ *  Description     : The hint is to use the range connector
+ *                  : This test is intended to verify that the range connector is used instead of single node merge.
+ *  Expected Result : Success
+ *  Date            : 1th May 2015
+ */
+
+drop dataverse TinySocial if exists;
+create dataverse TinySocial;
+use dataverse TinySocial;
+
+create type TwitterUserType as open {
+        screen-name: string,
+        lang: string,
+        friends_count: int64,
+        statuses_count: int64,
+        name: string,
+        followers_count: int64
+}
+
+create dataset TwitterUsers(TwitterUserType)
+primary key screen-name;
+
+for $user in dataset TwitterUsers
+/*+ range [400, 150, 100] */
+order by $user.friends_count desc
+return $user;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-numeric.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-numeric.aql b/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-numeric.aql
new file mode 100644
index 0000000..1bf07ab
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-numeric.aql
@@ -0,0 +1,27 @@
+/*
+ *  Description     : The hint is to use the range connector
+ *                  : This test is intended to verify that the range connector is used instead of single node merge.
+ *  Expected Result : Success
+ *  Date            : 1th May 2015
+ */
+
+drop dataverse TinySocial if exists;
+create dataverse TinySocial;
+use dataverse TinySocial;
+
+create type TwitterUserType as open {
+        screen-name: string,
+        lang: string,
+        friends_count: int64,
+        statuses_count: int64,
+        name: string,
+        followers_count: int64
+}
+
+create dataset TwitterUsers(TwitterUserType)
+primary key screen-name;
+
+for $user in dataset TwitterUsers
+/*+ range [100, 150, 400] */
+order by $user.friends_count
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-string-desc.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-string-desc.aql b/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-string-desc.aql
new file mode 100644
index 0000000..7d61041
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-string-desc.aql
@@ -0,0 +1,27 @@
+/*
+ *  Description     : The hint is to use the range connector
+ *                  : This test is intended to verify that the range connector is used instead of single node merge.
+ *  Expected Result : Success
+ *  Date            : 1th May 2015
+ */
+
+drop dataverse TinySocial if exists;
+create dataverse TinySocial;
+use dataverse TinySocial;
+
+create type TwitterUserType as open {
+        screen-name: string,
+        lang: string,
+        friends_count: int64,
+        statuses_count: int64,
+        name: string,
+        followers_count: int64
+}
+
+create dataset TwitterUsers(TwitterUserType)
+primary key screen-name;
+
+for $user in dataset TwitterUsers
+/*+ range ["Nb", "F", "Ci"] */
+order by $user.screen-name desc
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-string.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-string.aql b/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-string.aql
new file mode 100644
index 0000000..71de562
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries/range-connector/sort-hint-on-closed-string.aql
@@ -0,0 +1,27 @@
+/*
+ *  Description     : The hint is to use the range connector
+ *                  : This test is intended to verify that the range connector is used instead of single node merge.
+ *  Expected Result : Success
+ *  Date            : 1th May 2015
+ */
+
+drop dataverse TinySocial if exists;
+create dataverse TinySocial;
+use dataverse TinySocial;
+
+create type TwitterUserType as open {
+        screen-name: string,
+        lang: string,
+        friends_count: int64,
+        statuses_count: int64,
+        name: string,
+        followers_count: int64
+}
+
+create dataset TwitterUsers(TwitterUserType)
+primary key screen-name;
+
+for $user in dataset TwitterUsers
+/*+ range ["Ci", "F", "Nb"] */
+order by $user.screen-name
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-numeric-desc.plan
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-numeric-desc.plan b/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-numeric-desc.plan
new file mode 100644
index 0000000..cdedfde
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-numeric-desc.plan
@@ -0,0 +1,12 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- RANGE_PARTITION_MERGE_EXCHANGE [$$4(DESC)] SPLIT COUNT:3  |PARTITIONED|
+        -- STABLE_SORT [$$4(DESC)]  |PARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            -- ASSIGN  |PARTITIONED|
+              -- STREAM_PROJECT  |PARTITIONED|
+                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-numeric.plan
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-numeric.plan b/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-numeric.plan
new file mode 100644
index 0000000..ba0dc6f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-numeric.plan
@@ -0,0 +1,12 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- RANGE_PARTITION_MERGE_EXCHANGE [$$4(ASC)] SPLIT COUNT:3  |PARTITIONED|
+        -- STABLE_SORT [$$4(ASC)]  |PARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            -- ASSIGN  |PARTITIONED|
+              -- STREAM_PROJECT  |PARTITIONED|
+                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-string-desc.plan
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-string-desc.plan b/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-string-desc.plan
new file mode 100644
index 0000000..3faa5ec
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-string-desc.plan
@@ -0,0 +1,9 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- RANGE_PARTITION_MERGE_EXCHANGE [$$3(DESC)] SPLIT COUNT:3  |PARTITIONED|
+        -- STABLE_SORT [$$3(DESC)]  |PARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-string.plan
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-string.plan b/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-string.plan
new file mode 100644
index 0000000..e0cffaa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/results/range-connector/sort-hint-on-closed-string.plan
@@ -0,0 +1,7 @@
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    -- STREAM_PROJECT  |PARTITIONED|
+      -- RANGE_PARTITION_MERGE_EXCHANGE [$$3(ASC)] SPLIT COUNT:3  |PARTITIONED|
+        -- DATASOURCE_SCAN  |PARTITIONED|
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.1.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.1.ddl.aql
new file mode 100644
index 0000000..eab28a2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.1.ddl.aql
@@ -0,0 +1,12 @@
+drop dataverse TinySocial if exists;
+create dataverse TinySocial;
+use dataverse TinySocial;
+
+create type TwitterUserType as open {
+        screen-name: string,
+        lang: string,
+        friends_count: int64,
+        statuses_count: int64,
+        name: string,
+        followers_count: int64
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.2.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.2.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.2.ddl.aql
new file mode 100644
index 0000000..8d402a7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.2.ddl.aql
@@ -0,0 +1,5 @@
+use dataverse TinySocial;
+
+create dataset TwitterUsers(TwitterUserType)
+primary key screen-name;
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.3.update.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.3.update.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.3.update.aql
new file mode 100644
index 0000000..2ed6ad5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.3.update.aql
@@ -0,0 +1,5 @@
+use dataverse TinySocial;
+
+load dataset TwitterUsers using localfs
+(("path"="nc1://data/tinysocial/twu.adm"),("format"="adm"));
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.4.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.4.query.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.4.query.aql
new file mode 100644
index 0000000..833521b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_01/order-by-exception_01.4.query.aql
@@ -0,0 +1,6 @@
+use dataverse TinySocial;
+
+for $user in dataset TwitterUsers
+/*+ range ["Ci", "Nb", "F"] */
+order by $user.screen-name
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.1.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.1.ddl.aql
new file mode 100644
index 0000000..eab28a2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.1.ddl.aql
@@ -0,0 +1,12 @@
+drop dataverse TinySocial if exists;
+create dataverse TinySocial;
+use dataverse TinySocial;
+
+create type TwitterUserType as open {
+        screen-name: string,
+        lang: string,
+        friends_count: int64,
+        statuses_count: int64,
+        name: string,
+        followers_count: int64
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.2.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.2.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.2.ddl.aql
new file mode 100644
index 0000000..8d402a7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.2.ddl.aql
@@ -0,0 +1,5 @@
+use dataverse TinySocial;
+
+create dataset TwitterUsers(TwitterUserType)
+primary key screen-name;
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.3.update.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.3.update.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.3.update.aql
new file mode 100644
index 0000000..2ed6ad5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.3.update.aql
@@ -0,0 +1,5 @@
+use dataverse TinySocial;
+
+load dataset TwitterUsers using localfs
+(("path"="nc1://data/tinysocial/twu.adm"),("format"="adm"));
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.4.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.4.query.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.4.query.aql
new file mode 100644
index 0000000..66167c8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by-exception_02/order-by-exception_02.4.query.aql
@@ -0,0 +1,6 @@
+use dataverse TinySocial;
+
+for $user in dataset TwitterUsers
+/*+ range ["Ci", "Nb", "F"] */
+order by $user.screen-name desc
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.1.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.1.ddl.aql
new file mode 100644
index 0000000..eab28a2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.1.ddl.aql
@@ -0,0 +1,12 @@
+drop dataverse TinySocial if exists;
+create dataverse TinySocial;
+use dataverse TinySocial;
+
+create type TwitterUserType as open {
+        screen-name: string,
+        lang: string,
+        friends_count: int64,
+        statuses_count: int64,
+        name: string,
+        followers_count: int64
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.2.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.2.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.2.ddl.aql
new file mode 100644
index 0000000..8d402a7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.2.ddl.aql
@@ -0,0 +1,5 @@
+use dataverse TinySocial;
+
+create dataset TwitterUsers(TwitterUserType)
+primary key screen-name;
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.3.update.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.3.update.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.3.update.aql
new file mode 100644
index 0000000..2ed6ad5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.3.update.aql
@@ -0,0 +1,5 @@
+use dataverse TinySocial;
+
+load dataset TwitterUsers using localfs
+(("path"="nc1://data/tinysocial/twu.adm"),("format"="adm"));
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.4.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.4.query.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.4.query.aql
new file mode 100644
index 0000000..afb12ef
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.4.query.aql
@@ -0,0 +1,6 @@
+use dataverse TinySocial;
+
+for $user in dataset TwitterUsers
+/*+ range ["Ci", "F", "Nb"] */
+order by $user.screen-name
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.5.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.5.query.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.5.query.aql
new file mode 100644
index 0000000..f9dbfe1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.5.query.aql
@@ -0,0 +1,6 @@
+use dataverse TinySocial;
+
+for $user in dataset TwitterUsers
+/*+ range ["Nb", "F", "Ci"] */
+order by $user.screen-name desc
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.6.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.6.query.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.6.query.aql
new file mode 100644
index 0000000..e85e13a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.6.query.aql
@@ -0,0 +1,6 @@
+use dataverse TinySocial;
+
+for $user in dataset TwitterUsers
+/*+ range [100, 150, 400] */
+order by $user.friends_count
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.7.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.7.query.aql b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.7.query.aql
new file mode 100644
index 0000000..1ba71c5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/range-hints/order-by/order-by.7.query.aql
@@ -0,0 +1,6 @@
+use dataverse TinySocial;
+
+for $user in dataset TwitterUsers
+/*+ range [400, 150, 100] */
+order by $user.friends_count desc
+return $user;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.4.adm
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.4.adm b/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.4.adm
new file mode 100644
index 0000000..5820838
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.4.adm
@@ -0,0 +1,5 @@
+[ { "screen-name": "ChangEwing_573", "lang": "en", "friends_count": 182, "statuses_count": 394, "name": "Chang Ewing", "followers_count": 32136 }
+, { "screen-name": "ColineGeyer@63", "lang": "en", "friends_count": 121, "statuses_count": 362, "name": "Coline Geyer", "followers_count": 17159 }
+, { "screen-name": "NathanGiesen@211", "lang": "en", "friends_count": 18, "statuses_count": 473, "name": "Nathan Giesen", "followers_count": 49416 }
+, { "screen-name": "NilaMilliron_tw", "lang": "en", "friends_count": 445, "statuses_count": 164, "name": "Nila Milliron", "followers_count": 22649 }
+ ]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.5.adm
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.5.adm b/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.5.adm
new file mode 100644
index 0000000..bbb58ab
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.5.adm
@@ -0,0 +1,5 @@
+[ { "screen-name": "NilaMilliron_tw", "lang": "en", "friends_count": 445, "statuses_count": 164, "name": "Nila Milliron", "followers_count": 22649 }
+, { "screen-name": "NathanGiesen@211", "lang": "en", "friends_count": 18, "statuses_count": 473, "name": "Nathan Giesen", "followers_count": 49416 }
+, { "screen-name": "ColineGeyer@63", "lang": "en", "friends_count": 121, "statuses_count": 362, "name": "Coline Geyer", "followers_count": 17159 }
+, { "screen-name": "ChangEwing_573", "lang": "en", "friends_count": 182, "statuses_count": 394, "name": "Chang Ewing", "followers_count": 32136 }
+ ]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.6.adm
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.6.adm b/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.6.adm
new file mode 100644
index 0000000..77b184b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.6.adm
@@ -0,0 +1,5 @@
+[ { "screen-name": "NathanGiesen@211", "lang": "en", "friends_count": 18, "statuses_count": 473, "name": "Nathan Giesen", "followers_count": 49416 }
+, { "screen-name": "ColineGeyer@63", "lang": "en", "friends_count": 121, "statuses_count": 362, "name": "Coline Geyer", "followers_count": 17159 }
+, { "screen-name": "ChangEwing_573", "lang": "en", "friends_count": 182, "statuses_count": 394, "name": "Chang Ewing", "followers_count": 32136 }
+, { "screen-name": "NilaMilliron_tw", "lang": "en", "friends_count": 445, "statuses_count": 164, "name": "Nila Milliron", "followers_count": 22649 }
+ ]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.7.adm
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.7.adm b/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.7.adm
new file mode 100644
index 0000000..9f60378
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/range-hints/order-by/order-by.7.adm
@@ -0,0 +1,5 @@
+[ { "screen-name": "NilaMilliron_tw", "lang": "en", "friends_count": 445, "statuses_count": 164, "name": "Nila Milliron", "followers_count": 22649 }
+, { "screen-name": "ChangEwing_573", "lang": "en", "friends_count": 182, "statuses_count": 394, "name": "Chang Ewing", "followers_count": 32136 }
+, { "screen-name": "ColineGeyer@63", "lang": "en", "friends_count": 121, "statuses_count": 362, "name": "Coline Geyer", "followers_count": 17159 }
+, { "screen-name": "NathanGiesen@211", "lang": "en", "friends_count": 18, "statuses_count": 473, "name": "Nathan Giesen", "followers_count": 49416 }
+ ]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-app/src/test/resources/runtimets/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 9df6301..f97f793 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -4318,6 +4318,25 @@
             </compilation-unit>
         </test-case>
     </test-group>
+    <test-group name="range-hints">
+        <test-case FilePath="range-hints">
+            <compilation-unit name="order-by">
+                <output-dir compare="Text">order-by</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="range-hints">
+            <compilation-unit name="order-by-exception_01">
+                <output-dir compare="Text">order-by</output-dir>
+                <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="range-hints">
+            <compilation-unit name="order-by-exception_02">
+                <output-dir compare="Text">order-by</output-dir>
+                <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+            </compilation-unit>
+        </test-case>
+    </test-group>
     <test-group name="records">
         <test-case FilePath="records">
             <compilation-unit name="closed-record-constructor_01">
@@ -5404,7 +5423,7 @@
         <test-case FilePath="tpch">
             <compilation-unit name="query-issue562">
                 <output-dir compare="Text">query-issue562</output-dir>
-        </compilation-unit>
+            </compilation-unit>
         </test-case>
         <test-case FilePath="tpch">
             <compilation-unit name="query-issue810">
@@ -6154,7 +6173,7 @@
                 <output-dir compare="Text">agg_01</output-dir>
             </compilation-unit>
         </test-case>
-       <test-case FilePath="temporal">
+        <test-case FilePath="temporal">
             <compilation-unit name="overlap_bins_gby_1">
                 <output-dir compare="Text">overlap_bins_gby_1</output-dir>
             </compilation-unit>
@@ -6310,237 +6329,237 @@
         </test-case>
     </test-group>
     <test-group name="index-leftouterjoin">
-    <test-case FilePath="index-leftouterjoin">
-      <compilation-unit name="probe-pidx-with-join-btree-sidx1">
-        <output-dir compare="Text">probe-pidx-with-join-btree-sidx1</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="index-leftouterjoin">
-      <compilation-unit name="probe-pidx-with-join-btree-sidx2">
-        <output-dir compare="Text">probe-pidx-with-join-btree-sidx2</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="index-leftouterjoin">
-      <compilation-unit name="probe-pidx-with-join-rtree-sidx1">
-        <output-dir compare="Text">probe-pidx-with-join-rtree-sidx1</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="index-leftouterjoin">
-      <compilation-unit name="probe-pidx-with-join-rtree-sidx2">
-        <output-dir compare="Text">probe-pidx-with-join-rtree-sidx2</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="index-leftouterjoin">
-      <compilation-unit name="probe-pidx-with-join-invidx-sidx1">
-        <output-dir compare="Text">probe-pidx-with-join-invidx-sidx1</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="index-leftouterjoin">
-      <compilation-unit name="probe-pidx-with-join-invidx-sidx2">
-        <output-dir compare="Text">probe-pidx-with-join-invidx-sidx2</output-dir>
-      </compilation-unit>
-    </test-case>
-  </test-group>
-  <test-group name="distinct">
-      <test-case FilePath="distinct">
-      <compilation-unit name="query-issue443">
-        <output-dir compare="Text">query-issue443</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="distinct">
-      <compilation-unit name="query-issue443-2">
-        <output-dir compare="Text">query-issue443-2</output-dir>
-      </compilation-unit>
-    </test-case>
-  </test-group>
-  <test-group name="tinysocial">
-    <test-case FilePath="tinysocial">
-      <compilation-unit name="tinysocial-suite">
-        <output-dir compare="Text">tinysocial-suite</output-dir>
-      </compilation-unit>
-    </test-case>
-  </test-group>
-  <test-group name="types">
-    <test-case FilePath="types">
-      <compilation-unit name="record01">
-        <output-dir compare="Text">record01</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="type_promotion_0">
-        <output-dir compare="Text">type_promotion_0</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="type_promotion_1">
-        <output-dir compare="Text">type_promotion_1</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="opentype_orderby_01">
-        <output-dir compare="Text">opentype_orderby_01</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_01">
-        <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_01</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_02">
-        <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_02</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_03">
-        <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_03</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_04">
-        <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_04</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_05">
-        <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_05</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_01">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_01</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_02">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_02</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_03">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_03</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_04">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_04</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_05">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_05</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_06">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_06</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_07">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_07</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_08">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_08</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_09">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_09</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_10">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_10</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_constant_11">
-        <output-dir compare="Text">promotion_closedtype_field_vs_constant_11</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_opentype_field_01">
-        <output-dir compare="Text">promotion_closedtype_field_vs_opentype_field_01</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_opentype_field_02">
-        <output-dir compare="Text">promotion_closedtype_field_vs_opentype_field_02</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_opentype_field_03">
-        <output-dir compare="Text">promotion_closedtype_field_vs_opentype_field_03</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_closedtype_field_vs_opentype_field_04">
-        <output-dir compare="Text">promotion_closedtype_field_vs_opentype_field_04</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_constant_01">
-        <output-dir compare="Text">promotion_opentype_field_vs_constant_01</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_constant_02">
-        <output-dir compare="Text">promotion_opentype_field_vs_constant_02</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_constant_03">
-        <output-dir compare="Text">promotion_opentype_field_vs_constant_03</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_constant_04">
-        <output-dir compare="Text">promotion_opentype_field_vs_constant_04</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_constant_05">
-        <output-dir compare="Text">promotion_opentype_field_vs_constant_05</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_constant_06">
-        <output-dir compare="Text">promotion_opentype_field_vs_constant_06</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_constant_07">
-        <output-dir compare="Text">promotion_opentype_field_vs_constant_07</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_constant_08">
-        <output-dir compare="Text">promotion_opentype_field_vs_constant_08</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_opentype_field_01">
-        <output-dir compare="Text">promotion_opentype_field_vs_opentype_field_01</output-dir>
-      </compilation-unit>
-    </test-case>
-    <test-case FilePath="types">
-      <compilation-unit name="promotion_opentype_field_vs_opentype_field_02">
-        <output-dir compare="Text">promotion_opentype_field_vs_opentype_field_02</output-dir>
-      </compilation-unit>
-    </test-case>
-  </test-group>
-  <test-group name="materialization">
-    <test-case FilePath="materialization">
-      <compilation-unit name="assign-reuse">
-        <output-dir compare="Text">assign-reuse</output-dir>
-      </compilation-unit>
-    </test-case>
-  </test-group>
-  <test-group name="filters">
-          <test-case FilePath="filters">
+        <test-case FilePath="index-leftouterjoin">
+            <compilation-unit name="probe-pidx-with-join-btree-sidx1">
+                <output-dir compare="Text">probe-pidx-with-join-btree-sidx1</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="index-leftouterjoin">
+            <compilation-unit name="probe-pidx-with-join-btree-sidx2">
+                <output-dir compare="Text">probe-pidx-with-join-btree-sidx2</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="index-leftouterjoin">
+            <compilation-unit name="probe-pidx-with-join-rtree-sidx1">
+                <output-dir compare="Text">probe-pidx-with-join-rtree-sidx1</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="index-leftouterjoin">
+            <compilation-unit name="probe-pidx-with-join-rtree-sidx2">
+                <output-dir compare="Text">probe-pidx-with-join-rtree-sidx2</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="index-leftouterjoin">
+            <compilation-unit name="probe-pidx-with-join-invidx-sidx1">
+                <output-dir compare="Text">probe-pidx-with-join-invidx-sidx1</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="index-leftouterjoin">
+            <compilation-unit name="probe-pidx-with-join-invidx-sidx2">
+                <output-dir compare="Text">probe-pidx-with-join-invidx-sidx2</output-dir>
+            </compilation-unit>
+        </test-case>
+    </test-group>
+    <test-group name="distinct">
+        <test-case FilePath="distinct">
+            <compilation-unit name="query-issue443">
+                <output-dir compare="Text">query-issue443</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="distinct">
+            <compilation-unit name="query-issue443-2">
+                <output-dir compare="Text">query-issue443-2</output-dir>
+            </compilation-unit>
+        </test-case>
+    </test-group>
+    <test-group name="tinysocial">
+        <test-case FilePath="tinysocial">
+            <compilation-unit name="tinysocial-suite">
+                <output-dir compare="Text">tinysocial-suite</output-dir>
+            </compilation-unit>
+        </test-case>
+    </test-group>
+    <test-group name="types">
+        <test-case FilePath="types">
+            <compilation-unit name="record01">
+                <output-dir compare="Text">record01</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="type_promotion_0">
+                <output-dir compare="Text">type_promotion_0</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="type_promotion_1">
+                <output-dir compare="Text">type_promotion_1</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="opentype_orderby_01">
+                <output-dir compare="Text">opentype_orderby_01</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_01">
+                <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_01</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_02">
+                <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_02</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_03">
+                <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_03</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_04">
+                <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_04</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_closedtype_field_05">
+                <output-dir compare="Text">promotion_closedtype_field_vs_closedtype_field_05</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_01">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_01</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_02">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_02</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_03">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_03</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_04">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_04</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_05">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_05</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_06">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_06</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_07">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_07</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_08">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_08</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_09">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_09</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_10">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_10</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_constant_11">
+                <output-dir compare="Text">promotion_closedtype_field_vs_constant_11</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_opentype_field_01">
+                <output-dir compare="Text">promotion_closedtype_field_vs_opentype_field_01</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_opentype_field_02">
+                <output-dir compare="Text">promotion_closedtype_field_vs_opentype_field_02</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_opentype_field_03">
+                <output-dir compare="Text">promotion_closedtype_field_vs_opentype_field_03</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_closedtype_field_vs_opentype_field_04">
+                <output-dir compare="Text">promotion_closedtype_field_vs_opentype_field_04</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_constant_01">
+                <output-dir compare="Text">promotion_opentype_field_vs_constant_01</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_constant_02">
+                <output-dir compare="Text">promotion_opentype_field_vs_constant_02</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_constant_03">
+                <output-dir compare="Text">promotion_opentype_field_vs_constant_03</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_constant_04">
+                <output-dir compare="Text">promotion_opentype_field_vs_constant_04</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_constant_05">
+                <output-dir compare="Text">promotion_opentype_field_vs_constant_05</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_constant_06">
+                <output-dir compare="Text">promotion_opentype_field_vs_constant_06</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_constant_07">
+                <output-dir compare="Text">promotion_opentype_field_vs_constant_07</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_constant_08">
+                <output-dir compare="Text">promotion_opentype_field_vs_constant_08</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_opentype_field_01">
+                <output-dir compare="Text">promotion_opentype_field_vs_opentype_field_01</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="types">
+            <compilation-unit name="promotion_opentype_field_vs_opentype_field_02">
+                <output-dir compare="Text">promotion_opentype_field_vs_opentype_field_02</output-dir>
+            </compilation-unit>
+        </test-case>
+    </test-group>
+    <test-group name="materialization">
+        <test-case FilePath="materialization">
+            <compilation-unit name="assign-reuse">
+                <output-dir compare="Text">assign-reuse</output-dir>
+            </compilation-unit>
+        </test-case>
+    </test-group>
+    <test-group name="filters">
+        <test-case FilePath="filters">
             <compilation-unit name="equality-predicate">
                 <output-dir compare="Text">equality-predicate</output-dir>
             </compilation-unit>

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-aql/pom.xml
----------------------------------------------------------------------
diff --git a/asterix-aql/pom.xml b/asterix-aql/pom.xml
index 6cfa550..26e9684 100644
--- a/asterix-aql/pom.xml
+++ b/asterix-aql/pom.xml
@@ -12,60 +12,63 @@
  ! See the License for the specific language governing permissions and
  ! limitations under the License.
  !-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<artifactId>asterix</artifactId>
-		<groupId>edu.uci.ics.asterix</groupId>
-		<version>0.8.7-SNAPSHOT</version>
-	</parent>
+<project
+    xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>asterix</artifactId>
+        <groupId>edu.uci.ics.asterix</groupId>
+        <version>0.8.7-SNAPSHOT</version>
+    </parent>
 
-  <licenses>
-    <license>
-      <name>Apache License, Version 2.0</name>
-      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
-      <distribution>repo</distribution>
-      <comments>A business-friendly OSS license</comments>
-    </license>
-  </licenses>
+    <licenses>
+        <license>
+            <name>Apache License, Version 2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+            <distribution>repo</distribution>
+            <comments>A business-friendly OSS license</comments>
+        </license>
+    </licenses>
 
-	<artifactId>asterix-aql</artifactId>
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<version>2.3.2</version>
-				<configuration>
-					<source>1.7</source>
-					<target>1.7</target>
-					<fork>true</fork>
-				</configuration>
-			</plugin>
-			<plugin>
-				<groupId>org.codehaus.mojo</groupId>
-				<artifactId>javacc-maven-plugin</artifactId>
-				<version>2.6</version>
-				<executions>
-					<execution>
-						<id>javacc</id>
-						<goals>
-							<goal>javacc</goal>
-						</goals>
-						<configuration>
-							<isStatic>false</isStatic>
-							<javaUnicodeEscape>true</javaUnicodeEscape>
-						</configuration>
-					</execution>
-					<execution>
-						<id>javacc-jjdoc</id>
-						<goals>
-							<goal>jjdoc</goal>
-						</goals>
-						<phase>process-sources</phase>
-					</execution>
-				</executions>
-			</plugin>
+    <artifactId>asterix-aql</artifactId>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.3.2</version>
+                <configuration>
+                    <source>1.7</source>
+                    <target>1.7</target>
+                    <fork>true</fork>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>javacc-maven-plugin</artifactId>
+                <version>2.6</version>
+                <executions>
+                    <execution>
+                        <id>javacc</id>
+                        <goals>
+                            <goal>javacc</goal>
+                        </goals>
+                        <configuration>
+                            <isStatic>false</isStatic>
+                            <javaUnicodeEscape>true</javaUnicodeEscape>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>javacc-jjdoc</id>
+                        <goals>
+                            <goal>jjdoc</goal>
+                        </goals>
+                        <phase>process-sources</phase>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
@@ -85,76 +88,76 @@
                     </execution>
                 </executions>
             </plugin>
-		</plugins>
-		<pluginManagement>
-			<plugins>
-				<!--This plugin's configuration is used to store Eclipse m2e settings 
-					only. It has no influence on the Maven build itself. -->
-				<plugin>
-					<groupId>org.eclipse.m2e</groupId>
-					<artifactId>lifecycle-mapping</artifactId>
-					<version>1.0.0</version>
-					<configuration>
-						<lifecycleMappingMetadata>
-							<pluginExecutions>
-								<pluginExecution>
-									<pluginExecutionFilter>
-										<groupId>
-											org.codehaus.mojo
-										</groupId>
-										<artifactId>
-											javacc-maven-plugin
-										</artifactId>
-										<versionRange>
-											[2.6,)
-										</versionRange>
-										<goals>
-											<goal>jjdoc</goal>
-											<goal>javacc</goal>
-										</goals>
-									</pluginExecutionFilter>
-									<action>
-										<ignore />
-									</action>
-								</pluginExecution>
-							</pluginExecutions>
-						</lifecycleMappingMetadata>
-					</configuration>
-				</plugin>
-			</plugins>
-		</pluginManagement>
-	</build>
+        </plugins>
+        <pluginManagement>
+            <plugins>
+                <!--This plugin's configuration is used to store Eclipse m2e settings 
+                    only. It has no influence on the Maven build itself. -->
+                <plugin>
+                    <groupId>org.eclipse.m2e</groupId>
+                    <artifactId>lifecycle-mapping</artifactId>
+                    <version>1.0.0</version>
+                    <configuration>
+                        <lifecycleMappingMetadata>
+                            <pluginExecutions>
+                                <pluginExecution>
+                                    <pluginExecutionFilter>
+                                        <groupId>
+                                            org.codehaus.mojo
+                                        </groupId>
+                                        <artifactId>
+                                            javacc-maven-plugin
+                                        </artifactId>
+                                        <versionRange>
+                                            [2.6,)
+                                        </versionRange>
+                                        <goals>
+                                            <goal>jjdoc</goal>
+                                            <goal>javacc</goal>
+                                        </goals>
+                                    </pluginExecutionFilter>
+                                    <action>
+                                        <ignore />
+                                    </action>
+                                </pluginExecution>
+                            </pluginExecutions>
+                        </lifecycleMappingMetadata>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
 
-	<dependencies>
-		<dependency>
-			<groupId>edu.uci.ics.asterix</groupId>
-			<artifactId>asterix-common</artifactId>
-			<version>0.8.7-SNAPSHOT</version>
-			<scope>compile</scope>
-		</dependency>
-		<dependency>
-			<groupId>edu.uci.ics.asterix</groupId>
-			<artifactId>asterix-om</artifactId>
-			<version>0.8.7-SNAPSHOT</version>
-			<scope>compile</scope>
-		</dependency>
-		<dependency>
-			<groupId>edu.uci.ics.asterix</groupId>
-			<artifactId>asterix-metadata</artifactId>
-			<version>0.8.7-SNAPSHOT</version>
-			<scope>compile</scope>
-		</dependency>
-		<dependency>
-			<groupId>edu.uci.ics.fuzzyjoin</groupId>
-			<artifactId>fuzzyjoin-core</artifactId>
-			<version>0.0.3</version>
-			<scope>compile</scope>
-		</dependency>
-		<dependency>
-			<groupId>xerces</groupId>
-			<artifactId>xerces</artifactId>
-			<version>2.4.0</version>
-		</dependency>
-	</dependencies>
+    <dependencies>
+        <dependency>
+            <groupId>edu.uci.ics.asterix</groupId>
+            <artifactId>asterix-common</artifactId>
+            <version>0.8.7-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>edu.uci.ics.asterix</groupId>
+            <artifactId>asterix-om</artifactId>
+            <version>0.8.7-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>edu.uci.ics.asterix</groupId>
+            <artifactId>asterix-metadata</artifactId>
+            <version>0.8.7-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>edu.uci.ics.fuzzyjoin</groupId>
+            <artifactId>fuzzyjoin-core</artifactId>
+            <version>0.0.3</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>xerces</groupId>
+            <artifactId>xerces</artifactId>
+            <version>2.4.0</version>
+        </dependency>
+    </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/OrderbyClause.java
----------------------------------------------------------------------
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/OrderbyClause.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/OrderbyClause.java
index 4418df9..90e8724 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/OrderbyClause.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/OrderbyClause.java
@@ -21,10 +21,12 @@ import edu.uci.ics.asterix.aql.base.Expression;
 import edu.uci.ics.asterix.aql.expression.visitor.IAqlExpressionVisitor;
 import edu.uci.ics.asterix.aql.expression.visitor.IAqlVisitorWithVoidReturn;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.hyracks.dataflow.common.data.partition.range.IRangeMap;
 
 public class OrderbyClause implements Clause {
     private List<Expression> orderbyList;
     private List<OrderModifier> modifierList;
+    private IRangeMap rangeMap;
     private int numFrames = -1;
     private int numTuples = -1;
 
@@ -86,4 +88,12 @@ public class OrderbyClause implements Clause {
     public void setNumTuples(int numTuples) {
         this.numTuples = numTuples;
     }
+
+    public IRangeMap getRangeMap() {
+        return rangeMap;
+    }
+
+    public void setRangeMap(IRangeMap rangeMap) {
+        this.rangeMap = rangeMap;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java
index 1e6747e..edb080c 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java
@@ -311,6 +311,9 @@ public class CloneAndSubstituteVariablesVisitor implements
             List<VariableSubstitution> arg) throws AsterixException {
         List<Expression> exprList = visitAndCloneExprList(oc.getOrderbyList(), arg);
         OrderbyClause oc2 = new OrderbyClause(exprList, oc.getModifierList());
+        oc2.setNumFrames(oc.getNumFrames());
+        oc2.setNumTuples(oc.getNumTuples());
+        oc2.setRangeMap(oc.getRangeMap());
         return new Pair<IAqlExpression, List<VariableSubstitution>>(oc2, arg);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d2d78adc/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/util/RangeMapBuilder.java
----------------------------------------------------------------------
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/util/RangeMapBuilder.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/util/RangeMapBuilder.java
new file mode 100644
index 0000000..223358c
--- /dev/null
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/util/RangeMapBuilder.java
@@ -0,0 +1,171 @@
+/*
+ * 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.aql.util;
+
+import java.io.DataOutput;
+import java.util.List;
+
+import edu.uci.ics.asterix.aql.base.Expression;
+import edu.uci.ics.asterix.aql.base.Expression.Kind;
+import edu.uci.ics.asterix.aql.base.Literal;
+import edu.uci.ics.asterix.aql.base.Statement;
+import edu.uci.ics.asterix.aql.expression.ListConstructor;
+import edu.uci.ics.asterix.aql.expression.LiteralExpr;
+import edu.uci.ics.asterix.aql.expression.Query;
+import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
+import edu.uci.ics.asterix.aql.literal.FloatLiteral;
+import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
+import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
+import edu.uci.ics.asterix.aql.literal.StringLiteral;
+import edu.uci.ics.asterix.aql.parser.AQLParser;
+import edu.uci.ics.asterix.aql.parser.ParseException;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AMutableDouble;
+import edu.uci.ics.asterix.om.base.AMutableFloat;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
+import edu.uci.ics.asterix.om.base.AMutableString;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+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.partition.range.IRangeMap;
+import edu.uci.ics.hyracks.dataflow.common.data.partition.range.RangeMap;
+
+public abstract class RangeMapBuilder {
+
+    public static IRangeMap parseHint(Object hint) throws ParseException {
+        ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+        DataOutput out = abvs.getDataOutput();;
+        abvs.reset();
+
+        AQLParser parser = new AQLParser((String) hint);
+        List<Statement> hintStatements = parser.parse();
+        if (hintStatements.size() != 1) {
+            throw new ParseException("Only one range statement is allowed for the range hint.");
+        }
+
+        // Translate the query into a Range Map
+        if (hintStatements.get(0).getKind() != Statement.Kind.QUERY) {
+            throw new ParseException("Not a proper query for the range hint.");
+        }
+        Query q = (Query) hintStatements.get(0);
+
+        if (q.getBody().getKind() != Kind.LIST_CONSTRUCTOR_EXPRESSION) {
+            throw new ParseException("The range hint must be a list.");
+        }
+        List<Expression> el = (List<Expression>) ((ListConstructor) q.getBody()).getExprList();
+        int offsets[] = new int[el.size()];
+
+        // Loop over list of literals
+        for (int i = 0; i < el.size(); ++i) {
+            Expression item = el.get(i);
+            if (item.getKind() == Kind.LITERAL_EXPRESSION) {
+                parseLiteralToBytes(item, out);
+                offsets[i] = abvs.getLength();
+            }
+            // TODO Add support for composite fields.
+        }
+
+        return new RangeMap(1, abvs.getByteArray(), offsets);
+    }
+
+    @SuppressWarnings("unchecked")
+    private static void parseLiteralToBytes(Expression item, DataOutput out) throws ParseException {
+        AMutableDouble aDouble = new AMutableDouble(0);
+        AMutableFloat aFloat = new AMutableFloat(0);
+        AMutableInt64 aInt64 = new AMutableInt64(0);
+        AMutableInt32 aInt32 = new AMutableInt32(0);
+        AMutableString aString = new AMutableString("");
+        @SuppressWarnings("rawtypes")
+        ISerializerDeserializer serde;
+
+        Literal l = (Literal) ((LiteralExpr) item).getValue();
+        try {
+            switch (l.getLiteralType()) {
+                case DOUBLE:
+                    DoubleLiteral dl = (DoubleLiteral) l;
+                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADOUBLE);
+                    aDouble.setValue(dl.getValue());
+                    serde.serialize(aDouble, out);
+                    break;
+                case FLOAT:
+                    FloatLiteral fl = (FloatLiteral) l;
+                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AFLOAT);
+                    aFloat.setValue(fl.getValue());
+                    serde.serialize(aFloat, out);
+                    break;
+                case INTEGER:
+                    IntegerLiteral il = (IntegerLiteral) l;
+                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
+                    aInt32.setValue(il.getValue());
+                    serde.serialize(aInt32, out);
+                    break;
+                case LONG:
+                    LongIntegerLiteral lil = (LongIntegerLiteral) l;
+                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
+                    aInt64.setValue(lil.getValue());
+                    serde.serialize(aInt64, out);
+                    break;
+                case STRING:
+                    StringLiteral sl = (StringLiteral) l;
+                    serde = AqlSerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
+                    aString.setValue(sl.getValue());
+                    serde.serialize(aString, out);
+                    break;
+                default:
+                    throw new NotImplementedException("The range map builder has not been implemented for "
+                            + item.getKind() + " type of expressions.");
+            }
+        } catch (HyracksDataException e) {
+            throw new ParseException(e.getMessage());
+        }
+    }
+
+    public static void verifyRangeOrder(IRangeMap rangeMap, boolean ascending) throws AsterixException {
+        // TODO Add support for composite fields.
+        int fieldIndex = 0;
+        int fieldType = rangeMap.getTag(0, 0);
+        AqlBinaryComparatorFactoryProvider comparatorFactory = AqlBinaryComparatorFactoryProvider.INSTANCE;
+        IBinaryComparatorFactory bcf = comparatorFactory.getBinaryComparatorFactory(
+                ATypeTag.VALUE_TYPE_MAPPING[fieldType], ascending);
+        IBinaryComparator comparator = bcf.createBinaryComparator();
+        int c = 0;
+        for (int split = 1; split < rangeMap.getSplitCount(); ++split) {
+            if (fieldType != rangeMap.getTag(fieldIndex, split)) {
+                throw new AsterixException("Range field contains more than a single type of items (" + fieldType
+                        + " and " + rangeMap.getTag(fieldIndex, split) + ").");
+            }
+            int previousSplit = split - 1;
+            try {
+                c = comparator.compare(rangeMap.getByteArray(fieldIndex, previousSplit),
+                        rangeMap.getStartOffset(fieldIndex, previousSplit),
+                        rangeMap.getLength(fieldIndex, previousSplit), rangeMap.getByteArray(fieldIndex, split),
+                        rangeMap.getStartOffset(fieldIndex, split), rangeMap.getLength(fieldIndex, split));
+            } catch (HyracksDataException e) {
+                throw new AsterixException(e);
+            }
+            if (c >= 0) {
+                throw new AsterixException("Range fields are not in sorted order.");
+            }
+        }
+    }
+}