Merged asterix_stabilization -r 457:535.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_unnest_to_join_enhance@536 eaa15691-b419-025a-1212-ee371bd00084
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 e004a7d..35fb3ae 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
@@ -154,1255 +154,1507 @@
  * source for the current subtree.
  */
 
-public class AqlExpressionToPlanTranslator extends AbstractAqlTranslator implements
-        IAqlExpressionVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
+public class AqlExpressionToPlanTranslator extends AbstractAqlTranslator
+		implements
+		IAqlExpressionVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
 
-    private final MetadataTransactionContext mdTxnCtx;
-    private final long txnId;
-    private TranslationContext context;
-    private String outputDatasetName;
-    private Statement.Kind dmlKind;
-    private static AtomicLong outputFileID = new AtomicLong(0);
-    private static final String OUTPUT_FILE_PREFIX = "OUTPUT_";
+	private final MetadataTransactionContext mdTxnCtx;
+	private final long txnId;
+	private TranslationContext context;
+	private String outputDatasetName;
+	private Statement.Kind dmlKind;
+	private static AtomicLong outputFileID = new AtomicLong(0);
+	private static final String OUTPUT_FILE_PREFIX = "OUTPUT_";
 
-    private static LogicalVariable METADATA_DUMMY_VAR = new LogicalVariable(-1);
+	private static LogicalVariable METADATA_DUMMY_VAR = new LogicalVariable(-1);
 
-    public AqlExpressionToPlanTranslator(long txnId, MetadataTransactionContext mdTxnCtx, int currentVarCounter,
-            String outputDatasetName, Statement.Kind dmlKind) {
-        this.mdTxnCtx = mdTxnCtx;
-        this.txnId = txnId;
-        this.context = new TranslationContext(new Counter(currentVarCounter));
-        this.outputDatasetName = outputDatasetName;
-        this.dmlKind = dmlKind;
-    }
+	public AqlExpressionToPlanTranslator(long txnId,
+			MetadataTransactionContext mdTxnCtx, int currentVarCounter,
+			String outputDatasetName, Statement.Kind dmlKind) {
+		this.mdTxnCtx = mdTxnCtx;
+		this.txnId = txnId;
+		this.context = new TranslationContext(new Counter(currentVarCounter));
+		this.outputDatasetName = outputDatasetName;
+		this.dmlKind = dmlKind;
+	}
 
-    public int getVarCounter() {
-        return context.getVarCounter();
-    }
+	public int getVarCounter() {
+		return context.getVarCounter();
+	}
 
-    public ILogicalPlanAndMetadata translate(Query expr, AqlCompiledMetadataDeclarations compiledDeclarations)
-            throws AlgebricksException, AsterixException {
-        if (expr == null) {
-            return null;
-        }
-        if (compiledDeclarations == null) {
-            compiledDeclarations = compileMetadata(mdTxnCtx, expr.getPrologDeclList(), true);
-        }
-        if (!compiledDeclarations.isConnectedToDataverse())
-            compiledDeclarations.connectToDataverse(compiledDeclarations.getDataverseName());
-        IDataFormat format = compiledDeclarations.getFormat();
-        if (format == null) {
-            throw new AlgebricksException("Data format has not been set.");
-        }
-        format.registerRuntimeFunctions();
-        Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, new MutableObject<ILogicalOperator>(
-                new EmptyTupleSourceOperator()));
+	public ILogicalPlanAndMetadata translate(Query expr,
+			AqlCompiledMetadataDeclarations compiledDeclarations)
+			throws AlgebricksException, AsterixException {
+		if (expr == null) {
+			return null;
+		}
+		if (compiledDeclarations == null) {
+			compiledDeclarations = compileMetadata(mdTxnCtx,
+					expr.getPrologDeclList(), true);
+		}
+		if (!compiledDeclarations.isConnectedToDataverse())
+			compiledDeclarations.connectToDataverse(compiledDeclarations
+					.getDataverseName());
+		IDataFormat format = compiledDeclarations.getFormat();
+		if (format == null) {
+			throw new AlgebricksException("Data format has not been set.");
+		}
+		format.registerRuntimeFunctions();
+		Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
+				new MutableObject<ILogicalOperator>(
+						new EmptyTupleSourceOperator()));
 
-        ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
+		ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
 
-        boolean isTransactionalWrite = false;
-        ILogicalOperator topOp = p.first;
-        ProjectOperator project = (ProjectOperator) topOp;
-        LogicalVariable resVar = project.getVariables().get(0);
-        if (outputDatasetName == null) {
-            FileSplit outputFileSplit = compiledDeclarations.getOutputFile();
-            if (outputFileSplit == null) {
-                outputFileSplit = getDefaultOutputFileLocation();
-            }
-            compiledDeclarations.setOutputFile(outputFileSplit);
-            List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(1);
-            writeExprList.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(resVar)));
-            FileSplitSinkId fssi = new FileSplitSinkId(outputFileSplit);
-            FileSplitDataSink sink = new FileSplitDataSink(fssi, null);
-            topOp = new WriteOperator(writeExprList, sink);
-            topOp.getInputs().add(new MutableObject<ILogicalOperator>(project));
-        } else {
-            String dataVerseName = compiledDeclarations.getDataverseName();
-            Dataset dataset = compiledDeclarations.findDataset(outputDatasetName);
-            if (dataset == null) {
-                throw new AlgebricksException("Cannot find dataset " + outputDatasetName);
-            }
+		boolean isTransactionalWrite = false;
+		ILogicalOperator topOp = p.first;
+		ProjectOperator project = (ProjectOperator) topOp;
+		LogicalVariable resVar = project.getVariables().get(0);
+		if (outputDatasetName == null) {
+			FileSplit outputFileSplit = compiledDeclarations.getOutputFile();
+			if (outputFileSplit == null) {
+				outputFileSplit = getDefaultOutputFileLocation();
+			}
+			compiledDeclarations.setOutputFile(outputFileSplit);
+			List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(
+					1);
+			writeExprList.add(new MutableObject<ILogicalExpression>(
+					new VariableReferenceExpression(resVar)));
+			FileSplitSinkId fssi = new FileSplitSinkId(outputFileSplit);
+			FileSplitDataSink sink = new FileSplitDataSink(fssi, null);
+			topOp = new WriteOperator(writeExprList, sink);
+			topOp.getInputs().add(new MutableObject<ILogicalOperator>(project));
+		} else {
+			String dataVerseName = compiledDeclarations.getDataverseName();
+			Dataset dataset = compiledDeclarations
+					.findDataset(outputDatasetName);
+			if (dataset == null) {
+				throw new AlgebricksException("Cannot find dataset "
+						+ outputDatasetName);
+			}
 
-            AqlSourceId sourceId = new AqlSourceId(dataVerseName, outputDatasetName);
-            String itemTypeName = dataset.getItemTypeName();
-            IAType itemType = compiledDeclarations.findType(itemTypeName);
-            AqlDataSource dataSource = new AqlDataSource(sourceId, dataset, itemType);
-            if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
-                throw new AlgebricksException("Cannot write output to an external dataset.");
-            }
-            ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>();
-            ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
-            List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>();
+			AqlSourceId sourceId = new AqlSourceId(dataVerseName,
+					outputDatasetName);
+			String itemTypeName = dataset.getItemTypeName();
+			IAType itemType = compiledDeclarations.findType(itemTypeName);
+			AqlDataSource dataSource = new AqlDataSource(sourceId, dataset,
+					itemType);
+			if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
+				throw new AlgebricksException(
+						"Cannot write output to an external dataset.");
+			}
+			ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>();
+			ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
+			List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>();
 
-            List<String> partitionKeys = DatasetUtils.getPartitioningKeys(dataset);
-            for (String keyFieldName : partitionKeys) {
-                IFunctionInfo finfoAccess = AsterixBuiltinFunctions
-                        .getAsterixFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME);
-                @SuppressWarnings("unchecked")
-                ScalarFunctionCallExpression f = new ScalarFunctionCallExpression(finfoAccess,
-                        new MutableObject<ILogicalExpression>(new VariableReferenceExpression(METADATA_DUMMY_VAR)),
-                        new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(
-                                new AString(keyFieldName)))));
-                f.substituteVar(METADATA_DUMMY_VAR, resVar);
-                exprs.add(new MutableObject<ILogicalExpression>(f));
-                LogicalVariable v = context.newVar();
-                vars.add(v);
-                varRefsForLoading.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v)));
-            }
-            AssignOperator assign = new AssignOperator(vars, exprs);
-            assign.getInputs().add(new MutableObject<ILogicalOperator>(project));
+			List<String> partitionKeys = DatasetUtils
+					.getPartitioningKeys(dataset);
+			for (String keyFieldName : partitionKeys) {
+				IFunctionInfo finfoAccess = AsterixBuiltinFunctions
+						.getAsterixFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME);
+				@SuppressWarnings("unchecked")
+				ScalarFunctionCallExpression f = new ScalarFunctionCallExpression(
+						finfoAccess, new MutableObject<ILogicalExpression>(
+								new VariableReferenceExpression(
+										METADATA_DUMMY_VAR)),
+						new MutableObject<ILogicalExpression>(
+								new ConstantExpression(
+										new AsterixConstantValue(new AString(
+												keyFieldName)))));
+				f.substituteVar(METADATA_DUMMY_VAR, resVar);
+				exprs.add(new MutableObject<ILogicalExpression>(f));
+				LogicalVariable v = context.newVar();
+				vars.add(v);
+				varRefsForLoading.add(new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(v)));
+			}
+			AssignOperator assign = new AssignOperator(vars, exprs);
+			assign.getInputs()
+					.add(new MutableObject<ILogicalOperator>(project));
 
-            Mutable<ILogicalExpression> varRef = new MutableObject<ILogicalExpression>(new VariableReferenceExpression(
-                    resVar));
-            ILogicalOperator load = null;
+			Mutable<ILogicalExpression> varRef = new MutableObject<ILogicalExpression>(
+					new VariableReferenceExpression(resVar));
+			ILogicalOperator load = null;
 
-            switch (dmlKind) {
-                case WRITE_FROM_QUERY_RESULT: {
-                    load = new WriteResultOperator(dataSource, varRef, varRefsForLoading);
-                    load.getInputs().add(new MutableObject<ILogicalOperator>(assign));
-                    break;
-                }
-                case INSERT: {
-                    ILogicalOperator insertOp = new InsertDeleteOperator(dataSource, varRef, varRefsForLoading,
-                            InsertDeleteOperator.Kind.INSERT);
-                    insertOp.getInputs().add(new MutableObject<ILogicalOperator>(assign));
-                    load = new SinkOperator();
-                    load.getInputs().add(new MutableObject<ILogicalOperator>(insertOp));
-                    isTransactionalWrite = true;
-                    break;
-                }
-                case DELETE: {
-                    ILogicalOperator deleteOp = new InsertDeleteOperator(dataSource, varRef, varRefsForLoading,
-                            InsertDeleteOperator.Kind.DELETE);
-                    deleteOp.getInputs().add(new MutableObject<ILogicalOperator>(assign));
-                    load = new SinkOperator();
-                    load.getInputs().add(new MutableObject<ILogicalOperator>(deleteOp));
-                    isTransactionalWrite = true;
-                    break;
-                }
-                case BEGIN_FEED: {
-                    ILogicalOperator insertOp = new InsertDeleteOperator(dataSource, varRef, varRefsForLoading,
-                            InsertDeleteOperator.Kind.INSERT);
-                    insertOp.getInputs().add(new MutableObject<ILogicalOperator>(assign));
-                    load = new SinkOperator();
-                    load.getInputs().add(new MutableObject<ILogicalOperator>(insertOp));
-                    isTransactionalWrite = false;
-                    break;
-                }
-            }
-            topOp = load;
-        }
+			switch (dmlKind) {
+			case WRITE_FROM_QUERY_RESULT: {
+				load = new WriteResultOperator(dataSource, varRef,
+						varRefsForLoading);
+				load.getInputs().add(
+						new MutableObject<ILogicalOperator>(assign));
+				break;
+			}
+			case INSERT: {
+				ILogicalOperator insertOp = new InsertDeleteOperator(
+						dataSource, varRef, varRefsForLoading,
+						InsertDeleteOperator.Kind.INSERT);
+				insertOp.getInputs().add(
+						new MutableObject<ILogicalOperator>(assign));
+				load = new SinkOperator();
+				load.getInputs().add(
+						new MutableObject<ILogicalOperator>(insertOp));
+				isTransactionalWrite = true;
+				break;
+			}
+			case DELETE: {
+				ILogicalOperator deleteOp = new InsertDeleteOperator(
+						dataSource, varRef, varRefsForLoading,
+						InsertDeleteOperator.Kind.DELETE);
+				deleteOp.getInputs().add(
+						new MutableObject<ILogicalOperator>(assign));
+				load = new SinkOperator();
+				load.getInputs().add(
+						new MutableObject<ILogicalOperator>(deleteOp));
+				isTransactionalWrite = true;
+				break;
+			}
+			case BEGIN_FEED: {
+				ILogicalOperator insertOp = new InsertDeleteOperator(
+						dataSource, varRef, varRefsForLoading,
+						InsertDeleteOperator.Kind.INSERT);
+				insertOp.getInputs().add(
+						new MutableObject<ILogicalOperator>(assign));
+				load = new SinkOperator();
+				load.getInputs().add(
+						new MutableObject<ILogicalOperator>(insertOp));
+				isTransactionalWrite = false;
+				break;
+			}
+			}
+			topOp = load;
+		}
 
-        globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
-        ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
-        AqlMetadataProvider metadataProvider = new AqlMetadataProvider(txnId, isTransactionalWrite,
-                compiledDeclarations);
-        ILogicalPlanAndMetadata planAndMetadata = new AqlLogicalPlanAndMetadataImpl(plan, metadataProvider);
-        return planAndMetadata;
-    }
+		globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
+		ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
+		AqlMetadataProvider metadataProvider = new AqlMetadataProvider(txnId,
+				isTransactionalWrite, compiledDeclarations);
+		ILogicalPlanAndMetadata planAndMetadata = new AqlLogicalPlanAndMetadataImpl(
+				plan, metadataProvider);
+		return planAndMetadata;
+	}
 
-    private FileSplit getDefaultOutputFileLocation() throws MetadataException {
-        if (AsterixProperties.INSTANCE.getOutputDir() == null) {
-            throw new MetadataException(
-                    "Output location for query result not specified at the time of deployment, must specify explicitly using 'write output to ..' statement");
-        }
-        String filePath = AsterixProperties.INSTANCE.getOutputDir() + System.getProperty("file.separator")
-                + OUTPUT_FILE_PREFIX + outputFileID.incrementAndGet();
-        return new FileSplit(AsterixProperties.INSTANCE.getMetadataNodeName(), new FileReference(new File(filePath)));
-    }
+	private FileSplit getDefaultOutputFileLocation() throws MetadataException {
+		if (AsterixProperties.INSTANCE.getOutputDir() == null) {
+			throw new MetadataException(
+					"Output location for query result not specified at the time of deployment, must specify explicitly using 'write output to ..' statement");
+		}
+		String filePath = AsterixProperties.INSTANCE.getOutputDir()
+				+ System.getProperty("file.separator") + OUTPUT_FILE_PREFIX
+				+ outputFileID.incrementAndGet();
+		return new FileSplit(AsterixProperties.INSTANCE.getMetadataNodeName(),
+				new FileReference(new File(filePath)));
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitForClause(ForClause fc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        LogicalVariable v = context.newVar(fc.getVarExpr());
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitForClause(ForClause fc,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		LogicalVariable v = context.newVar(fc.getVarExpr());
 
-        Expression inExpr = fc.getInExpr();
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(inExpr, tupSource);
-        ILogicalOperator returnedOp;
+		Expression inExpr = fc.getInExpr();
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+				inExpr, tupSource);
+		ILogicalOperator returnedOp;
 
-        if (fc.getPosVarExpr() == null) {
-            returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)));
-        } else {
-            LogicalVariable pVar = context.newVar(fc.getPosVarExpr());
-            returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)),
-                    pVar, BuiltinType.AINT32);
-        }
-        returnedOp.getInputs().add(eo.second);
+		if (fc.getPosVarExpr() == null) {
+			returnedOp = new UnnestOperator(v,
+					new MutableObject<ILogicalExpression>(
+							makeUnnestExpression(eo.first)));
+		} else {
+			LogicalVariable pVar = context.newVar(fc.getPosVarExpr());
+			returnedOp = new UnnestOperator(v,
+					new MutableObject<ILogicalExpression>(
+							makeUnnestExpression(eo.first)), pVar,
+					BuiltinType.AINT32);
+		}
+		returnedOp.getInputs().add(eo.second);
 
-        return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLetClause(LetClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        LogicalVariable v;
-        ILogicalOperator returnedOp;
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLetClause(LetClause lc,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		LogicalVariable v;
+		ILogicalOperator returnedOp;
 
-        switch (lc.getBindingExpr().getKind()) {
-            case VARIABLE_EXPRESSION: {
-                v = context.newVar(lc.getVarExpr());
-                LogicalVariable prev = context.getVar(((VariableExpr) lc.getBindingExpr()).getVar().getId());
-                returnedOp = new AssignOperator(v, new MutableObject<ILogicalExpression>(
-                        new VariableReferenceExpression(prev)));
-                returnedOp.getInputs().add(tupSource);
-                break;
-            }
-            default: {
-                Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(lc.getBindingExpr(),
-                        tupSource);
-                v = context.newVar(lc.getVarExpr());
-                returnedOp = new AssignOperator(v, new MutableObject<ILogicalExpression>(eo.first));
-                returnedOp.getInputs().add(eo.second);
-                break;
-            }
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
-    }
+		switch (lc.getBindingExpr().getKind()) {
+		case VARIABLE_EXPRESSION: {
+			v = context.newVar(lc.getVarExpr());
+			LogicalVariable prev = context.getVar(((VariableExpr) lc
+					.getBindingExpr()).getVar().getId());
+			returnedOp = new AssignOperator(v,
+					new MutableObject<ILogicalExpression>(
+							new VariableReferenceExpression(prev)));
+			returnedOp.getInputs().add(tupSource);
+			break;
+		}
+		default: {
+			v = context.newVar(lc.getVarExpr());
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+					lc.getBindingExpr(), tupSource);
+			returnedOp = new AssignOperator(v,
+					new MutableObject<ILogicalExpression>(eo.first));
+			returnedOp.getInputs().add(eo.second);
+			break;
+		}
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitFlworExpression(FLWOGRExpression flwor,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Mutable<ILogicalOperator> flworPlan = tupSource;
-        boolean isTop = context.isTopFlwor();
-        if (isTop) {
-            context.setTopFlwor(false);
-        }
-        for (Clause c : flwor.getClauseList()) {
-            Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this, flworPlan);
-            flworPlan = new MutableObject<ILogicalOperator>(pC.first);
-        }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitFlworExpression(
+			FLWOGRExpression flwor, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Mutable<ILogicalOperator> flworPlan = tupSource;
+		boolean isTop = context.isTopFlwor();
+		if (isTop) {
+			context.setTopFlwor(false);
+		}
+		for (Clause c : flwor.getClauseList()) {
+			Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this,
+					flworPlan);
+			flworPlan = new MutableObject<ILogicalOperator>(pC.first);
+		}
 
-        Expression r = flwor.getReturnExpr();
-        boolean noFlworClause = flwor.noForClause();
+		Expression r = flwor.getReturnExpr();
+		boolean noFlworClause = flwor.noForClause();
 
-        if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
-            VariableExpr v = (VariableExpr) r;
-            LogicalVariable var = context.getVar(v.getVar().getId());
+		if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
+			VariableExpr v = (VariableExpr) r;
+			LogicalVariable var = context.getVar(v.getVar().getId());
 
-            return produceFlwrResult(noFlworClause, isTop, flworPlan, var);
+			return produceFlwrResult(noFlworClause, isTop, flworPlan, var);
 
-        } else {
-            Mutable<ILogicalOperator> baseOp = new MutableObject<ILogicalOperator>(flworPlan.getValue());
-            Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this, baseOp);
-            ILogicalOperator rOp = rRes.first;
-            ILogicalOperator resOp;
-            if (expressionNeedsNoNesting(r)) {
-                baseOp.setValue(flworPlan.getValue());
-                resOp = rOp;
-            } else {
-                SubplanOperator s = new SubplanOperator(rOp);
-                s.getInputs().add(flworPlan);
-                resOp = s;
-                baseOp.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
-            }
-            Mutable<ILogicalOperator> resOpRef = new MutableObject<ILogicalOperator>(resOp);
-            return produceFlwrResult(noFlworClause, isTop, resOpRef, rRes.second);
-        }
-    }
+		} else {
+			Mutable<ILogicalOperator> baseOp = new MutableObject<ILogicalOperator>(
+					flworPlan.getValue());
+			Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this,
+					baseOp);
+			ILogicalOperator rOp = rRes.first;
+			ILogicalOperator resOp;
+			if (expressionNeedsNoNesting(r)) {
+				baseOp.setValue(flworPlan.getValue());
+				resOp = rOp;
+			} else {
+				SubplanOperator s = new SubplanOperator(rOp);
+				s.getInputs().add(flworPlan);
+				resOp = s;
+				baseOp.setValue(new NestedTupleSourceOperator(
+						new MutableObject<ILogicalOperator>(s)));
+			}
+			Mutable<ILogicalOperator> resOpRef = new MutableObject<ILogicalOperator>(
+					resOp);
+			return produceFlwrResult(noFlworClause, isTop, resOpRef,
+					rRes.second);
+		}
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitFieldAccessor(FieldAccessor fa,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(fa.getExpr(), tupSource);
-        LogicalVariable v = context.newVar();
-        AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
-                FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME));
-        fldAccess.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
-        ILogicalExpression faExpr = new ConstantExpression(new AsterixConstantValue(new AString(fa.getIdent()
-                .getValue())));
-        fldAccess.getArguments().add(new MutableObject<ILogicalExpression>(faExpr));
-        AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(fldAccess));
-        a.getInputs().add(p.second);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v);
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitFieldAccessor(
+			FieldAccessor fa, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+				fa.getExpr(), tupSource);
+		LogicalVariable v = context.newVar();
+		AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
+				FunctionUtils
+						.getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME));
+		fldAccess.getArguments().add(
+				new MutableObject<ILogicalExpression>(p.first));
+		ILogicalExpression faExpr = new ConstantExpression(
+				new AsterixConstantValue(new AString(fa.getIdent().getValue())));
+		fldAccess.getArguments().add(
+				new MutableObject<ILogicalExpression>(faExpr));
+		AssignOperator a = new AssignOperator(v,
+				new MutableObject<ILogicalExpression>(fldAccess));
+		a.getInputs().add(p.second);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v);
 
-    }
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitIndexAccessor(IndexAccessor ia,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(ia.getExpr(), tupSource);
-        LogicalVariable v = context.newVar();
-        AbstractFunctionCallExpression f;
-        int i = ia.getIndex();
-        if (i == IndexAccessor.ANY) {
-            f = new ScalarFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
-            f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
-        } else {
-            f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
-            f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
-            f.getArguments().add(
-                    new MutableObject<ILogicalExpression>(new ConstantExpression(
-                            new AsterixConstantValue(new AInt32(i)))));
-        }
-        AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
-        a.getInputs().add(p.second);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitIndexAccessor(
+			IndexAccessor ia, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+				ia.getExpr(), tupSource);
+		LogicalVariable v = context.newVar();
+		AbstractFunctionCallExpression f;
+		int i = ia.getIndex();
+		if (i == IndexAccessor.ANY) {
+			f = new ScalarFunctionCallExpression(
+					FunctionUtils
+							.getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
+			f.getArguments()
+					.add(new MutableObject<ILogicalExpression>(p.first));
+		} else {
+			f = new ScalarFunctionCallExpression(
+					FunctionUtils
+							.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
+			f.getArguments()
+					.add(new MutableObject<ILogicalExpression>(p.first));
+			f.getArguments().add(
+					new MutableObject<ILogicalExpression>(
+							new ConstantExpression(new AsterixConstantValue(
+									new AInt32(i)))));
+		}
+		AssignOperator a = new AssignOperator(v,
+				new MutableObject<ILogicalExpression>(f));
+		a.getInputs().add(p.second);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitCallExpr(CallExpr fcall, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        LogicalVariable v = context.newVar();
-        AsterixFunction fid = fcall.getIdent();
-        List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
-        Mutable<ILogicalOperator> topOp = tupSource;
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitCallExpr(
+			CallExpr fcall, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		LogicalVariable v = context.newVar();
+		AsterixFunction fid = fcall.getIdent();
+		List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
+		Mutable<ILogicalOperator> topOp = tupSource;
 
-        for (Expression expr : fcall.getExprList()) {
-            switch (expr.getKind()) {
-                case VARIABLE_EXPRESSION: {
-                    LogicalVariable var = context.getVar(((VariableExpr) expr).getVar().getId());
-                    args.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
-                    break;
-                }
-                case LITERAL_EXPRESSION: {
-                    LiteralExpr val = (LiteralExpr) expr;
-                    args.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(
-                            ConstantHelper.objectFromLiteral(val.getValue())))));
-                    break;
-                }
-                default: {
-                    Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, topOp);
-                    AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second.getValue();
-                    args.add(new MutableObject<ILogicalExpression>(eo.first));
-                    if (o1 != null && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(o1, topOp))) {
-                        topOp = eo.second;
-                    }
-                    break;
-                }
-            }
-        }
+		for (Expression expr : fcall.getExprList()) {
+			switch (expr.getKind()) {
+			case VARIABLE_EXPRESSION: {
+				LogicalVariable var = context.getVar(((VariableExpr) expr)
+						.getVar().getId());
+				args.add(new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(var)));
+				break;
+			}
+			case LITERAL_EXPRESSION: {
+				LiteralExpr val = (LiteralExpr) expr;
+				args.add(new MutableObject<ILogicalExpression>(
+						new ConstantExpression(
+								new AsterixConstantValue(ConstantHelper
+										.objectFromLiteral(val.getValue())))));
+				break;
+			}
+			default: {
+				Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+						expr, topOp);
+				AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second
+						.getValue();
+				args.add(new MutableObject<ILogicalExpression>(eo.first));
+				if (o1 != null
+						&& !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(
+								o1, topOp))) {
+					topOp = eo.second;
+				}
+				break;
+			}
+			}
+		}
 
-        FunctionIdentifier fi = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS, fid.getFunctionName(),
-                false);
-        AsterixFunctionInfo afi = AsterixBuiltinFunctions.lookupFunction(fi);
-        FunctionIdentifier builtinAquafi = afi == null ? null : afi.getFunctionIdentifier();
+		FunctionIdentifier fi = new FunctionIdentifier(
+				AlgebricksBuiltinFunctions.ALGEBRICKS_NS, fid.getFunctionName());
+		AsterixFunctionInfo afi = AsterixBuiltinFunctions.lookupFunction(fi);
+		FunctionIdentifier builtinAquafi = afi == null ? null : afi
+				.getFunctionIdentifier();
 
-        if (builtinAquafi != null) {
-            fi = builtinAquafi;
-        } else {
-            fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, fid.getFunctionName(), false);
-            FunctionIdentifier builtinAsterixFi = AsterixBuiltinFunctions.getBuiltinFunctionIdentifier(fi);
-            if (builtinAsterixFi != null) {
-                fi = builtinAsterixFi;
-            }
-        }
-        AbstractFunctionCallExpression f;
-        if (AsterixBuiltinFunctions.isBuiltinAggregateFunction(fi)) {
-            f = AsterixBuiltinFunctions.makeAggregateFunctionExpression(fi, args);
-        } else if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(fi)) {
-            UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(fi), args);
-            ufce.setReturnsUniqueValues(AsterixBuiltinFunctions.returnsUniqueValues(fi));
-            f = ufce;
-        } else {
-            f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fi), args);
-        }
-        AssignOperator op = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
-        if (topOp != null) {
-            op.getInputs().add(topOp);
-        }
+		if (builtinAquafi != null) {
+			fi = builtinAquafi;
+		} else {
+			fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+					fid.getFunctionName());
+			FunctionIdentifier builtinAsterixFi = AsterixBuiltinFunctions
+					.getBuiltinFunctionIdentifier(fi);
+			if (builtinAsterixFi != null) {
+				fi = builtinAsterixFi;
+			}
+		}
+		AbstractFunctionCallExpression f;
+		if (AsterixBuiltinFunctions.isBuiltinAggregateFunction(fi)) {
+			f = AsterixBuiltinFunctions.makeAggregateFunctionExpression(fi,
+					args);
+		} else if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(fi)) {
+			UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(
+					FunctionUtils.getFunctionInfo(fi), args);
+			ufce.setReturnsUniqueValues(AsterixBuiltinFunctions
+					.returnsUniqueValues(fi));
+			f = ufce;
+		} else {
+			f = new ScalarFunctionCallExpression(
+					FunctionUtils.getFunctionInfo(fi), args);
+		}
+		AssignOperator op = new AssignOperator(v,
+				new MutableObject<ILogicalExpression>(f));
+		if (topOp != null) {
+			op.getInputs().add(topOp);
+		}
 
-        return new Pair<ILogicalOperator, LogicalVariable>(op, v);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(op, v);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitFunctionDecl(FunctionDecl fd,
-            Mutable<ILogicalOperator> tupSource) {
-        // TODO Auto-generated method stub
-        throw new NotImplementedException();
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitFunctionDecl(
+			FunctionDecl fd, Mutable<ILogicalOperator> tupSource) {
+		// TODO Auto-generated method stub
+		throw new NotImplementedException();
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitGroupbyClause(GroupbyClause gc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        GroupByOperator gOp = new GroupByOperator();
-        Mutable<ILogicalOperator> topOp = tupSource;
-        for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
-            LogicalVariable v;
-            VariableExpr vexpr = ve.getVar();
-            if (vexpr != null) {
-                v = context.newVar(vexpr);
-            } else {
-                v = context.newVar();
-            }
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(ve.getExpr(), topOp);
-            gOp.addGbyExpression(v, eo.first);
-            topOp = eo.second;
-        }
-        for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
-            LogicalVariable v;
-            VariableExpr vexpr = ve.getVar();
-            if (vexpr != null) {
-                v = context.newVar(vexpr);
-            } else {
-                v = context.newVar();
-            }
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(ve.getExpr(), topOp);
-            gOp.addDecorExpression(v, eo.first);
-            topOp = eo.second;
-        }
-        gOp.getInputs().add(topOp);
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitGroupbyClause(
+			GroupbyClause gc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		GroupByOperator gOp = new GroupByOperator();
+		Mutable<ILogicalOperator> topOp = tupSource;
+		for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
+			LogicalVariable v;
+			VariableExpr vexpr = ve.getVar();
+			if (vexpr != null) {
+				v = context.newVar(vexpr);
+			} else {
+				v = context.newVar();
+			}
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+					ve.getExpr(), topOp);
+			gOp.addGbyExpression(v, eo.first);
+			topOp = eo.second;
+		}
+		for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
+			LogicalVariable v;
+			VariableExpr vexpr = ve.getVar();
+			if (vexpr != null) {
+				v = context.newVar(vexpr);
+			} else {
+				v = context.newVar();
+			}
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+					ve.getExpr(), topOp);
+			gOp.addDecorExpression(v, eo.first);
+			topOp = eo.second;
+		}
+		gOp.getInputs().add(topOp);
 
-        for (VariableExpr var : gc.getWithVarList()) {
-            LogicalVariable aggVar = context.newVar();
-            LogicalVariable oldVar = context.getVar(var);
-            List<Mutable<ILogicalExpression>> flArgs = new ArrayList<Mutable<ILogicalExpression>>(1);
-            flArgs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(oldVar)));
-            AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
-                    AsterixBuiltinFunctions.LISTIFY, flArgs);
-            AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(aggVar),
-                    (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(fListify)));
+		for (VariableExpr var : gc.getWithVarList()) {
+			LogicalVariable aggVar = context.newVar();
+			LogicalVariable oldVar = context.getVar(var);
+			List<Mutable<ILogicalExpression>> flArgs = new ArrayList<Mutable<ILogicalExpression>>(
+					1);
+			flArgs.add(new MutableObject<ILogicalExpression>(
+					new VariableReferenceExpression(oldVar)));
+			AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions
+					.makeAggregateFunctionExpression(
+							AsterixBuiltinFunctions.LISTIFY, flArgs);
+			AggregateOperator agg = new AggregateOperator(
+					mkSingletonArrayList(aggVar),
+					(List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
+							fListify)));
 
-            agg.getInputs().add(
-                    new MutableObject<ILogicalOperator>(new NestedTupleSourceOperator(
-                            new MutableObject<ILogicalOperator>(gOp))));
-            ILogicalPlan plan = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(agg));
-            gOp.getNestedPlans().add(plan);
-            // Hide the variable that was part of the "with", replacing it with
-            // the one bound by the aggregation op.
-            context.setVar(var, aggVar);
-        }
+			agg.getInputs().add(
+					new MutableObject<ILogicalOperator>(
+							new NestedTupleSourceOperator(
+									new MutableObject<ILogicalOperator>(gOp))));
+			ILogicalPlan plan = new ALogicalPlanImpl(
+					new MutableObject<ILogicalOperator>(agg));
+			gOp.getNestedPlans().add(plan);
+			// Hide the variable that was part of the "with", replacing it with
+			// the one bound by the aggregation op.
+			context.setVar(var, aggVar);
+		}
 
-        gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, gc.hasHashGroupByHint());
-        return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
-    }
+		gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY,
+				gc.hasHashGroupByHint());
+		return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitIfExpr(IfExpr ifexpr, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        // In the most general case, IfThenElse is translated in the following
-        // way.
-        //
-        // We assign the result of the condition to one variable varCond.
-        // We create one subplan which contains the plan for the "then" branch,
-        // on top of which there is a selection whose condition is varCond.
-        // Similarly, we create one subplan for the "else" branch, in which the
-        // selection is not(varCond).
-        // Finally, we concatenate the results. (??)
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitIfExpr(IfExpr ifexpr,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		// In the most general case, IfThenElse is translated in the following
+		// way.
+		//
+		// We assign the result of the condition to one variable varCond.
+		// We create one subplan which contains the plan for the "then" branch,
+		// on top of which there is a selection whose condition is varCond.
+		// Similarly, we create one subplan for the "else" branch, in which the
+		// selection is not(varCond).
+		// Finally, we concatenate the results. (??)
 
-        Pair<ILogicalOperator, LogicalVariable> pCond = ifexpr.getCondExpr().accept(this, tupSource);
-        ILogicalOperator opCond = pCond.first;
-        LogicalVariable varCond = pCond.second;
+		Pair<ILogicalOperator, LogicalVariable> pCond = ifexpr.getCondExpr()
+				.accept(this, tupSource);
+		ILogicalOperator opCond = pCond.first;
+		LogicalVariable varCond = pCond.second;
 
-        SubplanOperator sp = new SubplanOperator();
-        Mutable<ILogicalOperator> nestedSource = new MutableObject<ILogicalOperator>(new NestedTupleSourceOperator(
-                new MutableObject<ILogicalOperator>(sp)));
+		SubplanOperator sp = new SubplanOperator();
+		Mutable<ILogicalOperator> nestedSource = new MutableObject<ILogicalOperator>(
+				new NestedTupleSourceOperator(
+						new MutableObject<ILogicalOperator>(sp)));
 
-        Pair<ILogicalOperator, LogicalVariable> pThen = ifexpr.getThenExpr().accept(this, nestedSource);
-        SelectOperator sel1 = new SelectOperator(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(
-                varCond)));
-        sel1.getInputs().add(new MutableObject<ILogicalOperator>(pThen.first));
+		Pair<ILogicalOperator, LogicalVariable> pThen = ifexpr.getThenExpr()
+				.accept(this, nestedSource);
+		SelectOperator sel1 = new SelectOperator(
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(varCond)));
+		sel1.getInputs().add(new MutableObject<ILogicalOperator>(pThen.first));
 
-        Pair<ILogicalOperator, LogicalVariable> pElse = ifexpr.getElseExpr().accept(this, nestedSource);
-        AbstractFunctionCallExpression notVarCond = new ScalarFunctionCallExpression(
-                FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), new MutableObject<ILogicalExpression>(
-                        new VariableReferenceExpression(varCond)));
-        SelectOperator sel2 = new SelectOperator(new MutableObject<ILogicalExpression>(notVarCond));
-        sel2.getInputs().add(new MutableObject<ILogicalOperator>(pElse.first));
+		Pair<ILogicalOperator, LogicalVariable> pElse = ifexpr.getElseExpr()
+				.accept(this, nestedSource);
+		AbstractFunctionCallExpression notVarCond = new ScalarFunctionCallExpression(
+				FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT),
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(varCond)));
+		SelectOperator sel2 = new SelectOperator(
+				new MutableObject<ILogicalExpression>(notVarCond));
+		sel2.getInputs().add(new MutableObject<ILogicalOperator>(pElse.first));
 
-        ILogicalPlan p1 = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(sel1));
-        sp.getNestedPlans().add(p1);
-        ILogicalPlan p2 = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(sel2));
-        sp.getNestedPlans().add(p2);
+		ILogicalPlan p1 = new ALogicalPlanImpl(
+				new MutableObject<ILogicalOperator>(sel1));
+		sp.getNestedPlans().add(p1);
+		ILogicalPlan p2 = new ALogicalPlanImpl(
+				new MutableObject<ILogicalOperator>(sel2));
+		sp.getNestedPlans().add(p2);
 
-        Mutable<ILogicalOperator> opCondRef = new MutableObject<ILogicalOperator>(opCond);
-        sp.getInputs().add(opCondRef);
+		Mutable<ILogicalOperator> opCondRef = new MutableObject<ILogicalOperator>(
+				opCond);
+		sp.getInputs().add(opCondRef);
 
-        LogicalVariable resV = context.newVar();
-        AbstractFunctionCallExpression concatNonNull = new ScalarFunctionCallExpression(
-                FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.CONCAT_NON_NULL),
-                new MutableObject<ILogicalExpression>(new VariableReferenceExpression(pThen.second)),
-                new MutableObject<ILogicalExpression>(new VariableReferenceExpression(pElse.second)));
-        AssignOperator a = new AssignOperator(resV, new MutableObject<ILogicalExpression>(concatNonNull));
-        a.getInputs().add(new MutableObject<ILogicalOperator>(sp));
+		LogicalVariable resV = context.newVar();
+		AbstractFunctionCallExpression concatNonNull = new ScalarFunctionCallExpression(
+				FunctionUtils
+						.getFunctionInfo(AsterixBuiltinFunctions.CONCAT_NON_NULL),
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(pThen.second)),
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(pElse.second)));
+		AssignOperator a = new AssignOperator(resV,
+				new MutableObject<ILogicalExpression>(concatNonNull));
+		a.getInputs().add(new MutableObject<ILogicalOperator>(sp));
 
-        return new Pair<ILogicalOperator, LogicalVariable>(a, resV);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(a, resV);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLiteralExpr(LiteralExpr l, Mutable<ILogicalOperator> tupSource) {
-        LogicalVariable var = context.newVar();
-        AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(new ConstantExpression(
-                new AsterixConstantValue(ConstantHelper.objectFromLiteral(l.getValue())))));
-        if (tupSource != null) {
-            a.getInputs().add(tupSource);
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(a, var);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLiteralExpr(
+			LiteralExpr l, Mutable<ILogicalOperator> tupSource) {
+		LogicalVariable var = context.newVar();
+		AssignOperator a = new AssignOperator(var,
+				new MutableObject<ILogicalExpression>(new ConstantExpression(
+						new AsterixConstantValue(ConstantHelper
+								.objectFromLiteral(l.getValue())))));
+		if (tupSource != null) {
+			a.getInputs().add(tupSource);
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitOperatorExpr(OperatorExpr op,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        ArrayList<OperatorType> ops = op.getOpList();
-        int nOps = ops.size();
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitOperatorExpr(
+			OperatorExpr op, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		ArrayList<OperatorType> ops = op.getOpList();
+		int nOps = ops.size();
 
-        if (nOps > 0 && (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
-            return visitAndOrOperator(op, tupSource);
-        }
+		if (nOps > 0
+				&& (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
+			return visitAndOrOperator(op, tupSource);
+		}
 
-        ArrayList<Expression> exprs = op.getExprList();
+		ArrayList<Expression> exprs = op.getExprList();
 
-        Mutable<ILogicalOperator> topOp = tupSource;
+		Mutable<ILogicalOperator> topOp = tupSource;
 
-        ILogicalExpression currExpr = null;
-        for (int i = 0; i <= nOps; i++) {
+		ILogicalExpression currExpr = null;
+		for (int i = 0; i <= nOps; i++) {
 
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(exprs.get(i), topOp);
-            topOp = p.second;
-            ILogicalExpression e = p.first;
-            // now look at the operator
-            if (i < nOps) {
-                if (OperatorExpr.opIsComparison(ops.get(i))) {
-                    AbstractFunctionCallExpression c = createComparisonExpression(ops.get(i));
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+					exprs.get(i), topOp);
+			topOp = p.second;
+			ILogicalExpression e = p.first;
+			// now look at the operator
+			if (i < nOps) {
+				if (OperatorExpr.opIsComparison(ops.get(i))) {
+					AbstractFunctionCallExpression c = createComparisonExpression(ops
+							.get(i));
 
-                    // chain the operators
-                    if (i == 0) {
-                        c.getArguments().add(new MutableObject<ILogicalExpression>(e));
-                        currExpr = c;
-                        if (op.isBroadcastOperand(i)) {
-                            BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
-                            bcast.setObject(BroadcastSide.LEFT);
-                            c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
-                        }
-                    } else {
-                        ((AbstractFunctionCallExpression) currExpr).getArguments().add(
-                                new MutableObject<ILogicalExpression>(e));
-                        c.getArguments().add(new MutableObject<ILogicalExpression>(currExpr));
-                        currExpr = c;
-                        if (i == 1 && op.isBroadcastOperand(i)) {
-                            BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
-                            bcast.setObject(BroadcastSide.RIGHT);
-                            c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
-                        }
-                    }
-                } else {
-                    AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops.get(i));
+					// chain the operators
+					if (i == 0) {
+						c.getArguments().add(
+								new MutableObject<ILogicalExpression>(e));
+						currExpr = c;
+						if (op.isBroadcastOperand(i)) {
+							BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+							bcast.setObject(BroadcastSide.LEFT);
+							c.getAnnotations()
+									.put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
+											bcast);
+						}
+					} else {
+						((AbstractFunctionCallExpression) currExpr)
+								.getArguments()
+								.add(new MutableObject<ILogicalExpression>(e));
+						c.getArguments()
+								.add(new MutableObject<ILogicalExpression>(
+										currExpr));
+						currExpr = c;
+						if (i == 1 && op.isBroadcastOperand(i)) {
+							BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+							bcast.setObject(BroadcastSide.RIGHT);
+							c.getAnnotations()
+									.put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
+											bcast);
+						}
+					}
+				} else {
+					AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops
+							.get(i));
 
-                    if (i == 0) {
-                        f.getArguments().add(new MutableObject<ILogicalExpression>(e));
-                        currExpr = f;
-                    } else {
-                        ((AbstractFunctionCallExpression) currExpr).getArguments().add(
-                                new MutableObject<ILogicalExpression>(e));
-                        f.getArguments().add(new MutableObject<ILogicalExpression>(currExpr));
-                        currExpr = f;
-                    }
-                }
-            } else { // don't forget the last expression...
-                ((AbstractFunctionCallExpression) currExpr).getArguments()
-                        .add(new MutableObject<ILogicalExpression>(e));
-                if (i == 1 && op.isBroadcastOperand(i)) {
-                    BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
-                    bcast.setObject(BroadcastSide.RIGHT);
-                    ((AbstractFunctionCallExpression) currExpr).getAnnotations().put(
-                            BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
-                }
-            }
-        }
+					if (i == 0) {
+						f.getArguments().add(
+								new MutableObject<ILogicalExpression>(e));
+						currExpr = f;
+					} else {
+						((AbstractFunctionCallExpression) currExpr)
+								.getArguments()
+								.add(new MutableObject<ILogicalExpression>(e));
+						f.getArguments()
+								.add(new MutableObject<ILogicalExpression>(
+										currExpr));
+						currExpr = f;
+					}
+				}
+			} else { // don't forget the last expression...
+				((AbstractFunctionCallExpression) currExpr).getArguments().add(
+						new MutableObject<ILogicalExpression>(e));
+				if (i == 1 && op.isBroadcastOperand(i)) {
+					BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+					bcast.setObject(BroadcastSide.RIGHT);
+					((AbstractFunctionCallExpression) currExpr)
+							.getAnnotations()
+							.put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
+									bcast);
+				}
+			}
+		}
 
-        LogicalVariable assignedVar = context.newVar();
-        AssignOperator a = new AssignOperator(assignedVar, new MutableObject<ILogicalExpression>(currExpr));
+		LogicalVariable assignedVar = context.newVar();
+		AssignOperator a = new AssignOperator(assignedVar,
+				new MutableObject<ILogicalExpression>(currExpr));
 
-        a.getInputs().add(topOp);
+		a.getInputs().add(topOp);
 
-        return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitOrderbyClause(OrderbyClause oc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+	@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;
-        for (Expression e : oc.getOrderbyList()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(e, topOp);
-            OrderModifier m = modifIter.next();
-            OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
-            ord.getOrderExpressions()
-                    .add(new Pair<IOrder, Mutable<ILogicalExpression>>(comp, new MutableObject<ILogicalExpression>(
-                            p.first)));
-            topOp = p.second;
-        }
-        ord.getInputs().add(topOp);
-        if (oc.getNumTuples() > 0) {
-            ord.getAnnotations().put(OperatorAnnotations.CARDINALITY, oc.getNumTuples());
-        }
-        if (oc.getNumFrames() > 0) {
-            ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames());
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
-    }
+		OrderOperator ord = new OrderOperator();
+		Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
+		Mutable<ILogicalOperator> topOp = tupSource;
+		for (Expression e : oc.getOrderbyList()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+					e, topOp);
+			OrderModifier m = modifIter.next();
+			OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER
+					: OrderOperator.DESC_ORDER;
+			ord.getOrderExpressions().add(
+					new Pair<IOrder, Mutable<ILogicalExpression>>(comp,
+							new MutableObject<ILogicalExpression>(p.first)));
+			topOp = p.second;
+		}
+		ord.getInputs().add(topOp);
+		if (oc.getNumTuples() > 0) {
+			ord.getAnnotations().put(OperatorAnnotations.CARDINALITY,
+					oc.getNumTuples());
+		}
+		if (oc.getNumFrames() > 0) {
+			ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES,
+					oc.getNumFrames());
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitQuantifiedExpression(QuantifiedExpression qe,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Mutable<ILogicalOperator> topOp = tupSource;
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitQuantifiedExpression(
+			QuantifiedExpression qe, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Mutable<ILogicalOperator> topOp = tupSource;
 
-        ILogicalOperator firstOp = null;
-        Mutable<ILogicalOperator> lastOp = null;
+		ILogicalOperator firstOp = null;
+		Mutable<ILogicalOperator> lastOp = null;
 
-        for (QuantifiedPair qt : qe.getQuantifiedList()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(qt.getExpr(), topOp);
-            topOp = eo1.second;
-            LogicalVariable uVar = context.newVar(qt.getVarExpr());
-            ILogicalOperator u = new UnnestOperator(uVar, new MutableObject<ILogicalExpression>(
-                    makeUnnestExpression(eo1.first)));
+		for (QuantifiedPair qt : qe.getQuantifiedList()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(
+					qt.getExpr(), topOp);
+			topOp = eo1.second;
+			LogicalVariable uVar = context.newVar(qt.getVarExpr());
+			ILogicalOperator u = new UnnestOperator(uVar,
+					new MutableObject<ILogicalExpression>(
+							makeUnnestExpression(eo1.first)));
 
-            if (firstOp == null) {
-                firstOp = u;
-            }
-            if (lastOp != null) {
-                u.getInputs().add(lastOp);
-            }
-            lastOp = new MutableObject<ILogicalOperator>(u);
-        }
+			if (firstOp == null) {
+				firstOp = u;
+			}
+			if (lastOp != null) {
+				u.getInputs().add(lastOp);
+			}
+			lastOp = new MutableObject<ILogicalOperator>(u);
+		}
 
-        // We make all the unnest correspond. to quantif. vars. sit on top
-        // in the hope of enabling joins & other optimiz.
-        firstOp.getInputs().add(topOp);
-        topOp = lastOp;
+		// We make all the unnest correspond. to quantif. vars. sit on top
+		// in the hope of enabling joins & other optimiz.
+		firstOp.getInputs().add(topOp);
+		topOp = lastOp;
 
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(qe.getSatisfiesExpr(), topOp);
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(
+				qe.getSatisfiesExpr(), topOp);
 
-        AggregateFunctionCallExpression fAgg;
-        SelectOperator s;
-        if (qe.getQuantifier() == Quantifier.SOME) {
-            s = new SelectOperator(new MutableObject<ILogicalExpression>(eo2.first));
-            s.getInputs().add(eo2.second);
-            fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(AsterixBuiltinFunctions.NON_EMPTY_STREAM,
-                    new ArrayList<Mutable<ILogicalExpression>>());
-        } else { // EVERY
-            List<Mutable<ILogicalExpression>> satExprList = new ArrayList<Mutable<ILogicalExpression>>(1);
-            satExprList.add(new MutableObject<ILogicalExpression>(eo2.first));
-            s = new SelectOperator(new MutableObject<ILogicalExpression>(new ScalarFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), satExprList)));
-            s.getInputs().add(eo2.second);
-            fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(AsterixBuiltinFunctions.EMPTY_STREAM,
-                    new ArrayList<Mutable<ILogicalExpression>>());
-        }
-        LogicalVariable qeVar = context.newVar();
-        AggregateOperator a = new AggregateOperator(mkSingletonArrayList(qeVar),
-                (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(fAgg)));
-        a.getInputs().add(new MutableObject<ILogicalOperator>(s));
-        return new Pair<ILogicalOperator, LogicalVariable>(a, qeVar);
-    }
+		AggregateFunctionCallExpression fAgg;
+		SelectOperator s;
+		if (qe.getQuantifier() == Quantifier.SOME) {
+			s = new SelectOperator(new MutableObject<ILogicalExpression>(
+					eo2.first));
+			s.getInputs().add(eo2.second);
+			fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+					AsterixBuiltinFunctions.NON_EMPTY_STREAM,
+					new ArrayList<Mutable<ILogicalExpression>>());
+		} else { // EVERY
+			List<Mutable<ILogicalExpression>> satExprList = new ArrayList<Mutable<ILogicalExpression>>(
+					1);
+			satExprList.add(new MutableObject<ILogicalExpression>(eo2.first));
+			s = new SelectOperator(new MutableObject<ILogicalExpression>(
+					new ScalarFunctionCallExpression(FunctionUtils
+							.getFunctionInfo(AlgebricksBuiltinFunctions.NOT),
+							satExprList)));
+			s.getInputs().add(eo2.second);
+			fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+					AsterixBuiltinFunctions.EMPTY_STREAM,
+					new ArrayList<Mutable<ILogicalExpression>>());
+		}
+		LogicalVariable qeVar = context.newVar();
+		AggregateOperator a = new AggregateOperator(
+				mkSingletonArrayList(qeVar),
+				(List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
+						fAgg)));
+		a.getInputs().add(new MutableObject<ILogicalOperator>(s));
+		return new Pair<ILogicalOperator, LogicalVariable>(a, qeVar);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitQuery(Query q, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        return q.getBody().accept(this, tupSource);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitQuery(Query q,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		return q.getBody().accept(this, tupSource);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitRecordConstructor(RecordConstructor rc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
-                FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
-        LogicalVariable v1 = context.newVar();
-        AssignOperator a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(f));
-        Mutable<ILogicalOperator> topOp = tupSource;
-        for (FieldBinding fb : rc.getFbList()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(fb.getLeftExpr(), topOp);
-            f.getArguments().add(new MutableObject<ILogicalExpression>(eo1.first));
-            topOp = eo1.second;
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(fb.getRightExpr(), topOp);
-            f.getArguments().add(new MutableObject<ILogicalExpression>(eo2.first));
-            topOp = eo2.second;
-        }
-        a.getInputs().add(topOp);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitRecordConstructor(
+			RecordConstructor rc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
+				FunctionUtils
+						.getFunctionInfo(AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
+		LogicalVariable v1 = context.newVar();
+		AssignOperator a = new AssignOperator(v1,
+				new MutableObject<ILogicalExpression>(f));
+		Mutable<ILogicalOperator> topOp = tupSource;
+		for (FieldBinding fb : rc.getFbList()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(
+					fb.getLeftExpr(), topOp);
+			f.getArguments().add(
+					new MutableObject<ILogicalExpression>(eo1.first));
+			topOp = eo1.second;
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(
+					fb.getRightExpr(), topOp);
+			f.getArguments().add(
+					new MutableObject<ILogicalExpression>(eo2.first));
+			topOp = eo2.second;
+		}
+		a.getInputs().add(topOp);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitListConstructor(ListConstructor lc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR) ? AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR
-                : AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
-        AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fid));
-        LogicalVariable v1 = context.newVar();
-        AssignOperator a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(f));
-        Mutable<ILogicalOperator> topOp = tupSource;
-        for (Expression expr : lc.getExprList()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, topOp);
-            f.getArguments().add(new MutableObject<ILogicalExpression>(eo.first));
-            topOp = eo.second;
-        }
-        a.getInputs().add(topOp);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitListConstructor(
+			ListConstructor lc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR) ? AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR
+				: AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
+		AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
+				FunctionUtils.getFunctionInfo(fid));
+		LogicalVariable v1 = context.newVar();
+		AssignOperator a = new AssignOperator(v1,
+				new MutableObject<ILogicalExpression>(f));
+		Mutable<ILogicalOperator> topOp = tupSource;
+		for (Expression expr : lc.getExprList()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+					expr, topOp);
+			f.getArguments().add(
+					new MutableObject<ILogicalExpression>(eo.first));
+			topOp = eo.second;
+		}
+		a.getInputs().add(topOp);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUnaryExpr(UnaryExpr u, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        Expression expr = u.getExpr();
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, tupSource);
-        LogicalVariable v1 = context.newVar();
-        AssignOperator a;
-        if (u.getSign() == Sign.POSITIVE) {
-            a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(eo.first));
-        } else {
-            AbstractFunctionCallExpression m = new ScalarFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS));
-            m.getArguments().add(new MutableObject<ILogicalExpression>(eo.first));
-            a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(m));
-        }
-        a.getInputs().add(eo.second);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUnaryExpr(UnaryExpr u,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		Expression expr = u.getExpr();
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+				expr, tupSource);
+		LogicalVariable v1 = context.newVar();
+		AssignOperator a;
+		if (u.getSign() == Sign.POSITIVE) {
+			a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(
+					eo.first));
+		} else {
+			AbstractFunctionCallExpression m = new ScalarFunctionCallExpression(
+					FunctionUtils
+							.getFunctionInfo(AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS));
+			m.getArguments().add(
+					new MutableObject<ILogicalExpression>(eo.first));
+			a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(m));
+		}
+		a.getInputs().add(eo.second);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitVariableExpr(VariableExpr v, Mutable<ILogicalOperator> tupSource) {
-        // Should we ever get to this method?
-        LogicalVariable var = context.newVar();
-        LogicalVariable oldV = context.getVar(v.getVar().getId());
-        AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(
-                new VariableReferenceExpression(oldV)));
-        a.getInputs().add(tupSource);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, var);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitVariableExpr(
+			VariableExpr v, Mutable<ILogicalOperator> tupSource) {
+		// Should we ever get to this method?
+		LogicalVariable var = context.newVar();
+		LogicalVariable oldV = context.getVar(v.getVar().getId());
+		AssignOperator a = new AssignOperator(var,
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(oldV)));
+		a.getInputs().add(tupSource);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitWhereClause(WhereClause w, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(w.getWhereExpr(), tupSource);
-        SelectOperator s = new SelectOperator(new MutableObject<ILogicalExpression>(p.first));
-        s.getInputs().add(p.second);
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitWhereClause(
+			WhereClause w, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+				w.getWhereExpr(), tupSource);
+		SelectOperator s = new SelectOperator(
+				new MutableObject<ILogicalExpression>(p.first));
+		s.getInputs().add(p.second);
 
-        return new Pair<ILogicalOperator, LogicalVariable>(s, null);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(s, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLimitClause(LimitClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getLimitExpr(), tupSource);
-        LimitOperator opLim;
-        Expression offset = lc.getOffset();
-        if (offset != null) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p2 = aqlExprToAlgExpression(offset, p1.second);
-            opLim = new LimitOperator(p1.first, p2.first);
-            opLim.getInputs().add(p2.second);
-        } else {
-            opLim = new LimitOperator(p1.first);
-            opLim.getInputs().add(p1.second);
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(opLim, null);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLimitClause(
+			LimitClause lc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(
+				lc.getLimitExpr(), tupSource);
+		LimitOperator opLim;
+		Expression offset = lc.getOffset();
+		if (offset != null) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p2 = aqlExprToAlgExpression(
+					offset, p1.second);
+			opLim = new LimitOperator(p1.first, p2.first);
+			opLim.getInputs().add(p2.second);
+		} else {
+			opLim = new LimitOperator(p1.first);
+			opLim.getInputs().add(p1.second);
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(opLim, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDieClause(DieClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getDieExpr(), tupSource);
-        DieOperator opDie = new DieOperator(p1.first);
-        opDie.getInputs().add(p1.second);
-        return new Pair<ILogicalOperator, LogicalVariable>(opDie, null);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDieClause(DieClause lc,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(
+				lc.getDieExpr(), tupSource);
+		DieOperator opDie = new DieOperator(p1.first);
+		opDie.getInputs().add(p1.second);
+		return new Pair<ILogicalOperator, LogicalVariable>(opDie, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDistinctClause(DistinctClause dc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
-        Mutable<ILogicalOperator> input = null;
-        for (Expression expr : dc.getDistinctByExpr()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(expr, tupSource);
-            exprList.add(new MutableObject<ILogicalExpression>(p.first));
-            input = p.second;
-        }
-        DistinctOperator opDistinct = new DistinctOperator(exprList);
-        opDistinct.getInputs().add(input);
-        return new Pair<ILogicalOperator, LogicalVariable>(opDistinct, null);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDistinctClause(
+			DistinctClause dc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
+		Mutable<ILogicalOperator> input = null;
+		for (Expression expr : dc.getDistinctByExpr()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+					expr, tupSource);
+			exprList.add(new MutableObject<ILogicalExpression>(p.first));
+			input = p.second;
+		}
+		DistinctOperator opDistinct = new DistinctOperator(exprList);
+		opDistinct.getInputs().add(input);
+		return new Pair<ILogicalOperator, LogicalVariable>(opDistinct, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUnionExpr(UnionExpr unionExpr,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Mutable<ILogicalOperator> ts = tupSource;
-        ILogicalOperator lastOp = null;
-        LogicalVariable lastVar = null;
-        boolean first = true;
-        for (Expression e : unionExpr.getExprs()) {
-            if (first) {
-                first = false;
-            } else {
-                ts = new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator());
-            }
-            Pair<ILogicalOperator, LogicalVariable> p1 = e.accept(this, ts);
-            if (lastOp == null) {
-                lastOp = p1.first;
-                lastVar = p1.second;
-            } else {
-                LogicalVariable unnestVar1 = context.newVar();
-                UnnestOperator unnest1 = new UnnestOperator(unnestVar1, new MutableObject<ILogicalExpression>(
-                        makeUnnestExpression(new VariableReferenceExpression(lastVar))));
-                unnest1.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
-                LogicalVariable unnestVar2 = context.newVar();
-                UnnestOperator unnest2 = new UnnestOperator(unnestVar2, new MutableObject<ILogicalExpression>(
-                        makeUnnestExpression(new VariableReferenceExpression(p1.second))));
-                unnest2.getInputs().add(new MutableObject<ILogicalOperator>(p1.first));
-                List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(
-                        1);
-                LogicalVariable resultVar = context.newVar();
-                Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
-                        unnestVar1, unnestVar2, resultVar);
-                varMap.add(triple);
-                UnionAllOperator unionOp = new UnionAllOperator(varMap);
-                unionOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest1));
-                unionOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest2));
-                lastVar = resultVar;
-                lastOp = unionOp;
-            }
-        }
-        LogicalVariable aggVar = context.newVar();
-        ArrayList<LogicalVariable> aggregVars = new ArrayList<LogicalVariable>(1);
-        aggregVars.add(aggVar);
-        List<Mutable<ILogicalExpression>> afcExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
-        afcExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(lastVar)));
-        AggregateFunctionCallExpression afc = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
-                AsterixBuiltinFunctions.LISTIFY, afcExprs);
-        ArrayList<Mutable<ILogicalExpression>> aggregExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
-        aggregExprs.add(new MutableObject<ILogicalExpression>(afc));
-        AggregateOperator agg = new AggregateOperator(aggregVars, aggregExprs);
-        agg.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
-        return new Pair<ILogicalOperator, LogicalVariable>(agg, aggVar);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUnionExpr(
+			UnionExpr unionExpr, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Mutable<ILogicalOperator> ts = tupSource;
+		ILogicalOperator lastOp = null;
+		LogicalVariable lastVar = null;
+		boolean first = true;
+		for (Expression e : unionExpr.getExprs()) {
+			if (first) {
+				first = false;
+			} else {
+				ts = new MutableObject<ILogicalOperator>(
+						new EmptyTupleSourceOperator());
+			}
+			Pair<ILogicalOperator, LogicalVariable> p1 = e.accept(this, ts);
+			if (lastOp == null) {
+				lastOp = p1.first;
+				lastVar = p1.second;
+			} else {
+				LogicalVariable unnestVar1 = context.newVar();
+				UnnestOperator unnest1 = new UnnestOperator(
+						unnestVar1,
+						new MutableObject<ILogicalExpression>(
+								makeUnnestExpression(new VariableReferenceExpression(
+										lastVar))));
+				unnest1.getInputs().add(
+						new MutableObject<ILogicalOperator>(lastOp));
+				LogicalVariable unnestVar2 = context.newVar();
+				UnnestOperator unnest2 = new UnnestOperator(
+						unnestVar2,
+						new MutableObject<ILogicalExpression>(
+								makeUnnestExpression(new VariableReferenceExpression(
+										p1.second))));
+				unnest2.getInputs().add(
+						new MutableObject<ILogicalOperator>(p1.first));
+				List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(
+						1);
+				LogicalVariable resultVar = context.newVar();
+				Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
+						unnestVar1, unnestVar2, resultVar);
+				varMap.add(triple);
+				UnionAllOperator unionOp = new UnionAllOperator(varMap);
+				unionOp.getInputs().add(
+						new MutableObject<ILogicalOperator>(unnest1));
+				unionOp.getInputs().add(
+						new MutableObject<ILogicalOperator>(unnest2));
+				lastVar = resultVar;
+				lastOp = unionOp;
+			}
+		}
+		LogicalVariable aggVar = context.newVar();
+		ArrayList<LogicalVariable> aggregVars = new ArrayList<LogicalVariable>(
+				1);
+		aggregVars.add(aggVar);
+		List<Mutable<ILogicalExpression>> afcExprs = new ArrayList<Mutable<ILogicalExpression>>(
+				1);
+		afcExprs.add(new MutableObject<ILogicalExpression>(
+				new VariableReferenceExpression(lastVar)));
+		AggregateFunctionCallExpression afc = AsterixBuiltinFunctions
+				.makeAggregateFunctionExpression(
+						AsterixBuiltinFunctions.LISTIFY, afcExprs);
+		ArrayList<Mutable<ILogicalExpression>> aggregExprs = new ArrayList<Mutable<ILogicalExpression>>(
+				1);
+		aggregExprs.add(new MutableObject<ILogicalExpression>(afc));
+		AggregateOperator agg = new AggregateOperator(aggregVars, aggregExprs);
+		agg.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
+		return new Pair<ILogicalOperator, LogicalVariable>(agg, aggVar);
+	}
 
-    private AbstractFunctionCallExpression createComparisonExpression(OperatorType t) {
-        FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
-        IFunctionInfo finfo = FunctionUtils.getFunctionInfo(fi);
-        return new ScalarFunctionCallExpression(finfo);
-    }
+	private AbstractFunctionCallExpression createComparisonExpression(
+			OperatorType t) {
+		FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
+		IFunctionInfo finfo = FunctionUtils.getFunctionInfo(fi);
+		return new ScalarFunctionCallExpression(finfo);
+	}
 
-    private FunctionIdentifier operatorTypeToFunctionIdentifier(OperatorType t) {
-        switch (t) {
-            case EQ: {
-                return AlgebricksBuiltinFunctions.EQ;
-            }
-            case NEQ: {
-                return AlgebricksBuiltinFunctions.NEQ;
-            }
-            case GT: {
-                return AlgebricksBuiltinFunctions.GT;
-            }
-            case GE: {
-                return AlgebricksBuiltinFunctions.GE;
-            }
-            case LT: {
-                return AlgebricksBuiltinFunctions.LT;
-            }
-            case LE: {
-                return AlgebricksBuiltinFunctions.LE;
-            }
-            default: {
-                throw new IllegalStateException();
-            }
-        }
-    }
+	private FunctionIdentifier operatorTypeToFunctionIdentifier(OperatorType t) {
+		switch (t) {
+		case EQ: {
+			return AlgebricksBuiltinFunctions.EQ;
+		}
+		case NEQ: {
+			return AlgebricksBuiltinFunctions.NEQ;
+		}
+		case GT: {
+			return AlgebricksBuiltinFunctions.GT;
+		}
+		case GE: {
+			return AlgebricksBuiltinFunctions.GE;
+		}
+		case LT: {
+			return AlgebricksBuiltinFunctions.LT;
+		}
+		case LE: {
+			return AlgebricksBuiltinFunctions.LE;
+		}
+		default: {
+			throw new IllegalStateException();
+		}
+		}
+	}
 
-    private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(OperatorType t)
-            throws AsterixException {
+	private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(
+			OperatorType t) throws AsterixException {
 
-        FunctionIdentifier fid = null;
-        switch (t) {
-            case PLUS: {
-                fid = AlgebricksBuiltinFunctions.NUMERIC_ADD;
-                break;
-            }
-            case MINUS: {
-                fid = AsterixBuiltinFunctions.NUMERIC_SUBTRACT;
-                break;
-            }
-            case MUL: {
-                fid = AsterixBuiltinFunctions.NUMERIC_MULTIPLY;
-                break;
-            }
-            case DIV: {
-                fid = AsterixBuiltinFunctions.NUMERIC_DIVIDE;
-                break;
-            }
-            case MOD: {
-                fid = AsterixBuiltinFunctions.NUMERIC_MOD;
-                break;
-            }
-            case IDIV: {
-                fid = AsterixBuiltinFunctions.NUMERIC_IDIV;
-                break;
-            }
-            case CARET: {
-                fid = AsterixBuiltinFunctions.CARET;
-                break;
-            }
-            case AND: {
-                fid = AlgebricksBuiltinFunctions.AND;
-                break;
-            }
-            case OR: {
-                fid = AlgebricksBuiltinFunctions.OR;
-                break;
-            }
-            case FUZZY_EQ: {
-                fid = AsterixBuiltinFunctions.FUZZY_EQ;
-                break;
-            }
+		FunctionIdentifier fid = null;
+		switch (t) {
+		case PLUS: {
+			fid = AlgebricksBuiltinFunctions.NUMERIC_ADD;
+			break;
+		}
+		case MINUS: {
+			fid = AsterixBuiltinFunctions.NUMERIC_SUBTRACT;
+			break;
+		}
+		case MUL: {
+			fid = AsterixBuiltinFunctions.NUMERIC_MULTIPLY;
+			break;
+		}
+		case DIV: {
+			fid = AsterixBuiltinFunctions.NUMERIC_DIVIDE;
+			break;
+		}
+		case MOD: {
+			fid = AsterixBuiltinFunctions.NUMERIC_MOD;
+			break;
+		}
+		case IDIV: {
+			fid = AsterixBuiltinFunctions.NUMERIC_IDIV;
+			break;
+		}
+		case CARET: {
+			fid = AsterixBuiltinFunctions.CARET;
+			break;
+		}
+		case AND: {
+			fid = AlgebricksBuiltinFunctions.AND;
+			break;
+		}
+		case OR: {
+			fid = AlgebricksBuiltinFunctions.OR;
+			break;
+		}
+		case FUZZY_EQ: {
+			fid = AsterixBuiltinFunctions.FUZZY_EQ;
+			break;
+		}
 
-            default: {
-                throw new NotImplementedException("Operator " + t + " is not yet implemented");
-            }
-        }
-        return new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fid));
-    }
+		default: {
+			throw new NotImplementedException("Operator " + t
+					+ " is not yet implemented");
+		}
+		}
+		return new ScalarFunctionCallExpression(
+				FunctionUtils.getFunctionInfo(fid));
+	}
 
-    private static boolean hasOnlyChild(ILogicalOperator parent, Mutable<ILogicalOperator> childCandidate) {
-        List<Mutable<ILogicalOperator>> inp = parent.getInputs();
-        if (inp == null || inp.size() != 1) {
-            return false;
-        }
-        return inp.get(0) == childCandidate;
-    }
+	private static boolean hasOnlyChild(ILogicalOperator parent,
+			Mutable<ILogicalOperator> childCandidate) {
+		List<Mutable<ILogicalOperator>> inp = parent.getInputs();
+		if (inp == null || inp.size() != 1) {
+			return false;
+		}
+		return inp.get(0) == childCandidate;
+	}
 
-    private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(Expression expr,
-            Mutable<ILogicalOperator> topOp) throws AsterixException {
-        switch (expr.getKind()) {
-            case VARIABLE_EXPRESSION: {
-                VariableReferenceExpression ve = new VariableReferenceExpression(context.getVar(((VariableExpr) expr)
-                        .getVar().getId()));
-                return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve, topOp);
-            }
-            case LITERAL_EXPRESSION: {
-                LiteralExpr val = (LiteralExpr) expr;
-                return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new ConstantExpression(
-                        new AsterixConstantValue(ConstantHelper.objectFromLiteral(val.getValue()))), topOp);
-            }
-            default: {
-                // Mutable<ILogicalOperator> src = new
-                // Mutable<ILogicalOperator>();
-                // Mutable<ILogicalOperator> src = topOp;
-                if (expressionNeedsNoNesting(expr)) {
-                    Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, topOp);
-                    ILogicalExpression exp = ((AssignOperator) p.first).getExpressions().get(0).getValue();
-                    return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(exp, p.first.getInputs().get(0));
-                } else {
-                    Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>();
+	private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(
+			Expression expr, Mutable<ILogicalOperator> topOp)
+			throws AsterixException {
+		switch (expr.getKind()) {
+		case VARIABLE_EXPRESSION: {
+			VariableReferenceExpression ve = new VariableReferenceExpression(
+					context.getVar(((VariableExpr) expr).getVar().getId()));
+			return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve,
+					topOp);
+		}
+		case LITERAL_EXPRESSION: {
+			LiteralExpr val = (LiteralExpr) expr;
+			return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
+					new ConstantExpression(new AsterixConstantValue(
+							ConstantHelper.objectFromLiteral(val.getValue()))),
+					topOp);
+		}
+		default: {
+			// Mutable<ILogicalOperator> src = new
+			// Mutable<ILogicalOperator>();
+			// Mutable<ILogicalOperator> src = topOp;
+			if (expressionNeedsNoNesting(expr)) {
+				Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
+						topOp);
+				ILogicalExpression exp = ((AssignOperator) p.first)
+						.getExpressions().get(0).getValue();
+				return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
+						exp, p.first.getInputs().get(0));
+			} else {
+				Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>();
 
-                    Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, src);
+				Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
+						src);
 
-                    if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
-                        // src.setOperator(topOp.getOperator());
-                        Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(p.first);
-                        return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new VariableReferenceExpression(
-                                p.second), top2);
-                    } else {
-                        SubplanOperator s = new SubplanOperator();
-                        s.getInputs().add(topOp);
-                        src.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
-                        Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(p.first);
-                        s.setRootOp(planRoot);
-                        return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new VariableReferenceExpression(
-                                p.second), new MutableObject<ILogicalOperator>(s));
-                    }
-                }
-            }
-        }
+				if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
+					// src.setOperator(topOp.getOperator());
+					Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(
+							p.first);
+					return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
+							new VariableReferenceExpression(p.second), top2);
+				} else {
+					SubplanOperator s = new SubplanOperator();
+					s.getInputs().add(topOp);
+					src.setValue(new NestedTupleSourceOperator(
+							new MutableObject<ILogicalOperator>(s)));
+					Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(
+							p.first);
+					s.setRootOp(planRoot);
+					return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
+							new VariableReferenceExpression(p.second),
+							new MutableObject<ILogicalOperator>(s));
+				}
+			}
+		}
+		}
 
-    }
+	}
 
-    private Pair<ILogicalOperator, LogicalVariable> produceFlwrResult(boolean noForClause, boolean isTop,
-            Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
-        if (isTop) {
-            ProjectOperator pr = new ProjectOperator(resVar);
-            pr.getInputs().add(resOpRef);
-            return new Pair<ILogicalOperator, LogicalVariable>(pr, resVar);
+	private Pair<ILogicalOperator, LogicalVariable> produceFlwrResult(
+			boolean noForClause, boolean isTop,
+			Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
+		if (isTop) {
+			ProjectOperator pr = new ProjectOperator(resVar);
+			pr.getInputs().add(resOpRef);
+			return new Pair<ILogicalOperator, LogicalVariable>(pr, resVar);
 
-        } else if (noForClause) {
-            return new Pair<ILogicalOperator, LogicalVariable>(resOpRef.getValue(), resVar);
-        } else {
-            return aggListify(resVar, resOpRef, false);
-        }
-    }
+		} else if (noForClause) {
+			return new Pair<ILogicalOperator, LogicalVariable>(
+					resOpRef.getValue(), resVar);
+		} else {
+			return aggListify(resVar, resOpRef, false);
+		}
+	}
 
-    private Pair<ILogicalOperator, LogicalVariable> aggListify(LogicalVariable var, Mutable<ILogicalOperator> opRef,
-            boolean bProject) {
-        AggregateFunctionCallExpression funAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
-                AsterixBuiltinFunctions.LISTIFY, new ArrayList<Mutable<ILogicalExpression>>());
-        funAgg.getArguments().add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
-        LogicalVariable varListified = context.newVar();
-        AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(varListified),
-                (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(funAgg)));
-        agg.getInputs().add(opRef);
-        ILogicalOperator res;
-        if (bProject) {
-            ProjectOperator pr = new ProjectOperator(varListified);
-            pr.getInputs().add(new MutableObject<ILogicalOperator>(agg));
-            res = pr;
-        } else {
-            res = agg;
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(res, varListified);
-    }
+	private Pair<ILogicalOperator, LogicalVariable> aggListify(
+			LogicalVariable var, Mutable<ILogicalOperator> opRef,
+			boolean bProject) {
+		AggregateFunctionCallExpression funAgg = AsterixBuiltinFunctions
+				.makeAggregateFunctionExpression(
+						AsterixBuiltinFunctions.LISTIFY,
+						new ArrayList<Mutable<ILogicalExpression>>());
+		funAgg.getArguments().add(
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(var)));
+		LogicalVariable varListified = context.newVar();
+		AggregateOperator agg = new AggregateOperator(
+				mkSingletonArrayList(varListified),
+				(List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
+						funAgg)));
+		agg.getInputs().add(opRef);
+		ILogicalOperator res;
+		if (bProject) {
+			ProjectOperator pr = new ProjectOperator(varListified);
+			pr.getInputs().add(new MutableObject<ILogicalOperator>(agg));
+			res = pr;
+		} else {
+			res = agg;
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(res, varListified);
+	}
 
-    private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(OperatorExpr op,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        ArrayList<OperatorType> ops = op.getOpList();
-        int nOps = ops.size();
+	private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(
+			OperatorExpr op, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		ArrayList<OperatorType> ops = op.getOpList();
+		int nOps = ops.size();
 
-        ArrayList<Expression> exprs = op.getExprList();
+		ArrayList<Expression> exprs = op.getExprList();
 
-        Mutable<ILogicalOperator> topOp = tupSource;
+		Mutable<ILogicalOperator> topOp = tupSource;
 
-        OperatorType opLogical = ops.get(0);
-        AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
+		OperatorType opLogical = ops.get(0);
+		AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
 
-        for (int i = 0; i <= nOps; i++) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(exprs.get(i), topOp);
-            topOp = p.second;
-            // now look at the operator
-            if (i < nOps) {
-                if (ops.get(i) != opLogical) {
-                    throw new TranslationException("Unexpected operator " + ops.get(i)
-                            + " in an OperatorExpr starting with " + opLogical);
-                }
-            }
-            f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
-        }
+		for (int i = 0; i <= nOps; i++) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+					exprs.get(i), topOp);
+			topOp = p.second;
+			// now look at the operator
+			if (i < nOps) {
+				if (ops.get(i) != opLogical) {
+					throw new TranslationException("Unexpected operator "
+							+ ops.get(i) + " in an OperatorExpr starting with "
+							+ opLogical);
+				}
+			}
+			f.getArguments()
+					.add(new MutableObject<ILogicalExpression>(p.first));
+		}
 
-        LogicalVariable assignedVar = context.newVar();
-        AssignOperator a = new AssignOperator(assignedVar, new MutableObject<ILogicalExpression>(f));
-        a.getInputs().add(topOp);
+		LogicalVariable assignedVar = context.newVar();
+		AssignOperator a = new AssignOperator(assignedVar,
+				new MutableObject<ILogicalExpression>(f));
+		a.getInputs().add(topOp);
 
-        return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
 
-    }
+	}
 
-    private static boolean expressionNeedsNoNesting(Expression expr) {
-        Kind k = expr.getKind();
-        return k == Kind.LITERAL_EXPRESSION || k == Kind.LIST_CONSTRUCTOR_EXPRESSION
-                || k == Kind.RECORD_CONSTRUCTOR_EXPRESSION || k == Kind.VARIABLE_EXPRESSION
-                || k == Kind.CALL_EXPRESSION || k == Kind.OP_EXPRESSION || k == Kind.FIELD_ACCESSOR_EXPRESSION
-                || k == Kind.INDEX_ACCESSOR_EXPRESSION || k == Kind.UNARY_EXPRESSION;
-    }
+	private static boolean expressionNeedsNoNesting(Expression expr) {
+		Kind k = expr.getKind();
+		return k == Kind.LITERAL_EXPRESSION
+				|| k == Kind.LIST_CONSTRUCTOR_EXPRESSION
+				|| k == Kind.RECORD_CONSTRUCTOR_EXPRESSION
+				|| k == Kind.VARIABLE_EXPRESSION || k == Kind.CALL_EXPRESSION
+				|| k == Kind.OP_EXPRESSION
+				|| k == Kind.FIELD_ACCESSOR_EXPRESSION
+				|| k == Kind.INDEX_ACCESSOR_EXPRESSION
+				|| k == Kind.UNARY_EXPRESSION;
+	}
 
-    private <T> ArrayList<T> mkSingletonArrayList(T item) {
-        ArrayList<T> array = new ArrayList<T>(1);
-        array.add(item);
-        return array;
-    }
+	private <T> ArrayList<T> mkSingletonArrayList(T item) {
+		ArrayList<T> array = new ArrayList<T>(1);
+		array.add(item);
+		return array;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitTypeDecl(TypeDecl td, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitTypeDecl(TypeDecl td,
+			Mutable<ILogicalOperator> arg) throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitRecordTypeDefiniton(RecordTypeDefinition tre,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitRecordTypeDefiniton(
+			RecordTypeDefinition tre, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitTypeReferenceExpression(TypeReferenceExpression tre,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitTypeReferenceExpression(
+			TypeReferenceExpression tre, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitNodegroupDecl(NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitNodegroupDecl(
+			NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLoadFromFileStatement(LoadFromFileStatement stmtLoad,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLoadFromFileStatement(
+			LoadFromFileStatement stmtLoad, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitWriteFromQueryResultStatement(
-            WriteFromQueryResultStatement stmtLoad, Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitWriteFromQueryResultStatement(
+			WriteFromQueryResultStatement stmtLoad,
+			Mutable<ILogicalOperator> arg) throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDropStatement(DropStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDropStatement(
+			DropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitControlFeedStatement(ControlFeedStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitControlFeedStatement(
+			ControlFeedStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitCreateIndexStatement(CreateIndexStatement cis,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitCreateIndexStatement(
+			CreateIndexStatement cis, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitOrderedListTypeDefiniton(OrderedListTypeDefinition olte,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitOrderedListTypeDefiniton(
+			OrderedListTypeDefinition olte, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUnorderedListTypeDefiniton(UnorderedListTypeDefinition ulte,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUnorderedListTypeDefiniton(
+			UnorderedListTypeDefinition ulte, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    private ILogicalExpression makeUnnestExpression(ILogicalExpression expr) {
-        switch (expr.getExpressionTag()) {
-            case VARIABLE: {
-                return new UnnestingFunctionCallExpression(
-                        FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
-                        new MutableObject<ILogicalExpression>(expr));
-            }
-            case FUNCTION_CALL: {
-                AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
-                if (fce.getKind() == FunctionKind.UNNEST) {
-                    return expr;
-                } else {
-                    return new UnnestingFunctionCallExpression(
-                            FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
-                            new MutableObject<ILogicalExpression>(expr));
-                }
-            }
-            default: {
-                return expr;
-            }
-        }
-    }
+	private ILogicalExpression makeUnnestExpression(ILogicalExpression expr) {
+		switch (expr.getExpressionTag()) {
+		case VARIABLE: {
+			return new UnnestingFunctionCallExpression(
+					FunctionUtils
+							.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
+					new MutableObject<ILogicalExpression>(expr));
+		}
+		case FUNCTION_CALL: {
+			AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
+			if (fce.getKind() == FunctionKind.UNNEST) {
+				return expr;
+			} else {
+				return new UnnestingFunctionCallExpression(
+						FunctionUtils
+								.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
+						new MutableObject<ILogicalExpression>(expr));
+			}
+		}
+		default: {
+			return expr;
+		}
+		}
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitInsertStatement(InsertStatement insert,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitInsertStatement(
+			InsertStatement insert, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDeleteStatement(DeleteStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDeleteStatement(
+			DeleteStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUpdateStatement(UpdateStatement update,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUpdateStatement(
+			UpdateStatement update, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUpdateClause(UpdateClause del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUpdateClause(
+			UpdateClause del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDataverseDecl(DataverseDecl dv, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDataverseDecl(
+			DataverseDecl dv, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDatasetDecl(DatasetDecl dd, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDatasetDecl(
+			DatasetDecl dd, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitSetStatement(SetStatement ss, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitSetStatement(
+			SetStatement ss, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitWriteStatement(WriteStatement ws, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitWriteStatement(
+			WriteStatement ws, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLoadFromQueryResultStatement(
-            WriteFromQueryResultStatement stmtLoad, Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLoadFromQueryResultStatement(
+			WriteFromQueryResultStatement stmtLoad,
+			Mutable<ILogicalOperator> arg) throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitCreateDataverseStatement(CreateDataverseStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitCreateDataverseStatement(
+			CreateDataverseStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitIndexDropStatement(IndexDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitIndexDropStatement(
+			IndexDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitNodeGroupDropStatement(NodeGroupDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitNodeGroupDropStatement(
+			NodeGroupDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDataverseDropStatement(DataverseDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDataverseDropStatement(
+			DataverseDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitTypeDropStatement(TypeDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitTypeDropStatement(
+			TypeDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visit(CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visit(
+			CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitFunctionDropStatement(FunctionDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitFunctionDropStatement(
+			FunctionDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitBeginFeedStatement(BeginFeedStatement bf,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitBeginFeedStatement(
+			BeginFeedStatement bf, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
index d8f294d..4fc1fc8 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
@@ -148,1327 +148,1581 @@
  * Each visit returns a pair of an operator and a variable. The variable
  * corresponds to the new column, if any, added to the tuple flow. E.g., for
  * Unnest, the column is the variable bound to the elements in the list, for
- * Subplan it is null.
- * The first argument of a visit method is the expression which is translated.
- * The second argument of a visit method is the tuple source for the current
- * subtree.
+ * Subplan it is null. The first argument of a visit method is the expression
+ * which is translated. The second argument of a visit method is the tuple
+ * source for the current subtree.
  */
 
-public class AqlPlusExpressionToPlanTranslator extends AbstractAqlTranslator implements
-        IAqlPlusExpressionVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
+public class AqlPlusExpressionToPlanTranslator extends AbstractAqlTranslator
+		implements
+		IAqlPlusExpressionVisitor<Pair<ILogicalOperator, LogicalVariable>, Mutable<ILogicalOperator>> {
 
-    private static final Logger LOGGER = Logger.getLogger(AqlPlusExpressionToPlanTranslator.class.getName());
+	private static final Logger LOGGER = Logger
+			.getLogger(AqlPlusExpressionToPlanTranslator.class.getName());
 
-    private class MetaScopeLogicalVariable {
-        private HashMap<Identifier, LogicalVariable> map = new HashMap<Identifier, LogicalVariable>();
+	private class MetaScopeLogicalVariable {
+		private HashMap<Identifier, LogicalVariable> map = new HashMap<Identifier, LogicalVariable>();
 
-        public VariableReferenceExpression getVariableReferenceExpression(Identifier id) throws AsterixException {
-            LogicalVariable var = map.get(id);
-            LOGGER.fine("get:" + id + ":" + var);
-            if (var == null) {
-                throw new AsterixException("Identifier " + id + " not found in AQL+ meta-scope.");
-            }
-            return new VariableReferenceExpression(var);
-        }
+		public VariableReferenceExpression getVariableReferenceExpression(
+				Identifier id) throws AsterixException {
+			LogicalVariable var = map.get(id);
+			LOGGER.fine("get:" + id + ":" + var);
+			if (var == null) {
+				throw new AsterixException("Identifier " + id
+						+ " not found in AQL+ meta-scope.");
+			}
+			return new VariableReferenceExpression(var);
+		}
 
-        public void put(Identifier id, LogicalVariable var) {
-            LOGGER.fine("put:" + id + ":" + var);
-            map.put(id, var);
-        }
-    }
+		public void put(Identifier id, LogicalVariable var) {
+			LOGGER.fine("put:" + id + ":" + var);
+			map.put(id, var);
+		}
+	}
 
-    private class MetaScopeILogicalOperator {
-        private HashMap<Identifier, ILogicalOperator> map = new HashMap<Identifier, ILogicalOperator>();
+	private class MetaScopeILogicalOperator {
+		private HashMap<Identifier, ILogicalOperator> map = new HashMap<Identifier, ILogicalOperator>();
 
-        public ILogicalOperator get(Identifier id) throws AsterixException {
-            ILogicalOperator op = map.get(id);
-            if (op == null) {
-                throw new AsterixException("Identifier " + id + " not found in AQL+ meta-scope.");
-            }
-            return op;
-        }
+		public ILogicalOperator get(Identifier id) throws AsterixException {
+			ILogicalOperator op = map.get(id);
+			if (op == null) {
+				throw new AsterixException("Identifier " + id
+						+ " not found in AQL+ meta-scope.");
+			}
+			return op;
+		}
 
-        public void put(Identifier id, ILogicalOperator op) {
-            LOGGER.fine("put:" + id + ":" + op);
-            map.put(id, op);
-        }
-    }
+		public void put(Identifier id, ILogicalOperator op) {
+			LOGGER.fine("put:" + id + ":" + op);
+			map.put(id, op);
+		}
+	}
 
-    private final long txnId;
-    private final MetadataTransactionContext mdTxnCtx;
-    private TranslationContext context;
-    private String outputDatasetName;
-    private MetaScopeLogicalVariable metaScopeExp = new MetaScopeLogicalVariable();
-    private MetaScopeILogicalOperator metaScopeOp = new MetaScopeILogicalOperator();
-    private static LogicalVariable METADATA_DUMMY_VAR = new LogicalVariable(-1);
+	private final long txnId;
+	private final MetadataTransactionContext mdTxnCtx;
+	private TranslationContext context;
+	private String outputDatasetName;
+	private MetaScopeLogicalVariable metaScopeExp = new MetaScopeLogicalVariable();
+	private MetaScopeILogicalOperator metaScopeOp = new MetaScopeILogicalOperator();
+	private static LogicalVariable METADATA_DUMMY_VAR = new LogicalVariable(-1);
 
-    public AqlPlusExpressionToPlanTranslator(long txnId, MetadataTransactionContext mdTxnCtx,
-            Counter currentVarCounter, String outputDatasetName) {
-        this.txnId = txnId;
-        this.mdTxnCtx = mdTxnCtx;
-        this.context = new TranslationContext(currentVarCounter);
-        this.outputDatasetName = outputDatasetName;
-        this.context.setTopFlwor(false);
-    }
+	public AqlPlusExpressionToPlanTranslator(long txnId,
+			MetadataTransactionContext mdTxnCtx, Counter currentVarCounter,
+			String outputDatasetName) {
+		this.txnId = txnId;
+		this.mdTxnCtx = mdTxnCtx;
+		this.context = new TranslationContext(currentVarCounter);
+		this.outputDatasetName = outputDatasetName;
+		this.context.setTopFlwor(false);
+	}
 
-    public int getVarCounter() {
-        return context.getVarCounter();
-    }
+	public int getVarCounter() {
+		return context.getVarCounter();
+	}
 
-    public ILogicalPlanAndMetadata translate(Query expr) throws AlgebricksException, AsterixException {
-        return translate(expr, null);
-    }
+	public ILogicalPlanAndMetadata translate(Query expr)
+			throws AlgebricksException, AsterixException {
+		return translate(expr, null);
+	}
 
-    public ILogicalPlanAndMetadata translate(Query expr, AqlCompiledMetadataDeclarations compiledDeclarations)
-            throws AlgebricksException, AsterixException {
-        if (expr == null) {
-            return null;
-        }
-        if (compiledDeclarations == null) {
-            compiledDeclarations = compileMetadata(mdTxnCtx, expr.getPrologDeclList(), true);
-        }
-        if (!compiledDeclarations.isConnectedToDataverse())
-            compiledDeclarations.connectToDataverse(compiledDeclarations.getDataverseName());
-        IDataFormat format = compiledDeclarations.getFormat();
-        if (format == null) {
-            throw new AlgebricksException("Data format has not been set.");
-        }
-        format.registerRuntimeFunctions();
-        Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, new MutableObject<ILogicalOperator>(
-                new EmptyTupleSourceOperator()));
+	public ILogicalPlanAndMetadata translate(Query expr,
+			AqlCompiledMetadataDeclarations compiledDeclarations)
+			throws AlgebricksException, AsterixException {
+		if (expr == null) {
+			return null;
+		}
+		if (compiledDeclarations == null) {
+			compiledDeclarations = compileMetadata(mdTxnCtx,
+					expr.getPrologDeclList(), true);
+		}
+		if (!compiledDeclarations.isConnectedToDataverse())
+			compiledDeclarations.connectToDataverse(compiledDeclarations
+					.getDataverseName());
+		IDataFormat format = compiledDeclarations.getFormat();
+		if (format == null) {
+			throw new AlgebricksException("Data format has not been set.");
+		}
+		format.registerRuntimeFunctions();
+		Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
+				new MutableObject<ILogicalOperator>(
+						new EmptyTupleSourceOperator()));
 
-        ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
+		ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
 
-        boolean isTransactionalWrite = false;
-        ILogicalOperator topOp = p.first;
-        ProjectOperator project = (ProjectOperator) topOp;
-        LogicalVariable resVar = project.getVariables().get(0);
-        if (outputDatasetName == null) {
-            List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(1);
-            writeExprList.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(resVar)));
-            FileSplitSinkId fssi = new FileSplitSinkId(compiledDeclarations.getOutputFile());
-            FileSplitDataSink sink = new FileSplitDataSink(fssi, null);
-            topOp = new WriteOperator(writeExprList, sink);
-            topOp.getInputs().add(new MutableObject<ILogicalOperator>(project));
-        } else {
-            Dataset dataset = compiledDeclarations.findDataset(outputDatasetName);
-            if (dataset == null) {
-                throw new AlgebricksException("Cannot find dataset " + outputDatasetName);
-            }
-            if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
-                throw new AlgebricksException("Cannot write output to an external dataset.");
-            }
-            ARecordType itemType = (ARecordType) compiledDeclarations.findType(dataset.getItemTypeName());
-            List<String> partitioningKeys = DatasetUtils.getPartitioningKeys(dataset);
-            ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>();
-            ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
-            List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>();
-            for (String partitioningKey : partitioningKeys) {
-                Triple<ICopyEvaluatorFactory, ScalarFunctionCallExpression, IAType> partitioner = format
-                        .partitioningEvaluatorFactory(itemType, partitioningKey);
-                AbstractFunctionCallExpression f = partitioner.second.cloneExpression();
-                f.substituteVar(METADATA_DUMMY_VAR, resVar);
-                exprs.add(new MutableObject<ILogicalExpression>(f));
-                LogicalVariable v = context.newVar();
-                vars.add(v);
-                varRefsForLoading.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v)));
-            }
-            AssignOperator assign = new AssignOperator(vars, exprs);
-            assign.getInputs().add(new MutableObject<ILogicalOperator>(project));
-        }
+		boolean isTransactionalWrite = false;
+		ILogicalOperator topOp = p.first;
+		ProjectOperator project = (ProjectOperator) topOp;
+		LogicalVariable resVar = project.getVariables().get(0);
+		if (outputDatasetName == null) {
+			List<Mutable<ILogicalExpression>> writeExprList = new ArrayList<Mutable<ILogicalExpression>>(
+					1);
+			writeExprList.add(new MutableObject<ILogicalExpression>(
+					new VariableReferenceExpression(resVar)));
+			FileSplitSinkId fssi = new FileSplitSinkId(
+					compiledDeclarations.getOutputFile());
+			FileSplitDataSink sink = new FileSplitDataSink(fssi, null);
+			topOp = new WriteOperator(writeExprList, sink);
+			topOp.getInputs().add(new MutableObject<ILogicalOperator>(project));
+		} else {
+			Dataset dataset = compiledDeclarations
+					.findDataset(outputDatasetName);
+			if (dataset == null) {
+				throw new AlgebricksException("Cannot find dataset "
+						+ outputDatasetName);
+			}
+			if (dataset.getDatasetType() == DatasetType.EXTERNAL) {
+				throw new AlgebricksException(
+						"Cannot write output to an external dataset.");
+			}
+			ARecordType itemType = (ARecordType) compiledDeclarations
+					.findType(dataset.getItemTypeName());
+			List<String> partitioningKeys = DatasetUtils
+					.getPartitioningKeys(dataset);
+			ArrayList<LogicalVariable> vars = new ArrayList<LogicalVariable>();
+			ArrayList<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>();
+			List<Mutable<ILogicalExpression>> varRefsForLoading = new ArrayList<Mutable<ILogicalExpression>>();
+			for (String partitioningKey : partitioningKeys) {
+				Triple<ICopyEvaluatorFactory, ScalarFunctionCallExpression, IAType> partitioner = format
+						.partitioningEvaluatorFactory(itemType, partitioningKey);
+				AbstractFunctionCallExpression f = partitioner.second
+						.cloneExpression();
+				f.substituteVar(METADATA_DUMMY_VAR, resVar);
+				exprs.add(new MutableObject<ILogicalExpression>(f));
+				LogicalVariable v = context.newVar();
+				vars.add(v);
+				varRefsForLoading.add(new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(v)));
+			}
+			AssignOperator assign = new AssignOperator(vars, exprs);
+			assign.getInputs()
+					.add(new MutableObject<ILogicalOperator>(project));
+		}
 
-        globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
-        ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
-        AqlMetadataProvider metadataProvider = new AqlMetadataProvider(txnId, isTransactionalWrite,
-                compiledDeclarations);
-        ILogicalPlanAndMetadata planAndMetadata = new AqlLogicalPlanAndMetadataImpl(plan, metadataProvider);
-        return planAndMetadata;
-    }
+		globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
+		ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
+		AqlMetadataProvider metadataProvider = new AqlMetadataProvider(txnId,
+				isTransactionalWrite, compiledDeclarations);
+		ILogicalPlanAndMetadata planAndMetadata = new AqlLogicalPlanAndMetadataImpl(
+				plan, metadataProvider);
+		return planAndMetadata;
+	}
 
-    public ILogicalPlan translate(List<Clause> clauses) throws AlgebricksException, AsterixException {
+	public ILogicalPlan translate(List<Clause> clauses)
+			throws AlgebricksException, AsterixException {
 
-        if (clauses == null) {
-            return null;
-        }
+		if (clauses == null) {
+			return null;
+		}
 
-        Mutable<ILogicalOperator> opRef = new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator());
-        Pair<ILogicalOperator, LogicalVariable> p = null;
-        for (Clause c : clauses) {
-            p = c.accept(this, opRef);
-            opRef = new MutableObject<ILogicalOperator>(p.first);
-        }
+		Mutable<ILogicalOperator> opRef = new MutableObject<ILogicalOperator>(
+				new EmptyTupleSourceOperator());
+		Pair<ILogicalOperator, LogicalVariable> p = null;
+		for (Clause c : clauses) {
+			p = c.accept(this, opRef);
+			opRef = new MutableObject<ILogicalOperator>(p.first);
+		}
 
-        ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
+		ArrayList<Mutable<ILogicalOperator>> globalPlanRoots = new ArrayList<Mutable<ILogicalOperator>>();
 
-        ILogicalOperator topOp = p.first;
+		ILogicalOperator topOp = p.first;
 
-        globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
-        ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
-        return plan;
-    }
+		globalPlanRoots.add(new MutableObject<ILogicalOperator>(topOp));
+		ILogicalPlan plan = new ALogicalPlanImpl(globalPlanRoots);
+		return plan;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitForClause(ForClause fc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        LogicalVariable v = context.newVar(fc.getVarExpr());
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitForClause(ForClause fc,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		LogicalVariable v = context.newVar(fc.getVarExpr());
 
-        Expression inExpr = fc.getInExpr();
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(inExpr, tupSource);
-        ILogicalOperator returnedOp;
+		Expression inExpr = fc.getInExpr();
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+				inExpr, tupSource);
+		ILogicalOperator returnedOp;
 
-        if (fc.getPosVarExpr() == null) {
-            returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)));
-        } else {
-            LogicalVariable pVar = context.newVar(fc.getPosVarExpr());
-            returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)),
-                    pVar, BuiltinType.AINT32);
-        }
-        returnedOp.getInputs().add(eo.second);
+		if (fc.getPosVarExpr() == null) {
+			returnedOp = new UnnestOperator(v,
+					new MutableObject<ILogicalExpression>(
+							makeUnnestExpression(eo.first)));
+		} else {
+			LogicalVariable pVar = context.newVar(fc.getPosVarExpr());
+			returnedOp = new UnnestOperator(v,
+					new MutableObject<ILogicalExpression>(
+							makeUnnestExpression(eo.first)), pVar,
+					BuiltinType.AINT32);
+		}
+		returnedOp.getInputs().add(eo.second);
 
-        return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLetClause(LetClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        LogicalVariable v;
-        ILogicalOperator returnedOp;
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLetClause(LetClause lc,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		LogicalVariable v;
+		ILogicalOperator returnedOp;
 
-        switch (lc.getBindingExpr().getKind()) {
-            case VARIABLE_EXPRESSION: {
-                v = context.newVar(lc.getVarExpr());
-                LogicalVariable prev = context.getVar(((VariableExpr) lc.getBindingExpr()).getVar().getId());
-                returnedOp = new AssignOperator(v, new MutableObject<ILogicalExpression>(
-                        new VariableReferenceExpression(prev)));
-                returnedOp.getInputs().add(tupSource);
-                break;
-            }
-            default: {
-                Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(lc.getBindingExpr(),
-                        tupSource);
-                v = context.newVar(lc.getVarExpr());
-                returnedOp = new AssignOperator(v, new MutableObject<ILogicalExpression>(eo.first));
-                returnedOp.getInputs().add(eo.second);
-                break;
-            }
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
-    }
+		switch (lc.getBindingExpr().getKind()) {
+		case VARIABLE_EXPRESSION: {
+			v = context.newVar(lc.getVarExpr());
+			LogicalVariable prev = context.getVar(((VariableExpr) lc
+					.getBindingExpr()).getVar().getId());
+			returnedOp = new AssignOperator(v,
+					new MutableObject<ILogicalExpression>(
+							new VariableReferenceExpression(prev)));
+			returnedOp.getInputs().add(tupSource);
+			break;
+		}
+		default: {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+					lc.getBindingExpr(), tupSource);
+			v = context.newVar(lc.getVarExpr());
+			returnedOp = new AssignOperator(v,
+					new MutableObject<ILogicalExpression>(eo.first));
+			returnedOp.getInputs().add(eo.second);
+			break;
+		}
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(returnedOp, v);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitFlworExpression(FLWOGRExpression flwor,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Mutable<ILogicalOperator> flworPlan = tupSource;
-        boolean isTop = context.isTopFlwor();
-        if (isTop) {
-            context.setTopFlwor(false);
-        }
-        for (Clause c : flwor.getClauseList()) {
-            Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this, flworPlan);
-            flworPlan = new MutableObject<ILogicalOperator>(pC.first);
-        }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitFlworExpression(
+			FLWOGRExpression flwor, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Mutable<ILogicalOperator> flworPlan = tupSource;
+		boolean isTop = context.isTopFlwor();
+		if (isTop) {
+			context.setTopFlwor(false);
+		}
+		for (Clause c : flwor.getClauseList()) {
+			Pair<ILogicalOperator, LogicalVariable> pC = c.accept(this,
+					flworPlan);
+			flworPlan = new MutableObject<ILogicalOperator>(pC.first);
+		}
 
-        Expression r = flwor.getReturnExpr();
-        boolean noFlworClause = flwor.noForClause();
+		Expression r = flwor.getReturnExpr();
+		boolean noFlworClause = flwor.noForClause();
 
-        if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
-            VariableExpr v = (VariableExpr) r;
-            LogicalVariable var = context.getVar(v.getVar().getId());
+		if (r.getKind() == Kind.VARIABLE_EXPRESSION) {
+			VariableExpr v = (VariableExpr) r;
+			LogicalVariable var = context.getVar(v.getVar().getId());
 
-            return produceFlwrResult(noFlworClause, isTop, flworPlan, var);
+			return produceFlwrResult(noFlworClause, isTop, flworPlan, var);
 
-        } else {
-            Mutable<ILogicalOperator> baseOp = new MutableObject<ILogicalOperator>(flworPlan.getValue());
-            Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this, baseOp);
-            ILogicalOperator rOp = rRes.first;
-            ILogicalOperator resOp;
-            if (expressionNeedsNoNesting(r)) {
-                baseOp.setValue(flworPlan.getValue());
-                resOp = rOp;
-            } else {
-                SubplanOperator s = new SubplanOperator(rOp);
-                s.getInputs().add(flworPlan);
-                resOp = s;
-                baseOp.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
-            }
-            Mutable<ILogicalOperator> resOpRef = new MutableObject<ILogicalOperator>(resOp);
-            return produceFlwrResult(noFlworClause, isTop, resOpRef, rRes.second);
-        }
-    }
+		} else {
+			Mutable<ILogicalOperator> baseOp = new MutableObject<ILogicalOperator>(
+					flworPlan.getValue());
+			Pair<ILogicalOperator, LogicalVariable> rRes = r.accept(this,
+					baseOp);
+			ILogicalOperator rOp = rRes.first;
+			ILogicalOperator resOp;
+			if (expressionNeedsNoNesting(r)) {
+				baseOp.setValue(flworPlan.getValue());
+				resOp = rOp;
+			} else {
+				SubplanOperator s = new SubplanOperator(rOp);
+				s.getInputs().add(flworPlan);
+				resOp = s;
+				baseOp.setValue(new NestedTupleSourceOperator(
+						new MutableObject<ILogicalOperator>(s)));
+			}
+			Mutable<ILogicalOperator> resOpRef = new MutableObject<ILogicalOperator>(
+					resOp);
+			return produceFlwrResult(noFlworClause, isTop, resOpRef,
+					rRes.second);
+		}
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitFieldAccessor(FieldAccessor fa,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(fa.getExpr(), tupSource);
-        LogicalVariable v = context.newVar();
-        AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
-                FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME));
-        fldAccess.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
-        ILogicalExpression faExpr = new ConstantExpression(new AsterixConstantValue(new AString(fa.getIdent()
-                .getValue())));
-        fldAccess.getArguments().add(new MutableObject<ILogicalExpression>(faExpr));
-        AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(fldAccess));
-        a.getInputs().add(p.second);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v);
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitFieldAccessor(
+			FieldAccessor fa, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+				fa.getExpr(), tupSource);
+		LogicalVariable v = context.newVar();
+		AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(
+				FunctionUtils
+						.getFunctionInfo(AsterixBuiltinFunctions.FIELD_ACCESS_BY_NAME));
+		fldAccess.getArguments().add(
+				new MutableObject<ILogicalExpression>(p.first));
+		ILogicalExpression faExpr = new ConstantExpression(
+				new AsterixConstantValue(new AString(fa.getIdent().getValue())));
+		fldAccess.getArguments().add(
+				new MutableObject<ILogicalExpression>(faExpr));
+		AssignOperator a = new AssignOperator(v,
+				new MutableObject<ILogicalExpression>(fldAccess));
+		a.getInputs().add(p.second);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v);
 
-    }
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitIndexAccessor(IndexAccessor ia,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(ia.getExpr(), tupSource);
-        LogicalVariable v = context.newVar();
-        AbstractFunctionCallExpression f;
-        int i = ia.getIndex();
-        if (i == IndexAccessor.ANY) {
-            f = new ScalarFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
-            f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
-        } else {
-            f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
-            f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
-            f.getArguments().add(
-                    new MutableObject<ILogicalExpression>(new ConstantExpression(
-                            new AsterixConstantValue(new AInt32(i)))));
-        }
-        AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
-        a.getInputs().add(p.second);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitIndexAccessor(
+			IndexAccessor ia, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+				ia.getExpr(), tupSource);
+		LogicalVariable v = context.newVar();
+		AbstractFunctionCallExpression f;
+		int i = ia.getIndex();
+		if (i == IndexAccessor.ANY) {
+			f = new ScalarFunctionCallExpression(
+					FunctionUtils
+							.getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
+			f.getArguments()
+					.add(new MutableObject<ILogicalExpression>(p.first));
+		} else {
+			f = new ScalarFunctionCallExpression(
+					FunctionUtils
+							.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
+			f.getArguments()
+					.add(new MutableObject<ILogicalExpression>(p.first));
+			f.getArguments().add(
+					new MutableObject<ILogicalExpression>(
+							new ConstantExpression(new AsterixConstantValue(
+									new AInt32(i)))));
+		}
+		AssignOperator a = new AssignOperator(v,
+				new MutableObject<ILogicalExpression>(f));
+		a.getInputs().add(p.second);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitCallExpr(CallExpr fcall, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        LogicalVariable v = context.newVar();
-        AsterixFunction fid = fcall.getIdent();
-        List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
-        Mutable<ILogicalOperator> topOp = tupSource;
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitCallExpr(
+			CallExpr fcall, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		LogicalVariable v = context.newVar();
+		AsterixFunction fid = fcall.getIdent();
+		List<Mutable<ILogicalExpression>> args = new ArrayList<Mutable<ILogicalExpression>>();
+		Mutable<ILogicalOperator> topOp = tupSource;
 
-        for (Expression expr : fcall.getExprList()) {
-            switch (expr.getKind()) {
-                case VARIABLE_EXPRESSION: {
-                    LogicalVariable var = context.getVar(((VariableExpr) expr).getVar().getId());
-                    args.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
-                    break;
-                }
-                case LITERAL_EXPRESSION: {
-                    LiteralExpr val = (LiteralExpr) expr;
-                    args.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(
-                            ConstantHelper.objectFromLiteral(val.getValue())))));
-                    break;
-                }
-                default: {
-                    Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, topOp);
-                    AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second.getValue();
-                    args.add(new MutableObject<ILogicalExpression>(eo.first));
-                    if (o1 != null && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(o1, topOp))) {
-                        topOp = eo.second;
-                    }
-                    break;
-                }
-            }
-        }
+		for (Expression expr : fcall.getExprList()) {
+			switch (expr.getKind()) {
+			case VARIABLE_EXPRESSION: {
+				LogicalVariable var = context.getVar(((VariableExpr) expr)
+						.getVar().getId());
+				args.add(new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(var)));
+				break;
+			}
+			case LITERAL_EXPRESSION: {
+				LiteralExpr val = (LiteralExpr) expr;
+				args.add(new MutableObject<ILogicalExpression>(
+						new ConstantExpression(
+								new AsterixConstantValue(ConstantHelper
+										.objectFromLiteral(val.getValue())))));
+				break;
+			}
+			default: {
+				Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+						expr, topOp);
+				AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second
+						.getValue();
+				args.add(new MutableObject<ILogicalExpression>(eo.first));
+				if (o1 != null
+						&& !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(
+								o1, topOp))) {
+					topOp = eo.second;
+				}
+				break;
+			}
+			}
+		}
 
-        FunctionIdentifier fi = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS, fid.getFunctionName(),
-                false);
-        AsterixFunctionInfo afi = AsterixBuiltinFunctions.lookupFunction(fi);
-        FunctionIdentifier builtinAquafi = afi == null ? null : afi.getFunctionIdentifier();
+		FunctionIdentifier fi = new FunctionIdentifier(
+				AlgebricksBuiltinFunctions.ALGEBRICKS_NS, fid.getFunctionName());
+		AsterixFunctionInfo afi = AsterixBuiltinFunctions.lookupFunction(fi);
+		FunctionIdentifier builtinAquafi = afi == null ? null : afi
+				.getFunctionIdentifier();
 
-        if (builtinAquafi != null) {
-            fi = builtinAquafi;
-        } else {
-            fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, fid.getFunctionName(), false);
-            FunctionIdentifier builtinAsterixFi = AsterixBuiltinFunctions.getBuiltinFunctionIdentifier(fi);
-            if (builtinAsterixFi != null) {
-                fi = builtinAsterixFi;
-            }
-        }
-        AbstractFunctionCallExpression f;
-        if (AsterixBuiltinFunctions.isBuiltinAggregateFunction(fi)) {
-            f = AsterixBuiltinFunctions.makeAggregateFunctionExpression(fi, args);
-        } else if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(fi)) {
-            UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(fi), args);
-            ufce.setReturnsUniqueValues(AsterixBuiltinFunctions.returnsUniqueValues(fi));
-            f = ufce;
-        } else {
-            f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fi), args);
-        }
-        AssignOperator op = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
-        if (topOp != null) {
-            op.getInputs().add(topOp);
-        }
+		if (builtinAquafi != null) {
+			fi = builtinAquafi;
+		} else {
+			fi = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+					fid.getFunctionName());
+			FunctionIdentifier builtinAsterixFi = AsterixBuiltinFunctions
+					.getBuiltinFunctionIdentifier(fi);
+			if (builtinAsterixFi != null) {
+				fi = builtinAsterixFi;
+			}
+		}
+		AbstractFunctionCallExpression f;
+		if (AsterixBuiltinFunctions.isBuiltinAggregateFunction(fi)) {
+			f = AsterixBuiltinFunctions.makeAggregateFunctionExpression(fi,
+					args);
+		} else if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(fi)) {
+			UnnestingFunctionCallExpression ufce = new UnnestingFunctionCallExpression(
+					FunctionUtils.getFunctionInfo(fi), args);
+			ufce.setReturnsUniqueValues(AsterixBuiltinFunctions
+					.returnsUniqueValues(fi));
+			f = ufce;
+		} else {
+			f = new ScalarFunctionCallExpression(
+					FunctionUtils.getFunctionInfo(fi), args);
+		}
+		AssignOperator op = new AssignOperator(v,
+				new MutableObject<ILogicalExpression>(f));
+		if (topOp != null) {
+			op.getInputs().add(topOp);
+		}
 
-        return new Pair<ILogicalOperator, LogicalVariable>(op, v);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(op, v);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitFunctionDecl(FunctionDecl fd,
-            Mutable<ILogicalOperator> tupSource) {
-        // TODO Auto-generated method stub
-        throw new NotImplementedException();
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitFunctionDecl(
+			FunctionDecl fd, Mutable<ILogicalOperator> tupSource) {
+		// TODO Auto-generated method stub
+		throw new NotImplementedException();
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitGroupbyClause(GroupbyClause gc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        GroupByOperator gOp = new GroupByOperator();
-        Mutable<ILogicalOperator> topOp = tupSource;
-        for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
-            LogicalVariable v;
-            VariableExpr vexpr = ve.getVar();
-            if (vexpr != null) {
-                v = context.newVar(vexpr);
-            } else {
-                v = context.newVar();
-            }
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(ve.getExpr(), topOp);
-            gOp.addGbyExpression(v, eo.first);
-            topOp = eo.second;
-        }
-        for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
-            LogicalVariable v;
-            VariableExpr vexpr = ve.getVar();
-            if (vexpr != null) {
-                v = context.newVar(vexpr);
-            } else {
-                v = context.newVar();
-            }
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(ve.getExpr(), topOp);
-            gOp.addDecorExpression(v, eo.first);
-            topOp = eo.second;
-        }
-        gOp.getInputs().add(topOp);
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitGroupbyClause(
+			GroupbyClause gc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		GroupByOperator gOp = new GroupByOperator();
+		Mutable<ILogicalOperator> topOp = tupSource;
+		for (GbyVariableExpressionPair ve : gc.getGbyPairList()) {
+			LogicalVariable v;
+			VariableExpr vexpr = ve.getVar();
+			if (vexpr != null) {
+				v = context.newVar(vexpr);
+			} else {
+				v = context.newVar();
+			}
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+					ve.getExpr(), topOp);
+			gOp.addGbyExpression(v, eo.first);
+			topOp = eo.second;
+		}
+		for (GbyVariableExpressionPair ve : gc.getDecorPairList()) {
+			LogicalVariable v;
+			VariableExpr vexpr = ve.getVar();
+			if (vexpr != null) {
+				v = context.newVar(vexpr);
+			} else {
+				v = context.newVar();
+			}
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+					ve.getExpr(), topOp);
+			gOp.addDecorExpression(v, eo.first);
+			topOp = eo.second;
+		}
+		gOp.getInputs().add(topOp);
 
-        for (VariableExpr var : gc.getWithVarList()) {
-            LogicalVariable aggVar = context.newVar();
-            LogicalVariable oldVar = context.getVar(var);
-            List<Mutable<ILogicalExpression>> flArgs = new ArrayList<Mutable<ILogicalExpression>>(1);
-            flArgs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(oldVar)));
-            AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
-                    AsterixBuiltinFunctions.LISTIFY, flArgs);
-            AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(aggVar),
-                    (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(fListify)));
-            agg.getInputs().add(
-                    new MutableObject<ILogicalOperator>(new NestedTupleSourceOperator(
-                            new MutableObject<ILogicalOperator>(gOp))));
-            ILogicalPlan plan = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(agg));
-            gOp.getNestedPlans().add(plan);
-            // Hide the variable that was part of the "with", replacing it with
-            // the one bound by the aggregation op.
-            context.setVar(var, aggVar);
-        }
+		for (VariableExpr var : gc.getWithVarList()) {
+			LogicalVariable aggVar = context.newVar();
+			LogicalVariable oldVar = context.getVar(var);
+			List<Mutable<ILogicalExpression>> flArgs = new ArrayList<Mutable<ILogicalExpression>>(
+					1);
+			flArgs.add(new MutableObject<ILogicalExpression>(
+					new VariableReferenceExpression(oldVar)));
+			AggregateFunctionCallExpression fListify = AsterixBuiltinFunctions
+					.makeAggregateFunctionExpression(
+							AsterixBuiltinFunctions.LISTIFY, flArgs);
+			AggregateOperator agg = new AggregateOperator(
+					mkSingletonArrayList(aggVar),
+					(List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
+							fListify)));
+			agg.getInputs().add(
+					new MutableObject<ILogicalOperator>(
+							new NestedTupleSourceOperator(
+									new MutableObject<ILogicalOperator>(gOp))));
+			ILogicalPlan plan = new ALogicalPlanImpl(
+					new MutableObject<ILogicalOperator>(agg));
+			gOp.getNestedPlans().add(plan);
+			// Hide the variable that was part of the "with", replacing it with
+			// the one bound by the aggregation op.
+			context.setVar(var, aggVar);
+		}
 
-        gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, gc.hasHashGroupByHint());
-        return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
-    }
+		gOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY,
+				gc.hasHashGroupByHint());
+		return new Pair<ILogicalOperator, LogicalVariable>(gOp, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitIfExpr(IfExpr ifexpr, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        // In the most general case, IfThenElse is translated in the following
-        // way.
-        //
-        // We assign the result of the condition to one variable varCond.
-        // We create one subplan which contains the plan for the "then" branch,
-        // on top of which there is a selection whose condition is varCond.
-        // Similarly, we create one subplan for the "else" branch, in which the
-        // selection is not(varCond).
-        // Finally, we concatenate the results. (??)
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitIfExpr(IfExpr ifexpr,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		// In the most general case, IfThenElse is translated in the following
+		// way.
+		//
+		// We assign the result of the condition to one variable varCond.
+		// We create one subplan which contains the plan for the "then" branch,
+		// on top of which there is a selection whose condition is varCond.
+		// Similarly, we create one subplan for the "else" branch, in which the
+		// selection is not(varCond).
+		// Finally, we concatenate the results. (??)
 
-        Pair<ILogicalOperator, LogicalVariable> pCond = ifexpr.getCondExpr().accept(this, tupSource);
-        ILogicalOperator opCond = pCond.first;
-        LogicalVariable varCond = pCond.second;
+		Pair<ILogicalOperator, LogicalVariable> pCond = ifexpr.getCondExpr()
+				.accept(this, tupSource);
+		ILogicalOperator opCond = pCond.first;
+		LogicalVariable varCond = pCond.second;
 
-        SubplanOperator sp = new SubplanOperator();
-        Mutable<ILogicalOperator> nestedSource = new MutableObject<ILogicalOperator>(new NestedTupleSourceOperator(
-                new MutableObject<ILogicalOperator>(sp)));
+		SubplanOperator sp = new SubplanOperator();
+		Mutable<ILogicalOperator> nestedSource = new MutableObject<ILogicalOperator>(
+				new NestedTupleSourceOperator(
+						new MutableObject<ILogicalOperator>(sp)));
 
-        Pair<ILogicalOperator, LogicalVariable> pThen = ifexpr.getThenExpr().accept(this, nestedSource);
-        SelectOperator sel1 = new SelectOperator(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(
-                varCond)));
-        sel1.getInputs().add(new MutableObject<ILogicalOperator>(pThen.first));
+		Pair<ILogicalOperator, LogicalVariable> pThen = ifexpr.getThenExpr()
+				.accept(this, nestedSource);
+		SelectOperator sel1 = new SelectOperator(
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(varCond)));
+		sel1.getInputs().add(new MutableObject<ILogicalOperator>(pThen.first));
 
-        Pair<ILogicalOperator, LogicalVariable> pElse = ifexpr.getElseExpr().accept(this, nestedSource);
-        AbstractFunctionCallExpression notVarCond = new ScalarFunctionCallExpression(
-                FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), new MutableObject<ILogicalExpression>(
-                        new VariableReferenceExpression(varCond)));
-        SelectOperator sel2 = new SelectOperator(new MutableObject<ILogicalExpression>(notVarCond));
-        sel2.getInputs().add(new MutableObject<ILogicalOperator>(pElse.first));
+		Pair<ILogicalOperator, LogicalVariable> pElse = ifexpr.getElseExpr()
+				.accept(this, nestedSource);
+		AbstractFunctionCallExpression notVarCond = new ScalarFunctionCallExpression(
+				FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT),
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(varCond)));
+		SelectOperator sel2 = new SelectOperator(
+				new MutableObject<ILogicalExpression>(notVarCond));
+		sel2.getInputs().add(new MutableObject<ILogicalOperator>(pElse.first));
 
-        ILogicalPlan p1 = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(sel1));
-        sp.getNestedPlans().add(p1);
-        ILogicalPlan p2 = new ALogicalPlanImpl(new MutableObject<ILogicalOperator>(sel2));
-        sp.getNestedPlans().add(p2);
+		ILogicalPlan p1 = new ALogicalPlanImpl(
+				new MutableObject<ILogicalOperator>(sel1));
+		sp.getNestedPlans().add(p1);
+		ILogicalPlan p2 = new ALogicalPlanImpl(
+				new MutableObject<ILogicalOperator>(sel2));
+		sp.getNestedPlans().add(p2);
 
-        Mutable<ILogicalOperator> opCondRef = new MutableObject<ILogicalOperator>(opCond);
-        sp.getInputs().add(opCondRef);
+		Mutable<ILogicalOperator> opCondRef = new MutableObject<ILogicalOperator>(
+				opCond);
+		sp.getInputs().add(opCondRef);
 
-        LogicalVariable resV = context.newVar();
-        AbstractFunctionCallExpression concatNonNull = new ScalarFunctionCallExpression(
-                FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.CONCAT_NON_NULL),
-                new MutableObject<ILogicalExpression>(new VariableReferenceExpression(pThen.second)),
-                new MutableObject<ILogicalExpression>(new VariableReferenceExpression(pElse.second)));
-        AssignOperator a = new AssignOperator(resV, new MutableObject<ILogicalExpression>(concatNonNull));
-        a.getInputs().add(new MutableObject<ILogicalOperator>(sp));
+		LogicalVariable resV = context.newVar();
+		AbstractFunctionCallExpression concatNonNull = new ScalarFunctionCallExpression(
+				FunctionUtils
+						.getFunctionInfo(AsterixBuiltinFunctions.CONCAT_NON_NULL),
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(pThen.second)),
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(pElse.second)));
+		AssignOperator a = new AssignOperator(resV,
+				new MutableObject<ILogicalExpression>(concatNonNull));
+		a.getInputs().add(new MutableObject<ILogicalOperator>(sp));
 
-        return new Pair<ILogicalOperator, LogicalVariable>(a, resV);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(a, resV);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLiteralExpr(LiteralExpr l, Mutable<ILogicalOperator> tupSource) {
-        LogicalVariable var = context.newVar();
-        AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(new ConstantExpression(
-                new AsterixConstantValue(ConstantHelper.objectFromLiteral(l.getValue())))));
-        if (tupSource != null) {
-            a.getInputs().add(tupSource);
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(a, var);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLiteralExpr(
+			LiteralExpr l, Mutable<ILogicalOperator> tupSource) {
+		LogicalVariable var = context.newVar();
+		AssignOperator a = new AssignOperator(var,
+				new MutableObject<ILogicalExpression>(new ConstantExpression(
+						new AsterixConstantValue(ConstantHelper
+								.objectFromLiteral(l.getValue())))));
+		if (tupSource != null) {
+			a.getInputs().add(tupSource);
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitOperatorExpr(OperatorExpr op,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        ArrayList<OperatorType> ops = op.getOpList();
-        int nOps = ops.size();
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitOperatorExpr(
+			OperatorExpr op, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		ArrayList<OperatorType> ops = op.getOpList();
+		int nOps = ops.size();
 
-        if (nOps > 0 && (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
-            return visitAndOrOperator(op, tupSource);
-        }
+		if (nOps > 0
+				&& (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
+			return visitAndOrOperator(op, tupSource);
+		}
 
-        ArrayList<Expression> exprs = op.getExprList();
+		ArrayList<Expression> exprs = op.getExprList();
 
-        Mutable<ILogicalOperator> topOp = tupSource;
+		Mutable<ILogicalOperator> topOp = tupSource;
 
-        ILogicalExpression currExpr = null;
-        for (int i = 0; i <= nOps; i++) {
+		ILogicalExpression currExpr = null;
+		for (int i = 0; i <= nOps; i++) {
 
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(exprs.get(i), topOp);
-            topOp = p.second;
-            ILogicalExpression e = p.first;
-            // now look at the operator
-            if (i < nOps) {
-                if (OperatorExpr.opIsComparison(ops.get(i))) {
-                    AbstractFunctionCallExpression c = createComparisonExpression(ops.get(i));
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+					exprs.get(i), topOp);
+			topOp = p.second;
+			ILogicalExpression e = p.first;
+			// now look at the operator
+			if (i < nOps) {
+				if (OperatorExpr.opIsComparison(ops.get(i))) {
+					AbstractFunctionCallExpression c = createComparisonExpression(ops
+							.get(i));
 
-                    // chain the operators
-                    if (i == 0) {
-                        c.getArguments().add(new MutableObject<ILogicalExpression>(e));
-                        currExpr = c;
-                        if (op.isBroadcastOperand(i)) {
-                            BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
-                            bcast.setObject(BroadcastSide.LEFT);
-                            c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
-                        }
-                    } else {
-                        ((AbstractFunctionCallExpression) currExpr).getArguments().add(
-                                new MutableObject<ILogicalExpression>(e));
-                        c.getArguments().add(new MutableObject<ILogicalExpression>(currExpr));
-                        currExpr = c;
-                        if (i == 1 && op.isBroadcastOperand(i)) {
-                            BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
-                            bcast.setObject(BroadcastSide.RIGHT);
-                            c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
-                        }
-                    }
-                } else {
-                    AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops.get(i));
+					// chain the operators
+					if (i == 0) {
+						c.getArguments().add(
+								new MutableObject<ILogicalExpression>(e));
+						currExpr = c;
+						if (op.isBroadcastOperand(i)) {
+							BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+							bcast.setObject(BroadcastSide.LEFT);
+							c.getAnnotations()
+									.put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
+											bcast);
+						}
+					} else {
+						((AbstractFunctionCallExpression) currExpr)
+								.getArguments()
+								.add(new MutableObject<ILogicalExpression>(e));
+						c.getArguments()
+								.add(new MutableObject<ILogicalExpression>(
+										currExpr));
+						currExpr = c;
+						if (i == 1 && op.isBroadcastOperand(i)) {
+							BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+							bcast.setObject(BroadcastSide.RIGHT);
+							c.getAnnotations()
+									.put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
+											bcast);
+						}
+					}
+				} else {
+					AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops
+							.get(i));
 
-                    if (i == 0) {
-                        f.getArguments().add(new MutableObject<ILogicalExpression>(e));
-                        currExpr = f;
-                    } else {
-                        ((AbstractFunctionCallExpression) currExpr).getArguments().add(
-                                new MutableObject<ILogicalExpression>(e));
-                        f.getArguments().add(new MutableObject<ILogicalExpression>(currExpr));
-                        currExpr = f;
-                    }
-                }
-            } else { // don't forget the last expression...
-                ((AbstractFunctionCallExpression) currExpr).getArguments()
-                        .add(new MutableObject<ILogicalExpression>(e));
-                if (i == 1 && op.isBroadcastOperand(i)) {
-                    BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
-                    bcast.setObject(BroadcastSide.RIGHT);
-                    ((AbstractFunctionCallExpression) currExpr).getAnnotations().put(
-                            BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
-                }
-            }
-        }
+					if (i == 0) {
+						f.getArguments().add(
+								new MutableObject<ILogicalExpression>(e));
+						currExpr = f;
+					} else {
+						((AbstractFunctionCallExpression) currExpr)
+								.getArguments()
+								.add(new MutableObject<ILogicalExpression>(e));
+						f.getArguments()
+								.add(new MutableObject<ILogicalExpression>(
+										currExpr));
+						currExpr = f;
+					}
+				}
+			} else { // don't forget the last expression...
+				((AbstractFunctionCallExpression) currExpr).getArguments().add(
+						new MutableObject<ILogicalExpression>(e));
+				if (i == 1 && op.isBroadcastOperand(i)) {
+					BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
+					bcast.setObject(BroadcastSide.RIGHT);
+					((AbstractFunctionCallExpression) currExpr)
+							.getAnnotations()
+							.put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY,
+									bcast);
+				}
+			}
+		}
 
-        LogicalVariable assignedVar = context.newVar();
-        AssignOperator a = new AssignOperator(assignedVar, new MutableObject<ILogicalExpression>(currExpr));
+		LogicalVariable assignedVar = context.newVar();
+		AssignOperator a = new AssignOperator(assignedVar,
+				new MutableObject<ILogicalExpression>(currExpr));
 
-        a.getInputs().add(topOp);
+		a.getInputs().add(topOp);
 
-        return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitOrderbyClause(OrderbyClause oc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
+	@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;
-        for (Expression e : oc.getOrderbyList()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(e, topOp);
-            OrderModifier m = modifIter.next();
-            OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
-            ord.getOrderExpressions()
-                    .add(new Pair<IOrder, Mutable<ILogicalExpression>>(comp, new MutableObject<ILogicalExpression>(
-                            p.first)));
-            topOp = p.second;
-        }
-        ord.getInputs().add(topOp);
-        if (oc.getNumTuples() > 0) {
-            ord.getAnnotations().put(OperatorAnnotations.CARDINALITY, oc.getNumTuples());
-        }
-        if (oc.getNumFrames() > 0) {
-            ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames());
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
-    }
+		OrderOperator ord = new OrderOperator();
+		Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
+		Mutable<ILogicalOperator> topOp = tupSource;
+		for (Expression e : oc.getOrderbyList()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+					e, topOp);
+			OrderModifier m = modifIter.next();
+			OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER
+					: OrderOperator.DESC_ORDER;
+			ord.getOrderExpressions().add(
+					new Pair<IOrder, Mutable<ILogicalExpression>>(comp,
+							new MutableObject<ILogicalExpression>(p.first)));
+			topOp = p.second;
+		}
+		ord.getInputs().add(topOp);
+		if (oc.getNumTuples() > 0) {
+			ord.getAnnotations().put(OperatorAnnotations.CARDINALITY,
+					oc.getNumTuples());
+		}
+		if (oc.getNumFrames() > 0) {
+			ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES,
+					oc.getNumFrames());
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(ord, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitQuantifiedExpression(QuantifiedExpression qe,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Mutable<ILogicalOperator> topOp = tupSource;
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitQuantifiedExpression(
+			QuantifiedExpression qe, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Mutable<ILogicalOperator> topOp = tupSource;
 
-        ILogicalOperator firstOp = null;
-        Mutable<ILogicalOperator> lastOp = null;
+		ILogicalOperator firstOp = null;
+		Mutable<ILogicalOperator> lastOp = null;
 
-        for (QuantifiedPair qt : qe.getQuantifiedList()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(qt.getExpr(), topOp);
-            topOp = eo1.second;
-            LogicalVariable uVar = context.newVar(qt.getVarExpr());
-            ILogicalOperator u = new UnnestOperator(uVar, new MutableObject<ILogicalExpression>(
-                    makeUnnestExpression(eo1.first)));
+		for (QuantifiedPair qt : qe.getQuantifiedList()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(
+					qt.getExpr(), topOp);
+			topOp = eo1.second;
+			LogicalVariable uVar = context.newVar(qt.getVarExpr());
+			ILogicalOperator u = new UnnestOperator(uVar,
+					new MutableObject<ILogicalExpression>(
+							makeUnnestExpression(eo1.first)));
 
-            if (firstOp == null) {
-                firstOp = u;
-            }
-            if (lastOp != null) {
-                u.getInputs().add(lastOp);
-            }
-            lastOp = new MutableObject<ILogicalOperator>(u);
-        }
+			if (firstOp == null) {
+				firstOp = u;
+			}
+			if (lastOp != null) {
+				u.getInputs().add(lastOp);
+			}
+			lastOp = new MutableObject<ILogicalOperator>(u);
+		}
 
-        // We make all the unnest correspond. to quantif. vars. sit on top
-        // in the hope of enabling joins & other optimiz.
-        firstOp.getInputs().add(topOp);
-        topOp = lastOp;
+		// We make all the unnest correspond. to quantif. vars. sit on top
+		// in the hope of enabling joins & other optimiz.
+		firstOp.getInputs().add(topOp);
+		topOp = lastOp;
 
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(qe.getSatisfiesExpr(), topOp);
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(
+				qe.getSatisfiesExpr(), topOp);
 
-        AggregateFunctionCallExpression fAgg;
-        SelectOperator s;
-        if (qe.getQuantifier() == Quantifier.SOME) {
-            s = new SelectOperator(new MutableObject<ILogicalExpression>(eo2.first));
-            s.getInputs().add(eo2.second);
-            fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(AsterixBuiltinFunctions.NON_EMPTY_STREAM,
-                    new ArrayList<Mutable<ILogicalExpression>>());
-        } else { // EVERY
-            List<Mutable<ILogicalExpression>> satExprList = new ArrayList<Mutable<ILogicalExpression>>(1);
-            satExprList.add(new MutableObject<ILogicalExpression>(eo2.first));
-            s = new SelectOperator(new MutableObject<ILogicalExpression>(new ScalarFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), satExprList)));
-            s.getInputs().add(eo2.second);
-            fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(AsterixBuiltinFunctions.EMPTY_STREAM,
-                    new ArrayList<Mutable<ILogicalExpression>>());
-        }
-        LogicalVariable qeVar = context.newVar();
-        AggregateOperator a = new AggregateOperator(mkSingletonArrayList(qeVar),
-                (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(fAgg)));
-        a.getInputs().add(new MutableObject<ILogicalOperator>(s));
-        return new Pair<ILogicalOperator, LogicalVariable>(a, qeVar);
-    }
+		AggregateFunctionCallExpression fAgg;
+		SelectOperator s;
+		if (qe.getQuantifier() == Quantifier.SOME) {
+			s = new SelectOperator(new MutableObject<ILogicalExpression>(
+					eo2.first));
+			s.getInputs().add(eo2.second);
+			fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+					AsterixBuiltinFunctions.NON_EMPTY_STREAM,
+					new ArrayList<Mutable<ILogicalExpression>>());
+		} else { // EVERY
+			List<Mutable<ILogicalExpression>> satExprList = new ArrayList<Mutable<ILogicalExpression>>(
+					1);
+			satExprList.add(new MutableObject<ILogicalExpression>(eo2.first));
+			s = new SelectOperator(new MutableObject<ILogicalExpression>(
+					new ScalarFunctionCallExpression(FunctionUtils
+							.getFunctionInfo(AlgebricksBuiltinFunctions.NOT),
+							satExprList)));
+			s.getInputs().add(eo2.second);
+			fAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
+					AsterixBuiltinFunctions.EMPTY_STREAM,
+					new ArrayList<Mutable<ILogicalExpression>>());
+		}
+		LogicalVariable qeVar = context.newVar();
+		AggregateOperator a = new AggregateOperator(
+				mkSingletonArrayList(qeVar),
+				(List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
+						fAgg)));
+		a.getInputs().add(new MutableObject<ILogicalOperator>(s));
+		return new Pair<ILogicalOperator, LogicalVariable>(a, qeVar);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitQuery(Query q, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        return q.getBody().accept(this, tupSource);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitQuery(Query q,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		return q.getBody().accept(this, tupSource);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitRecordConstructor(RecordConstructor rc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
-                FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
-        LogicalVariable v1 = context.newVar();
-        AssignOperator a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(f));
-        Mutable<ILogicalOperator> topOp = tupSource;
-        for (FieldBinding fb : rc.getFbList()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(fb.getLeftExpr(), topOp);
-            f.getArguments().add(new MutableObject<ILogicalExpression>(eo1.first));
-            topOp = eo1.second;
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(fb.getRightExpr(), topOp);
-            f.getArguments().add(new MutableObject<ILogicalExpression>(eo2.first));
-            topOp = eo2.second;
-        }
-        a.getInputs().add(topOp);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitRecordConstructor(
+			RecordConstructor rc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
+				FunctionUtils
+						.getFunctionInfo(AsterixBuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
+		LogicalVariable v1 = context.newVar();
+		AssignOperator a = new AssignOperator(v1,
+				new MutableObject<ILogicalExpression>(f));
+		Mutable<ILogicalOperator> topOp = tupSource;
+		for (FieldBinding fb : rc.getFbList()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = aqlExprToAlgExpression(
+					fb.getLeftExpr(), topOp);
+			f.getArguments().add(
+					new MutableObject<ILogicalExpression>(eo1.first));
+			topOp = eo1.second;
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = aqlExprToAlgExpression(
+					fb.getRightExpr(), topOp);
+			f.getArguments().add(
+					new MutableObject<ILogicalExpression>(eo2.first));
+			topOp = eo2.second;
+		}
+		a.getInputs().add(topOp);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitListConstructor(ListConstructor lc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR) ? AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR
-                : AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
-        AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fid));
-        LogicalVariable v1 = context.newVar();
-        AssignOperator a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(f));
-        Mutable<ILogicalOperator> topOp = tupSource;
-        for (Expression expr : lc.getExprList()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, topOp);
-            f.getArguments().add(new MutableObject<ILogicalExpression>(eo.first));
-            topOp = eo.second;
-        }
-        a.getInputs().add(topOp);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitListConstructor(
+			ListConstructor lc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		FunctionIdentifier fid = (lc.getType() == Type.ORDERED_LIST_CONSTRUCTOR) ? AsterixBuiltinFunctions.ORDERED_LIST_CONSTRUCTOR
+				: AsterixBuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
+		AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(
+				FunctionUtils.getFunctionInfo(fid));
+		LogicalVariable v1 = context.newVar();
+		AssignOperator a = new AssignOperator(v1,
+				new MutableObject<ILogicalExpression>(f));
+		Mutable<ILogicalOperator> topOp = tupSource;
+		for (Expression expr : lc.getExprList()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+					expr, topOp);
+			f.getArguments().add(
+					new MutableObject<ILogicalExpression>(eo.first));
+			topOp = eo.second;
+		}
+		a.getInputs().add(topOp);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUnaryExpr(UnaryExpr u, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        Expression expr = u.getExpr();
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(expr, tupSource);
-        LogicalVariable v1 = context.newVar();
-        AssignOperator a;
-        if (u.getSign() == Sign.POSITIVE) {
-            a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(eo.first));
-        } else {
-            AbstractFunctionCallExpression m = new ScalarFunctionCallExpression(
-                    FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS));
-            m.getArguments().add(new MutableObject<ILogicalExpression>(eo.first));
-            a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(m));
-        }
-        a.getInputs().add(eo.second);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUnaryExpr(UnaryExpr u,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		Expression expr = u.getExpr();
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = aqlExprToAlgExpression(
+				expr, tupSource);
+		LogicalVariable v1 = context.newVar();
+		AssignOperator a;
+		if (u.getSign() == Sign.POSITIVE) {
+			a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(
+					eo.first));
+		} else {
+			AbstractFunctionCallExpression m = new ScalarFunctionCallExpression(
+					FunctionUtils
+							.getFunctionInfo(AsterixBuiltinFunctions.NUMERIC_UNARY_MINUS));
+			m.getArguments().add(
+					new MutableObject<ILogicalExpression>(eo.first));
+			a = new AssignOperator(v1, new MutableObject<ILogicalExpression>(m));
+		}
+		a.getInputs().add(eo.second);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, v1);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitVariableExpr(VariableExpr v, Mutable<ILogicalOperator> tupSource) {
-        // Should we ever get to this method?
-        LogicalVariable var = context.newVar();
-        LogicalVariable oldV = context.getVar(v.getVar().getId());
-        AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(
-                new VariableReferenceExpression(oldV)));
-        a.getInputs().add(tupSource);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, var);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitVariableExpr(
+			VariableExpr v, Mutable<ILogicalOperator> tupSource) {
+		// Should we ever get to this method?
+		LogicalVariable var = context.newVar();
+		LogicalVariable oldV = context.getVar(v.getVar().getId());
+		AssignOperator a = new AssignOperator(var,
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(oldV)));
+		a.getInputs().add(tupSource);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitWhereClause(WhereClause w, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(w.getWhereExpr(), tupSource);
-        SelectOperator s = new SelectOperator(new MutableObject<ILogicalExpression>(p.first));
-        s.getInputs().add(p.second);
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitWhereClause(
+			WhereClause w, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+				w.getWhereExpr(), tupSource);
+		SelectOperator s = new SelectOperator(
+				new MutableObject<ILogicalExpression>(p.first));
+		s.getInputs().add(p.second);
 
-        return new Pair<ILogicalOperator, LogicalVariable>(s, null);
-    }
+		return new Pair<ILogicalOperator, LogicalVariable>(s, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLimitClause(LimitClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getLimitExpr(), tupSource);
-        LimitOperator opLim;
-        Expression offset = lc.getOffset();
-        if (offset != null) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p2 = aqlExprToAlgExpression(offset, p1.second);
-            opLim = new LimitOperator(p1.first, p2.first);
-            opLim.getInputs().add(p2.second);
-        } else {
-            opLim = new LimitOperator(p1.first);
-            opLim.getInputs().add(p1.second);
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(opLim, null);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLimitClause(
+			LimitClause lc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(
+				lc.getLimitExpr(), tupSource);
+		LimitOperator opLim;
+		Expression offset = lc.getOffset();
+		if (offset != null) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p2 = aqlExprToAlgExpression(
+					offset, p1.second);
+			opLim = new LimitOperator(p1.first, p2.first);
+			opLim.getInputs().add(p2.second);
+		} else {
+			opLim = new LimitOperator(p1.first);
+			opLim.getInputs().add(p1.second);
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(opLim, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDieClause(DieClause lc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(lc.getDieExpr(), tupSource);
-        DieOperator opDie = new DieOperator(p1.first);
-        opDie.getInputs().add(p1.second);
-        return new Pair<ILogicalOperator, LogicalVariable>(opDie, null);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDieClause(DieClause lc,
+			Mutable<ILogicalOperator> tupSource) throws AsterixException {
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> p1 = aqlExprToAlgExpression(
+				lc.getDieExpr(), tupSource);
+		DieOperator opDie = new DieOperator(p1.first);
+		opDie.getInputs().add(p1.second);
+		return new Pair<ILogicalOperator, LogicalVariable>(opDie, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDistinctClause(DistinctClause dc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
-        Mutable<ILogicalOperator> input = null;
-        for (Expression expr : dc.getDistinctByExpr()) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(expr, tupSource);
-            exprList.add(new MutableObject<ILogicalExpression>(p.first));
-            input = p.second;
-        }
-        DistinctOperator opDistinct = new DistinctOperator(exprList);
-        opDistinct.getInputs().add(input);
-        return new Pair<ILogicalOperator, LogicalVariable>(opDistinct, null);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDistinctClause(
+			DistinctClause dc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		List<Mutable<ILogicalExpression>> exprList = new ArrayList<Mutable<ILogicalExpression>>();
+		Mutable<ILogicalOperator> input = null;
+		for (Expression expr : dc.getDistinctByExpr()) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+					expr, tupSource);
+			exprList.add(new MutableObject<ILogicalExpression>(p.first));
+			input = p.second;
+		}
+		DistinctOperator opDistinct = new DistinctOperator(exprList);
+		opDistinct.getInputs().add(input);
+		return new Pair<ILogicalOperator, LogicalVariable>(opDistinct, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUnionExpr(UnionExpr unionExpr,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        Mutable<ILogicalOperator> ts = tupSource;
-        ILogicalOperator lastOp = null;
-        LogicalVariable lastVar = null;
-        boolean first = true;
-        for (Expression e : unionExpr.getExprs()) {
-            if (first) {
-                first = false;
-            } else {
-                ts = new MutableObject<ILogicalOperator>(new EmptyTupleSourceOperator());
-            }
-            Pair<ILogicalOperator, LogicalVariable> p1 = e.accept(this, ts);
-            if (lastOp == null) {
-                lastOp = p1.first;
-                lastVar = p1.second;
-            } else {
-                LogicalVariable unnestVar1 = context.newVar();
-                UnnestOperator unnest1 = new UnnestOperator(unnestVar1, new MutableObject<ILogicalExpression>(
-                        makeUnnestExpression(new VariableReferenceExpression(lastVar))));
-                unnest1.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
-                LogicalVariable unnestVar2 = context.newVar();
-                UnnestOperator unnest2 = new UnnestOperator(unnestVar2, new MutableObject<ILogicalExpression>(
-                        makeUnnestExpression(new VariableReferenceExpression(p1.second))));
-                unnest2.getInputs().add(new MutableObject<ILogicalOperator>(p1.first));
-                List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(
-                        1);
-                LogicalVariable resultVar = context.newVar();
-                Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
-                        unnestVar1, unnestVar2, resultVar);
-                varMap.add(triple);
-                UnionAllOperator unionOp = new UnionAllOperator(varMap);
-                unionOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest1));
-                unionOp.getInputs().add(new MutableObject<ILogicalOperator>(unnest2));
-                lastVar = resultVar;
-                lastOp = unionOp;
-            }
-        }
-        LogicalVariable aggVar = context.newVar();
-        ArrayList<LogicalVariable> aggregVars = new ArrayList<LogicalVariable>(1);
-        aggregVars.add(aggVar);
-        List<Mutable<ILogicalExpression>> afcExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
-        afcExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(lastVar)));
-        AggregateFunctionCallExpression afc = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
-                AsterixBuiltinFunctions.LISTIFY, afcExprs);
-        ArrayList<Mutable<ILogicalExpression>> aggregExprs = new ArrayList<Mutable<ILogicalExpression>>(1);
-        aggregExprs.add(new MutableObject<ILogicalExpression>(afc));
-        AggregateOperator agg = new AggregateOperator(aggregVars, aggregExprs);
-        agg.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
-        return new Pair<ILogicalOperator, LogicalVariable>(agg, aggVar);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUnionExpr(
+			UnionExpr unionExpr, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		Mutable<ILogicalOperator> ts = tupSource;
+		ILogicalOperator lastOp = null;
+		LogicalVariable lastVar = null;
+		boolean first = true;
+		for (Expression e : unionExpr.getExprs()) {
+			if (first) {
+				first = false;
+			} else {
+				ts = new MutableObject<ILogicalOperator>(
+						new EmptyTupleSourceOperator());
+			}
+			Pair<ILogicalOperator, LogicalVariable> p1 = e.accept(this, ts);
+			if (lastOp == null) {
+				lastOp = p1.first;
+				lastVar = p1.second;
+			} else {
+				LogicalVariable unnestVar1 = context.newVar();
+				UnnestOperator unnest1 = new UnnestOperator(
+						unnestVar1,
+						new MutableObject<ILogicalExpression>(
+								makeUnnestExpression(new VariableReferenceExpression(
+										lastVar))));
+				unnest1.getInputs().add(
+						new MutableObject<ILogicalOperator>(lastOp));
+				LogicalVariable unnestVar2 = context.newVar();
+				UnnestOperator unnest2 = new UnnestOperator(
+						unnestVar2,
+						new MutableObject<ILogicalExpression>(
+								makeUnnestExpression(new VariableReferenceExpression(
+										p1.second))));
+				unnest2.getInputs().add(
+						new MutableObject<ILogicalOperator>(p1.first));
+				List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(
+						1);
+				LogicalVariable resultVar = context.newVar();
+				Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(
+						unnestVar1, unnestVar2, resultVar);
+				varMap.add(triple);
+				UnionAllOperator unionOp = new UnionAllOperator(varMap);
+				unionOp.getInputs().add(
+						new MutableObject<ILogicalOperator>(unnest1));
+				unionOp.getInputs().add(
+						new MutableObject<ILogicalOperator>(unnest2));
+				lastVar = resultVar;
+				lastOp = unionOp;
+			}
+		}
+		LogicalVariable aggVar = context.newVar();
+		ArrayList<LogicalVariable> aggregVars = new ArrayList<LogicalVariable>(
+				1);
+		aggregVars.add(aggVar);
+		List<Mutable<ILogicalExpression>> afcExprs = new ArrayList<Mutable<ILogicalExpression>>(
+				1);
+		afcExprs.add(new MutableObject<ILogicalExpression>(
+				new VariableReferenceExpression(lastVar)));
+		AggregateFunctionCallExpression afc = AsterixBuiltinFunctions
+				.makeAggregateFunctionExpression(
+						AsterixBuiltinFunctions.LISTIFY, afcExprs);
+		ArrayList<Mutable<ILogicalExpression>> aggregExprs = new ArrayList<Mutable<ILogicalExpression>>(
+				1);
+		aggregExprs.add(new MutableObject<ILogicalExpression>(afc));
+		AggregateOperator agg = new AggregateOperator(aggregVars, aggregExprs);
+		agg.getInputs().add(new MutableObject<ILogicalOperator>(lastOp));
+		return new Pair<ILogicalOperator, LogicalVariable>(agg, aggVar);
+	}
 
-    private AbstractFunctionCallExpression createComparisonExpression(OperatorType t) {
-        FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
-        IFunctionInfo finfo = FunctionUtils.getFunctionInfo(fi);
-        return new ScalarFunctionCallExpression(finfo);
-    }
+	private AbstractFunctionCallExpression createComparisonExpression(
+			OperatorType t) {
+		FunctionIdentifier fi = operatorTypeToFunctionIdentifier(t);
+		IFunctionInfo finfo = FunctionUtils.getFunctionInfo(fi);
+		return new ScalarFunctionCallExpression(finfo);
+	}
 
-    private FunctionIdentifier operatorTypeToFunctionIdentifier(OperatorType t) {
-        switch (t) {
-            case EQ: {
-                return AlgebricksBuiltinFunctions.EQ;
-            }
-            case NEQ: {
-                return AlgebricksBuiltinFunctions.NEQ;
-            }
-            case GT: {
-                return AlgebricksBuiltinFunctions.GT;
-            }
-            case GE: {
-                return AlgebricksBuiltinFunctions.GE;
-            }
-            case LT: {
-                return AlgebricksBuiltinFunctions.LT;
-            }
-            case LE: {
-                return AlgebricksBuiltinFunctions.LE;
-            }
-            default: {
-                throw new IllegalStateException();
-            }
-        }
-    }
+	private FunctionIdentifier operatorTypeToFunctionIdentifier(OperatorType t) {
+		switch (t) {
+		case EQ: {
+			return AlgebricksBuiltinFunctions.EQ;
+		}
+		case NEQ: {
+			return AlgebricksBuiltinFunctions.NEQ;
+		}
+		case GT: {
+			return AlgebricksBuiltinFunctions.GT;
+		}
+		case GE: {
+			return AlgebricksBuiltinFunctions.GE;
+		}
+		case LT: {
+			return AlgebricksBuiltinFunctions.LT;
+		}
+		case LE: {
+			return AlgebricksBuiltinFunctions.LE;
+		}
+		default: {
+			throw new IllegalStateException();
+		}
+		}
+	}
 
-    private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(OperatorType t)
-            throws AsterixException {
+	private AbstractFunctionCallExpression createFunctionCallExpressionForBuiltinOperator(
+			OperatorType t) throws AsterixException {
 
-        FunctionIdentifier fid = null;
-        switch (t) {
-            case PLUS: {
-                fid = AlgebricksBuiltinFunctions.NUMERIC_ADD;
-                break;
-            }
-            case MINUS: {
-                fid = AsterixBuiltinFunctions.NUMERIC_SUBTRACT;
-                break;
-            }
-            case MUL: {
-                fid = AsterixBuiltinFunctions.NUMERIC_MULTIPLY;
-                break;
-            }
-            case DIV: {
-                fid = AsterixBuiltinFunctions.NUMERIC_DIVIDE;
-                break;
-            }
-            case MOD: {
-                fid = AsterixBuiltinFunctions.NUMERIC_MOD;
-                break;
-            }
-            case IDIV: {
-                fid = AsterixBuiltinFunctions.NUMERIC_IDIV;
-                break;
-            }
-            case CARET: {
-                fid = AsterixBuiltinFunctions.CARET;
-                break;
-            }
-            case AND: {
-                fid = AlgebricksBuiltinFunctions.AND;
-                break;
-            }
-            case OR: {
-                fid = AlgebricksBuiltinFunctions.OR;
-                break;
-            }
-            case FUZZY_EQ: {
-                fid = AsterixBuiltinFunctions.FUZZY_EQ;
-                break;
-            }
+		FunctionIdentifier fid = null;
+		switch (t) {
+		case PLUS: {
+			fid = AlgebricksBuiltinFunctions.NUMERIC_ADD;
+			break;
+		}
+		case MINUS: {
+			fid = AsterixBuiltinFunctions.NUMERIC_SUBTRACT;
+			break;
+		}
+		case MUL: {
+			fid = AsterixBuiltinFunctions.NUMERIC_MULTIPLY;
+			break;
+		}
+		case DIV: {
+			fid = AsterixBuiltinFunctions.NUMERIC_DIVIDE;
+			break;
+		}
+		case MOD: {
+			fid = AsterixBuiltinFunctions.NUMERIC_MOD;
+			break;
+		}
+		case IDIV: {
+			fid = AsterixBuiltinFunctions.NUMERIC_IDIV;
+			break;
+		}
+		case CARET: {
+			fid = AsterixBuiltinFunctions.CARET;
+			break;
+		}
+		case AND: {
+			fid = AlgebricksBuiltinFunctions.AND;
+			break;
+		}
+		case OR: {
+			fid = AlgebricksBuiltinFunctions.OR;
+			break;
+		}
+		case FUZZY_EQ: {
+			fid = AsterixBuiltinFunctions.FUZZY_EQ;
+			break;
+		}
 
-            default: {
-                throw new NotImplementedException("Operator " + t + " is not yet implemented");
-            }
-        }
-        return new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(fid));
-    }
+		default: {
+			throw new NotImplementedException("Operator " + t
+					+ " is not yet implemented");
+		}
+		}
+		return new ScalarFunctionCallExpression(
+				FunctionUtils.getFunctionInfo(fid));
+	}
 
-    private static boolean hasOnlyChild(ILogicalOperator parent, Mutable<ILogicalOperator> childCandidate) {
-        List<Mutable<ILogicalOperator>> inp = parent.getInputs();
-        if (inp == null || inp.size() != 1) {
-            return false;
-        }
-        return inp.get(0) == childCandidate;
-    }
+	private static boolean hasOnlyChild(ILogicalOperator parent,
+			Mutable<ILogicalOperator> childCandidate) {
+		List<Mutable<ILogicalOperator>> inp = parent.getInputs();
+		if (inp == null || inp.size() != 1) {
+			return false;
+		}
+		return inp.get(0) == childCandidate;
+	}
 
-    private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(Expression expr,
-            Mutable<ILogicalOperator> topOp) throws AsterixException {
-        switch (expr.getKind()) {
-            case VARIABLE_EXPRESSION: {
-                VariableReferenceExpression ve = new VariableReferenceExpression(context.getVar(((VariableExpr) expr)
-                        .getVar().getId()));
-                return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve, topOp);
-            }
-            case METAVARIABLE_EXPRESSION: {
-                ILogicalExpression le = metaScopeExp.getVariableReferenceExpression(((VariableExpr) expr).getVar());
-                return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(le, topOp);
-            }
-            case LITERAL_EXPRESSION: {
-                LiteralExpr val = (LiteralExpr) expr;
-                return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new ConstantExpression(
-                        new AsterixConstantValue(ConstantHelper.objectFromLiteral(val.getValue()))), topOp);
-            }
-            default: {
-                // Mutable<ILogicalExpression> src = new
-                // Mutable<ILogicalExpression>();
-                // Mutable<ILogicalExpression> src = topOp;
-                if (expressionNeedsNoNesting(expr)) {
-                    Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, topOp);
-                    ILogicalExpression exp = ((AssignOperator) p.first).getExpressions().get(0).getValue();
-                    return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(exp, p.first.getInputs().get(0));
-                } else {
-                    Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>();
+	private Pair<ILogicalExpression, Mutable<ILogicalOperator>> aqlExprToAlgExpression(
+			Expression expr, Mutable<ILogicalOperator> topOp)
+			throws AsterixException {
+		switch (expr.getKind()) {
+		case VARIABLE_EXPRESSION: {
+			VariableReferenceExpression ve = new VariableReferenceExpression(
+					context.getVar(((VariableExpr) expr).getVar().getId()));
+			return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(ve,
+					topOp);
+		}
+		case METAVARIABLE_EXPRESSION: {
+			ILogicalExpression le = metaScopeExp
+					.getVariableReferenceExpression(((VariableExpr) expr)
+							.getVar());
+			return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(le,
+					topOp);
+		}
+		case LITERAL_EXPRESSION: {
+			LiteralExpr val = (LiteralExpr) expr;
+			return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
+					new ConstantExpression(new AsterixConstantValue(
+							ConstantHelper.objectFromLiteral(val.getValue()))),
+					topOp);
+		}
+		default: {
+			// Mutable<ILogicalExpression> src = new
+			// Mutable<ILogicalExpression>();
+			// Mutable<ILogicalExpression> src = topOp;
+			if (expressionNeedsNoNesting(expr)) {
+				Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
+						topOp);
+				ILogicalExpression exp = ((AssignOperator) p.first)
+						.getExpressions().get(0).getValue();
+				return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
+						exp, p.first.getInputs().get(0));
+			} else {
+				Mutable<ILogicalOperator> src = new MutableObject<ILogicalOperator>();
 
-                    Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this, src);
+				Pair<ILogicalOperator, LogicalVariable> p = expr.accept(this,
+						src);
 
-                    if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
-                        // src.setOperator(topOp.getOperator());
-                        Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(p.first);
-                        return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new VariableReferenceExpression(
-                                p.second), top2);
-                    } else {
-                        SubplanOperator s = new SubplanOperator();
-                        s.getInputs().add(topOp);
-                        src.setValue(new NestedTupleSourceOperator(new MutableObject<ILogicalOperator>(s)));
-                        Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(p.first);
-                        s.setRootOp(planRoot);
-                        return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(new VariableReferenceExpression(
-                                p.second), new MutableObject<ILogicalOperator>(s));
-                    }
-                }
-            }
-        }
+				if (((AbstractLogicalOperator) p.first).getOperatorTag() == LogicalOperatorTag.SUBPLAN) {
+					// src.setOperator(topOp.getOperator());
+					Mutable<ILogicalOperator> top2 = new MutableObject<ILogicalOperator>(
+							p.first);
+					return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
+							new VariableReferenceExpression(p.second), top2);
+				} else {
+					SubplanOperator s = new SubplanOperator();
+					s.getInputs().add(topOp);
+					src.setValue(new NestedTupleSourceOperator(
+							new MutableObject<ILogicalOperator>(s)));
+					Mutable<ILogicalOperator> planRoot = new MutableObject<ILogicalOperator>(
+							p.first);
+					s.setRootOp(planRoot);
+					return new Pair<ILogicalExpression, Mutable<ILogicalOperator>>(
+							new VariableReferenceExpression(p.second),
+							new MutableObject<ILogicalOperator>(s));
+				}
+			}
+		}
+		}
 
-    }
+	}
 
-    private Pair<ILogicalOperator, LogicalVariable> produceFlwrResult(boolean noForClause, boolean isTop,
-            Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
-        if (isTop) {
-            ProjectOperator pr = new ProjectOperator(resVar);
-            pr.getInputs().add(resOpRef);
-            return new Pair<ILogicalOperator, LogicalVariable>(pr, resVar);
+	private Pair<ILogicalOperator, LogicalVariable> produceFlwrResult(
+			boolean noForClause, boolean isTop,
+			Mutable<ILogicalOperator> resOpRef, LogicalVariable resVar) {
+		if (isTop) {
+			ProjectOperator pr = new ProjectOperator(resVar);
+			pr.getInputs().add(resOpRef);
+			return new Pair<ILogicalOperator, LogicalVariable>(pr, resVar);
 
-        } else if (noForClause) {
-            return new Pair<ILogicalOperator, LogicalVariable>(resOpRef.getValue(), resVar);
-        } else {
-            return aggListify(resVar, resOpRef, false);
-        }
-    }
+		} else if (noForClause) {
+			return new Pair<ILogicalOperator, LogicalVariable>(
+					resOpRef.getValue(), resVar);
+		} else {
+			return aggListify(resVar, resOpRef, false);
+		}
+	}
 
-    private Pair<ILogicalOperator, LogicalVariable> aggListify(LogicalVariable var, Mutable<ILogicalOperator> opRef,
-            boolean bProject) {
-        AggregateFunctionCallExpression funAgg = AsterixBuiltinFunctions.makeAggregateFunctionExpression(
-                AsterixBuiltinFunctions.LISTIFY, new ArrayList<Mutable<ILogicalExpression>>());
-        funAgg.getArguments().add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
-        LogicalVariable varListified = context.newVar();
-        AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(varListified),
-                (List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(funAgg)));
-        agg.getInputs().add(opRef);
-        ILogicalOperator res;
-        if (bProject) {
-            ProjectOperator pr = new ProjectOperator(varListified);
-            pr.getInputs().add(new MutableObject<ILogicalOperator>(agg));
-            res = pr;
-        } else {
-            res = agg;
-        }
-        return new Pair<ILogicalOperator, LogicalVariable>(res, varListified);
-    }
+	private Pair<ILogicalOperator, LogicalVariable> aggListify(
+			LogicalVariable var, Mutable<ILogicalOperator> opRef,
+			boolean bProject) {
+		AggregateFunctionCallExpression funAgg = AsterixBuiltinFunctions
+				.makeAggregateFunctionExpression(
+						AsterixBuiltinFunctions.LISTIFY,
+						new ArrayList<Mutable<ILogicalExpression>>());
+		funAgg.getArguments().add(
+				new MutableObject<ILogicalExpression>(
+						new VariableReferenceExpression(var)));
+		LogicalVariable varListified = context.newVar();
+		AggregateOperator agg = new AggregateOperator(
+				mkSingletonArrayList(varListified),
+				(List) mkSingletonArrayList(new MutableObject<ILogicalExpression>(
+						funAgg)));
+		agg.getInputs().add(opRef);
+		ILogicalOperator res;
+		if (bProject) {
+			ProjectOperator pr = new ProjectOperator(varListified);
+			pr.getInputs().add(new MutableObject<ILogicalOperator>(agg));
+			res = pr;
+		} else {
+			res = agg;
+		}
+		return new Pair<ILogicalOperator, LogicalVariable>(res, varListified);
+	}
 
-    private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(OperatorExpr op,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        ArrayList<OperatorType> ops = op.getOpList();
-        int nOps = ops.size();
+	private Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(
+			OperatorExpr op, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		ArrayList<OperatorType> ops = op.getOpList();
+		int nOps = ops.size();
 
-        ArrayList<Expression> exprs = op.getExprList();
+		ArrayList<Expression> exprs = op.getExprList();
 
-        Mutable<ILogicalOperator> topOp = tupSource;
+		Mutable<ILogicalOperator> topOp = tupSource;
 
-        OperatorType opLogical = ops.get(0);
-        AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
+		OperatorType opLogical = ops.get(0);
+		AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
 
-        for (int i = 0; i <= nOps; i++) {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(exprs.get(i), topOp);
-            topOp = p.second;
-            // now look at the operator
-            if (i < nOps) {
-                if (ops.get(i) != opLogical) {
-                    throw new TranslationException("Unexpected operator " + ops.get(i)
-                            + " in an OperatorExpr starting with " + opLogical);
-                }
-            }
-            f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
-        }
+		for (int i = 0; i <= nOps; i++) {
+			Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(
+					exprs.get(i), topOp);
+			topOp = p.second;
+			// now look at the operator
+			if (i < nOps) {
+				if (ops.get(i) != opLogical) {
+					throw new TranslationException("Unexpected operator "
+							+ ops.get(i) + " in an OperatorExpr starting with "
+							+ opLogical);
+				}
+			}
+			f.getArguments()
+					.add(new MutableObject<ILogicalExpression>(p.first));
+		}
 
-        LogicalVariable assignedVar = context.newVar();
-        AssignOperator a = new AssignOperator(assignedVar, new MutableObject<ILogicalExpression>(f));
-        a.getInputs().add(topOp);
+		LogicalVariable assignedVar = context.newVar();
+		AssignOperator a = new AssignOperator(assignedVar,
+				new MutableObject<ILogicalExpression>(f));
+		a.getInputs().add(topOp);
 
-        return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, assignedVar);
 
-    }
+	}
 
-    private static boolean expressionNeedsNoNesting(Expression expr) {
-        Kind k = expr.getKind();
-        return k == Kind.LITERAL_EXPRESSION || k == Kind.LIST_CONSTRUCTOR_EXPRESSION
-                || k == Kind.RECORD_CONSTRUCTOR_EXPRESSION || k == Kind.VARIABLE_EXPRESSION
-                || k == Kind.CALL_EXPRESSION || k == Kind.OP_EXPRESSION || k == Kind.FIELD_ACCESSOR_EXPRESSION
-                || k == Kind.INDEX_ACCESSOR_EXPRESSION || k == Kind.UNARY_EXPRESSION;
-    }
+	private static boolean expressionNeedsNoNesting(Expression expr) {
+		Kind k = expr.getKind();
+		return k == Kind.LITERAL_EXPRESSION
+				|| k == Kind.LIST_CONSTRUCTOR_EXPRESSION
+				|| k == Kind.RECORD_CONSTRUCTOR_EXPRESSION
+				|| k == Kind.VARIABLE_EXPRESSION || k == Kind.CALL_EXPRESSION
+				|| k == Kind.OP_EXPRESSION
+				|| k == Kind.FIELD_ACCESSOR_EXPRESSION
+				|| k == Kind.INDEX_ACCESSOR_EXPRESSION
+				|| k == Kind.UNARY_EXPRESSION;
+	}
 
-    private <T> ArrayList<T> mkSingletonArrayList(T item) {
-        ArrayList<T> array = new ArrayList<T>(1);
-        array.add(item);
-        return array;
-    }
+	private <T> ArrayList<T> mkSingletonArrayList(T item) {
+		ArrayList<T> array = new ArrayList<T>(1);
+		array.add(item);
+		return array;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitTypeDecl(TypeDecl td, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitTypeDecl(TypeDecl td,
+			Mutable<ILogicalOperator> arg) throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitRecordTypeDefiniton(RecordTypeDefinition tre,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitRecordTypeDefiniton(
+			RecordTypeDefinition tre, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitTypeReferenceExpression(TypeReferenceExpression tre,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitTypeReferenceExpression(
+			TypeReferenceExpression tre, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitNodegroupDecl(NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitNodegroupDecl(
+			NodegroupDecl ngd, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLoadFromFileStatement(LoadFromFileStatement stmtLoad,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLoadFromFileStatement(
+			LoadFromFileStatement stmtLoad, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitWriteFromQueryResultStatement(
-            WriteFromQueryResultStatement stmtLoad, Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitWriteFromQueryResultStatement(
+			WriteFromQueryResultStatement stmtLoad,
+			Mutable<ILogicalOperator> arg) throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDropStatement(DropStatement del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDropStatement(
+			DropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitCreateIndexStatement(CreateIndexStatement cis,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitCreateIndexStatement(
+			CreateIndexStatement cis, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitOrderedListTypeDefiniton(OrderedListTypeDefinition olte,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitOrderedListTypeDefiniton(
+			OrderedListTypeDefinition olte, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUnorderedListTypeDefiniton(UnorderedListTypeDefinition ulte,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUnorderedListTypeDefiniton(
+			UnorderedListTypeDefinition ulte, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableClause(MetaVariableClause mc,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        return new Pair<ILogicalOperator, LogicalVariable>(metaScopeOp.get(mc.getVar()), null);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableClause(
+			MetaVariableClause mc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		return new Pair<ILogicalOperator, LogicalVariable>(metaScopeOp.get(mc
+				.getVar()), null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitJoinClause(JoinClause jc, Mutable<ILogicalOperator> tupSource)
-            throws AsterixException {
-        // Pair<ILogicalOperator, LogicalVariable> leftSide =
-        // jc.getLeftExpr().accept(this, tupSource);
-        Mutable<ILogicalOperator> opRef = tupSource;
-        Pair<ILogicalOperator, LogicalVariable> leftSide = null;
-        for (Clause c : jc.getLeftClauses()) {
-            leftSide = c.accept(this, opRef);
-            opRef = new MutableObject<ILogicalOperator>(leftSide.first);
-        }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitJoinClause(
+			JoinClause jc, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		// Pair<ILogicalOperator, LogicalVariable> leftSide =
+		// jc.getLeftExpr().accept(this, tupSource);
+		Mutable<ILogicalOperator> opRef = tupSource;
+		Pair<ILogicalOperator, LogicalVariable> leftSide = null;
+		for (Clause c : jc.getLeftClauses()) {
+			leftSide = c.accept(this, opRef);
+			opRef = new MutableObject<ILogicalOperator>(leftSide.first);
+		}
 
-        // Pair<ILogicalOperator, LogicalVariable> rightSide =
-        // jc.getRightExpr().accept(this, tupSource);
-        opRef = tupSource;
-        Pair<ILogicalOperator, LogicalVariable> rightSide = null;
-        for (Clause c : jc.getRightClauses()) {
-            rightSide = c.accept(this, opRef);
-            opRef = new MutableObject<ILogicalOperator>(rightSide.first);
-        }
+		// Pair<ILogicalOperator, LogicalVariable> rightSide =
+		// jc.getRightExpr().accept(this, tupSource);
+		opRef = tupSource;
+		Pair<ILogicalOperator, LogicalVariable> rightSide = null;
+		for (Clause c : jc.getRightClauses()) {
+			rightSide = c.accept(this, opRef);
+			opRef = new MutableObject<ILogicalOperator>(rightSide.first);
+		}
 
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> whereCond = aqlExprToAlgExpression(jc.getWhereExpr(),
-                tupSource);
+		Pair<ILogicalExpression, Mutable<ILogicalOperator>> whereCond = aqlExprToAlgExpression(
+				jc.getWhereExpr(), tupSource);
 
-        AbstractBinaryJoinOperator join;
-        switch (jc.getKind()) {
-            case INNER: {
-                join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
-                break;
-            }
-            case LEFT_OUTER: {
-                join = new LeftOuterJoinOperator(new MutableObject<ILogicalExpression>(whereCond.first));
-                break;
-            }
-            default: {
-                throw new IllegalStateException();
-            }
-        }
-        join.getInputs().add(new MutableObject<ILogicalOperator>(leftSide.first));
-        join.getInputs().add(new MutableObject<ILogicalOperator>(rightSide.first));
-        return new Pair<ILogicalOperator, LogicalVariable>(join, null);
-    }
+		AbstractBinaryJoinOperator join;
+		switch (jc.getKind()) {
+		case INNER: {
+			join = new InnerJoinOperator(new MutableObject<ILogicalExpression>(
+					whereCond.first));
+			break;
+		}
+		case LEFT_OUTER: {
+			join = new LeftOuterJoinOperator(
+					new MutableObject<ILogicalExpression>(whereCond.first));
+			break;
+		}
+		default: {
+			throw new IllegalStateException();
+		}
+		}
+		join.getInputs().add(
+				new MutableObject<ILogicalOperator>(leftSide.first));
+		join.getInputs().add(
+				new MutableObject<ILogicalOperator>(rightSide.first));
+		return new Pair<ILogicalOperator, LogicalVariable>(join, null);
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableExpr(MetaVariableExpr me,
-            Mutable<ILogicalOperator> tupSource) throws AsterixException {
-        LogicalVariable var = context.newVar();
-        AssignOperator a = new AssignOperator(var, new MutableObject<ILogicalExpression>(
-                metaScopeExp.getVariableReferenceExpression(me.getVar())));
-        a.getInputs().add(tupSource);
-        return new Pair<ILogicalOperator, LogicalVariable>(a, var);
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitMetaVariableExpr(
+			MetaVariableExpr me, Mutable<ILogicalOperator> tupSource)
+			throws AsterixException {
+		LogicalVariable var = context.newVar();
+		AssignOperator a = new AssignOperator(var,
+				new MutableObject<ILogicalExpression>(metaScopeExp
+						.getVariableReferenceExpression(me.getVar())));
+		a.getInputs().add(tupSource);
+		return new Pair<ILogicalOperator, LogicalVariable>(a, var);
+	}
 
-    public void addOperatorToMetaScope(Identifier id, ILogicalOperator op) {
-        metaScopeOp.put(id, op);
-    }
+	public void addOperatorToMetaScope(Identifier id, ILogicalOperator op) {
+		metaScopeOp.put(id, op);
+	}
 
-    public void addVariableToMetaScope(Identifier id, LogicalVariable var) {
-        metaScopeExp.put(id, var);
-    }
+	public void addVariableToMetaScope(Identifier id, LogicalVariable var) {
+		metaScopeExp.put(id, var);
+	}
 
-    private ILogicalExpression makeUnnestExpression(ILogicalExpression expr) {
-        switch (expr.getExpressionTag()) {
-            case VARIABLE: {
-                return new UnnestingFunctionCallExpression(
-                        FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
-                        new MutableObject<ILogicalExpression>(expr));
-            }
-            case FUNCTION_CALL: {
-                AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
-                if (fce.getKind() == FunctionKind.UNNEST) {
-                    return expr;
-                } else {
-                    return new UnnestingFunctionCallExpression(
-                            FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
-                            new MutableObject<ILogicalExpression>(expr));
-                }
-            }
-            default: {
-                return expr;
-            }
-        }
-    }
+	private ILogicalExpression makeUnnestExpression(ILogicalExpression expr) {
+		switch (expr.getExpressionTag()) {
+		case VARIABLE: {
+			return new UnnestingFunctionCallExpression(
+					FunctionUtils
+							.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
+					new MutableObject<ILogicalExpression>(expr));
+		}
+		case FUNCTION_CALL: {
+			AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
+			if (fce.getKind() == FunctionKind.UNNEST) {
+				return expr;
+			} else {
+				return new UnnestingFunctionCallExpression(
+						FunctionUtils
+								.getFunctionInfo(AsterixBuiltinFunctions.SCAN_COLLECTION),
+						new MutableObject<ILogicalExpression>(expr));
+			}
+		}
+		default: {
+			return expr;
+		}
+		}
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitInsertStatement(InsertStatement insert,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitInsertStatement(
+			InsertStatement insert, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDeleteStatement(DeleteStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDeleteStatement(
+			DeleteStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUpdateStatement(UpdateStatement update,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUpdateStatement(
+			UpdateStatement update, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitUpdateClause(UpdateClause del, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitUpdateClause(
+			UpdateClause del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDataverseDecl(DataverseDecl dv, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDataverseDecl(
+			DataverseDecl dv, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDatasetDecl(DatasetDecl dd, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDatasetDecl(
+			DatasetDecl dd, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitSetStatement(SetStatement ss, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitSetStatement(
+			SetStatement ss, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitWriteStatement(WriteStatement ws, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitWriteStatement(
+			WriteStatement ws, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitLoadFromQueryResultStatement(
-            WriteFromQueryResultStatement stmtLoad, Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitLoadFromQueryResultStatement(
+			WriteFromQueryResultStatement stmtLoad,
+			Mutable<ILogicalOperator> arg) throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitCreateDataverseStatement(CreateDataverseStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitCreateDataverseStatement(
+			CreateDataverseStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitIndexDropStatement(IndexDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitIndexDropStatement(
+			IndexDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitNodeGroupDropStatement(NodeGroupDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitNodeGroupDropStatement(
+			NodeGroupDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitDataverseDropStatement(DataverseDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitDataverseDropStatement(
+			DataverseDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitTypeDropStatement(TypeDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitTypeDropStatement(
+			TypeDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitControlFeedStatement(ControlFeedStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitControlFeedStatement(
+			ControlFeedStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visit(CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
-            throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visit(
+			CreateFunctionStatement cfs, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitFunctionDropStatement(FunctionDropStatement del,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitFunctionDropStatement(
+			FunctionDropStatement del, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-    @Override
-    public Pair<ILogicalOperator, LogicalVariable> visitBeginFeedStatement(BeginFeedStatement bf,
-            Mutable<ILogicalOperator> arg) throws AsterixException {
-        // TODO Auto-generated method stub
-        return null;
-    }
+	@Override
+	public Pair<ILogicalOperator, LogicalVariable> visitBeginFeedStatement(
+			BeginFeedStatement bf, Mutable<ILogicalOperator> arg)
+			throws AsterixException {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/ConstantHelper.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/ConstantHelper.java
index e010d3c..bf2b64a 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/ConstantHelper.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/ConstantHelper.java
@@ -1,21 +1,23 @@
 package edu.uci.ics.asterix.translator;
 
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 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.om.base.ABoolean;
 import edu.uci.ics.asterix.om.base.ADouble;
 import edu.uci.ics.asterix.om.base.AFloat;
 import edu.uci.ics.asterix.om.base.AInt32;
+import edu.uci.ics.asterix.om.base.AInt64;
 import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.base.AString;
 import edu.uci.ics.asterix.om.base.IAObject;
 
 public final class ConstantHelper {
 
-    public static IAObject objectFromLiteral(ILiteral valLiteral) {
+    public static IAObject objectFromLiteral(Literal valLiteral) {
         switch (valLiteral.getLiteralType()) {
             case DOUBLE: {
                 DoubleLiteral d = (DoubleLiteral) valLiteral;
@@ -32,6 +34,10 @@
                 IntegerLiteral il = (IntegerLiteral) valLiteral;
                 return new AInt32(il.getValue());
             }
+            case LONG: {
+                LongIntegerLiteral il = (LongIntegerLiteral) valLiteral;
+                return new AInt64(il.getValue());                
+            }
             case NULL: {
                 return ANull.NULL;
             }
diff --git a/asterix-algebra/src/main/javacc/AQLPlus.jj b/asterix-algebra/src/main/javacc/AQLPlus.jj
index 9a8f783..3422652 100644
--- a/asterix-algebra/src/main/javacc/AQLPlus.jj
+++ b/asterix-algebra/src/main/javacc/AQLPlus.jj
@@ -20,8 +20,9 @@
 import edu.uci.ics.asterix.aql.literal.FloatLiteral;
 import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
 import edu.uci.ics.asterix.aql.literal.FalseLiteral;
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
+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;
@@ -778,8 +779,9 @@
 	{
 		if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
 		{
-			ILiteral lit = ((LiteralExpr)expr).getValue();
-			if(lit.getLiteralType() == ILiteral.Type.INTEGER) {
+			Literal lit = ((LiteralExpr)expr).getValue();
+			if(lit.getLiteralType() == Literal.Type.INTEGER || 
+ 			   lit.getLiteralType() == Literal.Type.LONG) {
 				idx = Integer.valueOf(lit.getStringValue());
 			}	
 			else {
@@ -809,7 +811,7 @@
   Expression expr = null;
 }
 {
-  //ILiteral | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression
+  //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression
 	(
 	  expr =Literal() 
 	   | expr = FunctionCallExpr()
@@ -846,7 +848,11 @@
  	 | <INTEGER_LITERAL>
     {
       t= getToken(0);
-	  lit.setValue(new IntegerLiteral(new Integer(t.image)));
+	  try {
+	      lit.setValue(new IntegerLiteral(new Integer(t.image)));
+	  } catch(NumberFormatException ex) {
+	      lit.setValue(new LongIntegerLiteral(new Long(t.image)));
+	  }
 	}
      | < FLOAT_LITERAL >
     {
@@ -1231,12 +1237,9 @@
 	extendCurrentScope();
 }
 {
-    "let" varExp = Variable()
+    "let" varExp = Variable() ":=" beExp = Expression()
     {
       getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
-	}
-     ":=" beExp = Expression()
-    {
       lc.setVarExpr(varExp);
       lc.setBeExpr(beExp);
       return lc;
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/AsterixHyracksIntegrationUtil.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/AsterixHyracksIntegrationUtil.java
index 83e9991..541edd0 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/AsterixHyracksIntegrationUtil.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/AsterixHyracksIntegrationUtil.java
@@ -22,7 +22,6 @@
 
     public static final int DEFAULT_HYRACKS_CC_CLUSTER_PORT = 1099;
 
-    public static final int FRAME_SIZE = 32768;
 
     private static ClusterControllerService cc;
     private static NodeControllerService nc1;
@@ -46,7 +45,6 @@
         ncConfig1.clusterNetIPAddress = "127.0.0.1";
         ncConfig1.dataIPAddress = "127.0.0.1";
         ncConfig1.nodeId = NC1_ID;
-        ncConfig1.frameSize = FRAME_SIZE;
         nc1 = new NodeControllerService(ncConfig1);
         nc1.start();
 
@@ -56,7 +54,6 @@
         ncConfig2.clusterNetIPAddress = "127.0.0.1";
         ncConfig2.dataIPAddress = "127.0.0.1";
         ncConfig2.nodeId = NC2_ID;
-        ncConfig2.frameSize = FRAME_SIZE;
         nc2 = new NodeControllerService(ncConfig2);
         nc2.start();
 
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/DdlTranslator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/DdlTranslator.java
index dc3fb25..c68817c 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/DdlTranslator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/DdlTranslator.java
@@ -93,922 +93,1090 @@
 
 public class DdlTranslator extends AbstractAqlTranslator {
 
-    private final MetadataTransactionContext mdTxnCtx;
-    private final List<Statement> aqlStatements;
-    private final PrintWriter out;
-    private final SessionConfig pc;
-    private final DisplayFormat pdf;
-    private AqlCompiledMetadataDeclarations compiledDeclarations;
+	private final MetadataTransactionContext mdTxnCtx;
+	private final List<Statement> aqlStatements;
+	private final PrintWriter out;
+	private final SessionConfig pc;
+	private final DisplayFormat pdf;
+	private AqlCompiledMetadataDeclarations compiledDeclarations;
 
-    private static Map<String, BuiltinType> builtinTypeMap;
+	private static Map<String, BuiltinType> builtinTypeMap;
 
-    public DdlTranslator(MetadataTransactionContext mdTxnCtx, List<Statement> aqlStatements, PrintWriter out,
-            SessionConfig pc, DisplayFormat pdf) {
-        this.mdTxnCtx = mdTxnCtx;
-        this.aqlStatements = aqlStatements;
-        this.out = out;
-        this.pc = pc;
-        this.pdf = pdf;
-        builtinTypeMap = AsterixBuiltinTypeMap.getBuiltinTypes();
-    }
+	public DdlTranslator(MetadataTransactionContext mdTxnCtx,
+			List<Statement> aqlStatements, PrintWriter out, SessionConfig pc,
+			DisplayFormat pdf) {
+		this.mdTxnCtx = mdTxnCtx;
+		this.aqlStatements = aqlStatements;
+		this.out = out;
+		this.pc = pc;
+		this.pdf = pdf;
+		builtinTypeMap = AsterixBuiltinTypeMap.getBuiltinTypes();
+	}
 
-    public void translate(IHyracksClientConnection hcc, boolean disconnectFromDataverse) throws AlgebricksException {
-        try {
-            compiledDeclarations = compileMetadata(mdTxnCtx, aqlStatements, true);
-            compileAndExecuteDDLstatements(hcc, mdTxnCtx, disconnectFromDataverse);
-        } catch (Exception e) {
-            throw new AlgebricksException(e);
-        }
-    }
+	public void translate(IHyracksClientConnection hcc,
+			boolean disconnectFromDataverse) throws AlgebricksException {
+		try {
+			compiledDeclarations = compileMetadata(mdTxnCtx, aqlStatements,
+					true);
+			compileAndExecuteDDLstatements(hcc, mdTxnCtx,
+					disconnectFromDataverse);
+		} catch (Exception e) {
+			throw new AlgebricksException(e);
+		}
+	}
 
-    private void compileAndExecuteDDLstatements(IHyracksClientConnection hcc, MetadataTransactionContext mdTxnCtx,
-            boolean disconnectFromDataverse) throws Exception {
-        for (Statement stmt : aqlStatements) {
-            validateOperation(compiledDeclarations, stmt);
-            switch (stmt.getKind()) {
-                case DATAVERSE_DECL: {
-                    checkForDataverseConnection(false);
-                    DataverseDecl dvd = (DataverseDecl) stmt;
-                    String dataverseName = dvd.getDataverseName().getValue();
-                    compiledDeclarations.connectToDataverse(dataverseName);
-                    break;
-                }
+	private void compileAndExecuteDDLstatements(IHyracksClientConnection hcc,
+			MetadataTransactionContext mdTxnCtx, boolean disconnectFromDataverse)
+			throws Exception {
+		for (Statement stmt : aqlStatements) {
+			validateOperation(compiledDeclarations, stmt);
+			switch (stmt.getKind()) {
+			case DATAVERSE_DECL: {
+				checkForDataverseConnection(false);
+				DataverseDecl dvd = (DataverseDecl) stmt;
+				String dataverseName = dvd.getDataverseName().getValue();
+				compiledDeclarations.connectToDataverse(dataverseName);
+				break;
+			}
 
-                case CREATE_DATAVERSE: {
-                    checkForDataverseConnection(false);
-                    CreateDataverseStatement stmtCreateDataverse = (CreateDataverseStatement) stmt;
-                    String dvName = stmtCreateDataverse.getDataverseName().getValue();
-                    Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dvName);
-                    if (dv != null && !stmtCreateDataverse.getIfNotExists()) {
-                        throw new AlgebricksException("A dataverse with this name " + dvName + " already exists.");
-                    }
-                    MetadataManager.INSTANCE.addDataverse(mdTxnCtx,
-                            new Dataverse(dvName, stmtCreateDataverse.getFormat()));
-                    break;
-                }
+			case CREATE_DATAVERSE: {
+				checkForDataverseConnection(false);
+				CreateDataverseStatement stmtCreateDataverse = (CreateDataverseStatement) stmt;
+				String dvName = stmtCreateDataverse.getDataverseName()
+						.getValue();
+				Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx,
+						dvName);
+				if (dv != null && !stmtCreateDataverse.getIfNotExists()) {
+					throw new AlgebricksException("A dataverse with this name "
+							+ dvName + " already exists.");
+				}
+				MetadataManager.INSTANCE.addDataverse(mdTxnCtx, new Dataverse(
+						dvName, stmtCreateDataverse.getFormat()));
+				break;
+			}
 
-                case DATASET_DECL: {
-                    checkForDataverseConnection(true);
-                    DatasetDecl dd = (DatasetDecl) stmt;
-                    String datasetName = dd.getName().getValue();
-                    DatasetType dsType = dd.getDatasetType();
-                    String itemTypeName = null;
-                    IDatasetDetails datasetDetails = null;
-                    Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                            datasetName);
-                    if (ds != null) {
-                        if (dd.getIfNotExists()) {
-                            continue;
-                        } else {
-                            throw new AlgebricksException("A dataset with this name " + datasetName
-                                    + " already exists.");
-                        }
-                    }
-                    itemTypeName = dd.getItemTypeName().getValue();
-                    Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
-                            compiledDeclarations.getDataverseName(), itemTypeName);
-                    if (dt == null) {
-                        throw new AlgebricksException(": type " + itemTypeName + " could not be found.");
-                    }
-                    switch (dd.getDatasetType()) {
-                        case INTERNAL: {
-                            IAType itemType = dt.getDatatype();
-                            if (itemType.getTypeTag() != ATypeTag.RECORD) {
-                                throw new AlgebricksException("Can only partition ARecord's.");
-                            }
-                            List<String> partitioningExprs = ((InternalDetailsDecl) dd.getDatasetDetailsDecl())
-                                    .getPartitioningExprs();
-                            String ngName = ((InternalDetailsDecl) dd.getDatasetDetailsDecl()).getNodegroupName()
-                                    .getValue();
-                            datasetDetails = new InternalDatasetDetails(InternalDatasetDetails.FileStructure.BTREE,
-                                    InternalDatasetDetails.PartitioningStrategy.HASH, partitioningExprs,
-                                    partitioningExprs, ngName);
-                            break;
-                        }
-                        case EXTERNAL: {
-                            String adapter = ((ExternalDetailsDecl) dd.getDatasetDetailsDecl()).getAdapter();
-                            Map<String, String> properties = ((ExternalDetailsDecl) dd.getDatasetDetailsDecl())
-                                    .getProperties();
-                            datasetDetails = new ExternalDatasetDetails(adapter, properties);
-                            break;
-                        }
-                        case FEED: {
-                            IAType itemType = dt.getDatatype();
-                            if (itemType.getTypeTag() != ATypeTag.RECORD) {
-                                throw new AlgebricksException("Can only partition ARecord's.");
-                            }
-                            List<String> partitioningExprs = ((FeedDetailsDecl) dd.getDatasetDetailsDecl())
-                                    .getPartitioningExprs();
-                            String ngName = ((FeedDetailsDecl) dd.getDatasetDetailsDecl()).getNodegroupName()
-                                    .getValue();
-                            String adapter = ((FeedDetailsDecl) dd.getDatasetDetailsDecl()).getAdapterClassname();
-                            Map<String, String> properties = ((FeedDetailsDecl) dd.getDatasetDetailsDecl())
-                                    .getProperties();
-                            String functionIdentifier = ((FeedDetailsDecl) dd.getDatasetDetailsDecl())
-                                    .getFunctionIdentifier();
-                            datasetDetails = new FeedDatasetDetails(InternalDatasetDetails.FileStructure.BTREE,
-                                    InternalDatasetDetails.PartitioningStrategy.HASH, partitioningExprs,
-                                    partitioningExprs, ngName, adapter, properties, functionIdentifier,
-                                    FeedDatasetDetails.FeedState.INACTIVE.toString());
-                            break;
-                        }
-                    }
-                    MetadataManager.INSTANCE.addDataset(mdTxnCtx, new Dataset(compiledDeclarations.getDataverseName(),
-                            datasetName, itemTypeName, datasetDetails, dsType));
-                    if (dd.getDatasetType() == DatasetType.INTERNAL || dd.getDatasetType() == DatasetType.FEED) {
-                        runCreateDatasetJob(hcc, datasetName);
-                    }
-                    break;
-                }
+			case DATASET_DECL: {
+				checkForDataverseConnection(true);
+				DatasetDecl dd = (DatasetDecl) stmt;
+				String datasetName = dd.getName().getValue();
+				DatasetType dsType = dd.getDatasetType();
+				String itemTypeName = null;
+				IDatasetDetails datasetDetails = null;
+				Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx,
+						compiledDeclarations.getDataverseName(), datasetName);
+				if (ds != null) {
+					if (dd.getIfNotExists()) {
+						continue;
+					} else {
+						throw new AlgebricksException(
+								"A dataset with this name " + datasetName
+										+ " already exists.");
+					}
+				}
+				itemTypeName = dd.getItemTypeName().getValue();
+				Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
+						compiledDeclarations.getDataverseName(), itemTypeName);
+				if (dt == null) {
+					throw new AlgebricksException(": type " + itemTypeName
+							+ " could not be found.");
+				}
+				switch (dd.getDatasetType()) {
+				case INTERNAL: {
+					IAType itemType = dt.getDatatype();
+					if (itemType.getTypeTag() != ATypeTag.RECORD) {
+						throw new AlgebricksException(
+								"Can only partition ARecord's.");
+					}
+					List<String> partitioningExprs = ((InternalDetailsDecl) dd
+							.getDatasetDetailsDecl()).getPartitioningExprs();
+					String ngName = ((InternalDetailsDecl) dd
+							.getDatasetDetailsDecl()).getNodegroupName()
+							.getValue();
+					datasetDetails = new InternalDatasetDetails(
+							InternalDatasetDetails.FileStructure.BTREE,
+							InternalDatasetDetails.PartitioningStrategy.HASH,
+							partitioningExprs, partitioningExprs, ngName);
+					break;
+				}
+				case EXTERNAL: {
+					String adapter = ((ExternalDetailsDecl) dd
+							.getDatasetDetailsDecl()).getAdapter();
+					Map<String, String> properties = ((ExternalDetailsDecl) dd
+							.getDatasetDetailsDecl()).getProperties();
+					datasetDetails = new ExternalDatasetDetails(adapter,
+							properties);
+					break;
+				}
+				case FEED: {
+					IAType itemType = dt.getDatatype();
+					if (itemType.getTypeTag() != ATypeTag.RECORD) {
+						throw new AlgebricksException(
+								"Can only partition ARecord's.");
+					}
+					List<String> partitioningExprs = ((FeedDetailsDecl) dd
+							.getDatasetDetailsDecl()).getPartitioningExprs();
+					String ngName = ((FeedDetailsDecl) dd
+							.getDatasetDetailsDecl()).getNodegroupName()
+							.getValue();
+					String adapter = ((FeedDetailsDecl) dd
+							.getDatasetDetailsDecl()).getAdapterClassname();
+					Map<String, String> properties = ((FeedDetailsDecl) dd
+							.getDatasetDetailsDecl()).getProperties();
+					String functionIdentifier = ((FeedDetailsDecl) dd
+							.getDatasetDetailsDecl()).getFunctionIdentifier();
+					datasetDetails = new FeedDatasetDetails(
+							InternalDatasetDetails.FileStructure.BTREE,
+							InternalDatasetDetails.PartitioningStrategy.HASH,
+							partitioningExprs, partitioningExprs, ngName,
+							adapter, properties, functionIdentifier,
+							FeedDatasetDetails.FeedState.INACTIVE.toString());
+					break;
+				}
+				}
+				MetadataManager.INSTANCE.addDataset(mdTxnCtx, new Dataset(
+						compiledDeclarations.getDataverseName(), datasetName,
+						itemTypeName, datasetDetails, dsType));
+				if (dd.getDatasetType() == DatasetType.INTERNAL
+						|| dd.getDatasetType() == DatasetType.FEED) {
+					runCreateDatasetJob(hcc, datasetName);
+				}
+				break;
+			}
 
-                case CREATE_INDEX: {
-                    checkForDataverseConnection(true);
-                    CreateIndexStatement stmtCreateIndex = (CreateIndexStatement) stmt;
-                    String datasetName = stmtCreateIndex.getDatasetName().getValue();
-                    Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                            datasetName);
-                    if (ds == null) {
-                        throw new AlgebricksException("There is no dataset with this name " + datasetName);
-                    }
-                    String indexName = stmtCreateIndex.getIndexName().getValue();
-                    Index idx = MetadataManager.INSTANCE.getIndex(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                            datasetName, indexName);
-                    if (idx != null) {
-                        if (!stmtCreateIndex.getIfNotExists()) {
-                            throw new AlgebricksException("An index with this name " + indexName + " already exists.");
-                        } else {
-                            stmtCreateIndex.setNeedToCreate(false);
-                        }
-                    } else {
-                        MetadataManager.INSTANCE.addIndex(mdTxnCtx, new Index(compiledDeclarations.getDataverseName(),
-                                datasetName, indexName, stmtCreateIndex.getIndexType(),
-                                stmtCreateIndex.getFieldExprs(), stmtCreateIndex.getGramLength(), false));
-                        runCreateIndexJob(hcc, stmtCreateIndex);
-                    }
-                    break;
-                }
-                case TYPE_DECL: {
-                    checkForDataverseConnection(true);
-                    TypeDecl stmtCreateType = (TypeDecl) stmt;
-                    String typeName = stmtCreateType.getIdent().getValue();
-                    Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
-                            compiledDeclarations.getDataverseName(), typeName);
-                    if (dt != null) {
-                        if (!stmtCreateType.getIfNotExists())
-                            throw new AlgebricksException("A datatype with this name " + typeName + " already exists.");
-                    } else {
-                        if (builtinTypeMap.get(typeName) != null) {
-                            throw new AlgebricksException("Cannot redefine builtin type " + typeName + ".");
-                        } else {
-                            Map<String, IAType> typeMap = computeTypes(mdTxnCtx, (TypeDecl) stmt);
-                            IAType type = typeMap.get(typeName);
-                            MetadataManager.INSTANCE.addDatatype(mdTxnCtx,
-                                    new Datatype(compiledDeclarations.getDataverseName(), typeName, type, false));
-                        }
-                    }
-                    break;
-                }
-                case NODEGROUP_DECL: {
-                    NodegroupDecl stmtCreateNodegroup = (NodegroupDecl) stmt;
-                    String ngName = stmtCreateNodegroup.getNodegroupName().getValue();
-                    NodeGroup ng = MetadataManager.INSTANCE.getNodegroup(mdTxnCtx, ngName);
-                    if (ng != null) {
-                        if (!stmtCreateNodegroup.getIfNotExists())
-                            throw new AlgebricksException("A nodegroup with this name " + ngName + " already exists.");
-                    } else {
-                        List<Identifier> ncIdentifiers = stmtCreateNodegroup.getNodeControllerNames();
-                        List<String> ncNames = new ArrayList<String>(ncIdentifiers.size());
-                        for (Identifier id : ncIdentifiers) {
-                            ncNames.add(id.getValue());
-                        }
-                        MetadataManager.INSTANCE.addNodegroup(mdTxnCtx, new NodeGroup(ngName, ncNames));
-                    }
-                    break;
-                }
-                // drop statements
-                case DATAVERSE_DROP: {
-                    DataverseDropStatement stmtDelete = (DataverseDropStatement) stmt;
-                    String dvName = stmtDelete.getDataverseName().getValue();
-                    if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(ARTIFACT_KIND.DATAVERSE, dvName)) {
-                        throw new AsterixException("Invalid Operation cannot drop dataverse " + dvName
-                                + " (protected by system)");
-                    }
+			case CREATE_INDEX: {
+				checkForDataverseConnection(true);
+				CreateIndexStatement stmtCreateIndex = (CreateIndexStatement) stmt;
+				String datasetName = stmtCreateIndex.getDatasetName()
+						.getValue();
+				Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx,
+						compiledDeclarations.getDataverseName(), datasetName);
+				if (ds == null) {
+					throw new AlgebricksException(
+							"There is no dataset with this name " + datasetName);
+				}
+				String indexName = stmtCreateIndex.getIndexName().getValue();
+				Index idx = MetadataManager.INSTANCE.getIndex(mdTxnCtx,
+						compiledDeclarations.getDataverseName(), datasetName,
+						indexName);
+				if (idx != null) {
+					if (!stmtCreateIndex.getIfNotExists()) {
+						throw new AlgebricksException(
+								"An index with this name " + indexName
+										+ " already exists.");
+					} else {
+						stmtCreateIndex.setNeedToCreate(false);
+					}
+				} else {
+					MetadataManager.INSTANCE.addIndex(
+							mdTxnCtx,
+							new Index(compiledDeclarations.getDataverseName(),
+									datasetName, indexName, stmtCreateIndex
+											.getIndexType(), stmtCreateIndex
+											.getFieldExprs(), stmtCreateIndex
+											.getGramLength(), false));
+					runCreateIndexJob(hcc, stmtCreateIndex);
+				}
+				break;
+			}
+			case TYPE_DECL: {
+				checkForDataverseConnection(true);
+				TypeDecl stmtCreateType = (TypeDecl) stmt;
+				String typeName = stmtCreateType.getIdent().getValue();
+				Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
+						compiledDeclarations.getDataverseName(), typeName);
+				if (dt != null) {
+					if (!stmtCreateType.getIfNotExists())
+						throw new AlgebricksException(
+								"A datatype with this name " + typeName
+										+ " already exists.");
+				} else {
+					if (builtinTypeMap.get(typeName) != null) {
+						throw new AlgebricksException(
+								"Cannot redefine builtin type " + typeName
+										+ ".");
+					} else {
+						Map<String, IAType> typeMap = computeTypes(mdTxnCtx,
+								(TypeDecl) stmt);
+						IAType type = typeMap.get(typeName);
+						MetadataManager.INSTANCE.addDatatype(
+								mdTxnCtx,
+								new Datatype(compiledDeclarations
+										.getDataverseName(), typeName, type,
+										false));
+					}
+				}
+				break;
+			}
+			case NODEGROUP_DECL: {
+				NodegroupDecl stmtCreateNodegroup = (NodegroupDecl) stmt;
+				String ngName = stmtCreateNodegroup.getNodegroupName()
+						.getValue();
+				NodeGroup ng = MetadataManager.INSTANCE.getNodegroup(mdTxnCtx,
+						ngName);
+				if (ng != null) {
+					if (!stmtCreateNodegroup.getIfNotExists())
+						throw new AlgebricksException(
+								"A nodegroup with this name " + ngName
+										+ " already exists.");
+				} else {
+					List<Identifier> ncIdentifiers = stmtCreateNodegroup
+							.getNodeControllerNames();
+					List<String> ncNames = new ArrayList<String>(
+							ncIdentifiers.size());
+					for (Identifier id : ncIdentifiers) {
+						ncNames.add(id.getValue());
+					}
+					MetadataManager.INSTANCE.addNodegroup(mdTxnCtx,
+							new NodeGroup(ngName, ncNames));
+				}
+				break;
+			}
+			// drop statements
+			case DATAVERSE_DROP: {
+				DataverseDropStatement stmtDelete = (DataverseDropStatement) stmt;
+				String dvName = stmtDelete.getDataverseName().getValue();
+				if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(
+						ARTIFACT_KIND.DATAVERSE, dvName)) {
+					throw new AsterixException(
+							"Invalid Operation cannot drop dataverse " + dvName
+									+ " (protected by system)");
+				}
 
-                    if (compiledDeclarations.isConnectedToDataverse())
-                        compiledDeclarations.disconnectFromDataverse();
-                    checkForDataverseConnection(false);
+				if (compiledDeclarations.isConnectedToDataverse())
+					compiledDeclarations.disconnectFromDataverse();
+				checkForDataverseConnection(false);
 
-                    Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dvName);
-                    if (dv == null) {
-                        if (!stmtDelete.getIfExists()) {
-                            throw new AlgebricksException("There is no dataverse with this name " + dvName + ".");
-                        }
-                    } else {
-                        compiledDeclarations.connectToDataverse(dvName);
-                        List<Dataset> datasets = MetadataManager.INSTANCE.getDataverseDatasets(mdTxnCtx, dvName);
-                        for (int j = 0; j < datasets.size(); j++) {
-                            String datasetName = datasets.get(j).getDatasetName();
-                            DatasetType dsType = datasets.get(j).getDatasetType();
-                            if (dsType == DatasetType.INTERNAL || dsType == DatasetType.FEED) {
-                                List<Index> indexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx, dvName,
-                                        datasetName);
-                                for (int k = 0; k < indexes.size(); k++) {
-                                    if (indexes.get(k).isSecondaryIndex()) {
-                                        compileIndexDropStatement(hcc, mdTxnCtx, datasetName, indexes.get(k)
-                                                .getIndexName());
-                                    }
-                                }
-                            }
-                            compileDatasetDropStatement(hcc, mdTxnCtx, datasetName);
-                        }
-                        MetadataManager.INSTANCE.dropDataverse(mdTxnCtx, dvName);
-                        if (compiledDeclarations.isConnectedToDataverse())
-                            compiledDeclarations.disconnectFromDataverse();
-                    }
-                    break;
-                }
-                case DATASET_DROP: {
-                    checkForDataverseConnection(true);
-                    DropStatement stmtDelete = (DropStatement) stmt;
-                    String datasetName = stmtDelete.getDatasetName().getValue();
-                    if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(ARTIFACT_KIND.DATASET, datasetName)) {
-                        throw new AsterixException("Invalid Operation cannot drop dataset " + datasetName
-                                + " (protected by system)");
-                    }
-                    Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                            datasetName);
-                    if (ds == null) {
-                        if (!stmtDelete.getIfExists())
-                            throw new AlgebricksException("There is no dataset with this name " + datasetName + ".");
-                    } else {
-                        if (ds.getDatasetType() == DatasetType.INTERNAL || ds.getDatasetType() == DatasetType.FEED) {
-                            List<Index> indexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx,
-                                    compiledDeclarations.getDataverseName(), datasetName);
-                            for (int j = 0; j < indexes.size(); j++) {
-                                if (indexes.get(j).isPrimaryIndex()) {
-                                    compileIndexDropStatement(hcc, mdTxnCtx, datasetName, indexes.get(j).getIndexName());
-                                }
-                            }
-                        }
-                        compileDatasetDropStatement(hcc, mdTxnCtx, datasetName);
-                    }
-                    break;
-                }
-                case INDEX_DROP: {
-                    checkForDataverseConnection(true);
-                    IndexDropStatement stmtDelete = (IndexDropStatement) stmt;
-                    String datasetName = stmtDelete.getDatasetName().getValue();
-                    Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                            datasetName);
-                    if (ds == null)
-                        throw new AlgebricksException("There is no dataset with this name " + datasetName + ".");
-                    if (ds.getDatasetType() == DatasetType.INTERNAL || ds.getDatasetType() == DatasetType.FEED) {
-                        String indexName = stmtDelete.getIndexName().getValue();
-                        Index idx = MetadataManager.INSTANCE.getIndex(mdTxnCtx,
-                                compiledDeclarations.getDataverseName(), datasetName, indexName);
-                        if (idx == null) {
-                            if (!stmtDelete.getIfExists())
-                                throw new AlgebricksException("There is no index with this name " + indexName + ".");
-                        } else
-                            compileIndexDropStatement(hcc, mdTxnCtx, datasetName, indexName);
-                    } else {
-                        throw new AlgebricksException(datasetName
-                                + " is an external dataset. Indexes are not maintained for external datasets.");
-                    }
-                    break;
-                }
-                case TYPE_DROP: {
-                    checkForDataverseConnection(true);
-                    TypeDropStatement stmtDelete = (TypeDropStatement) stmt;
-                    String typeName = stmtDelete.getTypeName().getValue();
-                    Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
-                            compiledDeclarations.getDataverseName(), typeName);
-                    if (dt == null) {
-                        if (!stmtDelete.getIfExists())
-                            throw new AlgebricksException("There is no datatype with this name " + typeName + ".");
-                    } else
-                        MetadataManager.INSTANCE.dropDatatype(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                                typeName);
-                    break;
-                }
-                case NODEGROUP_DROP: {
-                    NodeGroupDropStatement stmtDelete = (NodeGroupDropStatement) stmt;
-                    String nodegroupName = stmtDelete.getNodeGroupName().getValue();
-                    if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(ARTIFACT_KIND.NODEGROUP, nodegroupName)) {
-                        throw new AsterixException("Invalid Operation cannot drop nodegroup " + nodegroupName
-                                + " (protected by system)");
-                    }
-                    NodeGroup ng = MetadataManager.INSTANCE.getNodegroup(mdTxnCtx, nodegroupName);
-                    if (ng == null) {
-                        if (!stmtDelete.getIfExists())
-                            throw new AlgebricksException("There is no nodegroup with this name " + nodegroupName + ".");
-                    } else
-                        MetadataManager.INSTANCE.dropNodegroup(mdTxnCtx, nodegroupName);
-                    break;
-                }
+				Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx,
+						dvName);
+				if (dv == null) {
+					if (!stmtDelete.getIfExists()) {
+						throw new AlgebricksException(
+								"There is no dataverse with this name "
+										+ dvName + ".");
+					}
+				} else {
+					compiledDeclarations.connectToDataverse(dvName);
+					List<Dataset> datasets = MetadataManager.INSTANCE
+							.getDataverseDatasets(mdTxnCtx, dvName);
+					for (int j = 0; j < datasets.size(); j++) {
+						String datasetName = datasets.get(j).getDatasetName();
+						DatasetType dsType = datasets.get(j).getDatasetType();
+						if (dsType == DatasetType.INTERNAL
+								|| dsType == DatasetType.FEED) {
+							List<Index> indexes = MetadataManager.INSTANCE
+									.getDatasetIndexes(mdTxnCtx, dvName,
+											datasetName);
+							for (int k = 0; k < indexes.size(); k++) {
+								if (indexes.get(k).isSecondaryIndex()) {
+									compileIndexDropStatement(hcc, mdTxnCtx,
+											datasetName, indexes.get(k)
+													.getIndexName());
+								}
+							}
+						}
+						compileDatasetDropStatement(hcc, mdTxnCtx, datasetName);
+					}
+					MetadataManager.INSTANCE.dropDataverse(mdTxnCtx, dvName);
+					if (compiledDeclarations.isConnectedToDataverse())
+						compiledDeclarations.disconnectFromDataverse();
+				}
+				break;
+			}
+			case DATASET_DROP: {
+				checkForDataverseConnection(true);
+				DropStatement stmtDelete = (DropStatement) stmt;
+				String datasetName = stmtDelete.getDatasetName().getValue();
+				if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(
+						ARTIFACT_KIND.DATASET, datasetName)) {
+					throw new AsterixException(
+							"Invalid Operation cannot drop dataset "
+									+ datasetName + " (protected by system)");
+				}
+				Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx,
+						compiledDeclarations.getDataverseName(), datasetName);
+				if (ds == null) {
+					if (!stmtDelete.getIfExists())
+						throw new AlgebricksException(
+								"There is no dataset with this name "
+										+ datasetName + ".");
+				} else {
+					if (ds.getDatasetType() == DatasetType.INTERNAL
+							|| ds.getDatasetType() == DatasetType.FEED) {
+						List<Index> indexes = MetadataManager.INSTANCE
+								.getDatasetIndexes(
+										mdTxnCtx,
+										compiledDeclarations.getDataverseName(),
+										datasetName);
+						for (int j = 0; j < indexes.size(); j++) {
+							if (indexes.get(j).isPrimaryIndex()) {
+								compileIndexDropStatement(hcc, mdTxnCtx,
+										datasetName, indexes.get(j)
+												.getIndexName());
+							}
+						}
+					}
+					compileDatasetDropStatement(hcc, mdTxnCtx, datasetName);
+				}
+				break;
+			}
+			case INDEX_DROP: {
+				checkForDataverseConnection(true);
+				IndexDropStatement stmtDelete = (IndexDropStatement) stmt;
+				String datasetName = stmtDelete.getDatasetName().getValue();
+				Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx,
+						compiledDeclarations.getDataverseName(), datasetName);
+				if (ds == null)
+					throw new AlgebricksException(
+							"There is no dataset with this name " + datasetName
+									+ ".");
+				if (ds.getDatasetType() == DatasetType.INTERNAL
+						|| ds.getDatasetType() == DatasetType.FEED) {
+					String indexName = stmtDelete.getIndexName().getValue();
+					Index idx = MetadataManager.INSTANCE.getIndex(mdTxnCtx,
+							compiledDeclarations.getDataverseName(),
+							datasetName, indexName);
+					if (idx == null) {
+						if (!stmtDelete.getIfExists())
+							throw new AlgebricksException(
+									"There is no index with this name "
+											+ indexName + ".");
+					} else
+						compileIndexDropStatement(hcc, mdTxnCtx, datasetName,
+								indexName);
+				} else {
+					throw new AlgebricksException(
+							datasetName
+									+ " is an external dataset. Indexes are not maintained for external datasets.");
+				}
+				break;
+			}
+			case TYPE_DROP: {
+				checkForDataverseConnection(true);
+				TypeDropStatement stmtDelete = (TypeDropStatement) stmt;
+				String typeName = stmtDelete.getTypeName().getValue();
+				Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
+						compiledDeclarations.getDataverseName(), typeName);
+				if (dt == null) {
+					if (!stmtDelete.getIfExists())
+						throw new AlgebricksException(
+								"There is no datatype with this name "
+										+ typeName + ".");
+				} else
+					MetadataManager.INSTANCE.dropDatatype(mdTxnCtx,
+							compiledDeclarations.getDataverseName(), typeName);
+				break;
+			}
+			case NODEGROUP_DROP: {
+				NodeGroupDropStatement stmtDelete = (NodeGroupDropStatement) stmt;
+				String nodegroupName = stmtDelete.getNodeGroupName().getValue();
+				if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(
+						ARTIFACT_KIND.NODEGROUP, nodegroupName)) {
+					throw new AsterixException(
+							"Invalid Operation cannot drop nodegroup "
+									+ nodegroupName + " (protected by system)");
+				}
+				NodeGroup ng = MetadataManager.INSTANCE.getNodegroup(mdTxnCtx,
+						nodegroupName);
+				if (ng == null) {
+					if (!stmtDelete.getIfExists())
+						throw new AlgebricksException(
+								"There is no nodegroup with this name "
+										+ nodegroupName + ".");
+				} else
+					MetadataManager.INSTANCE.dropNodegroup(mdTxnCtx,
+							nodegroupName);
+				break;
+			}
 
-                case CREATE_FUNCTION: {
-                    CreateFunctionStatement cfs = (CreateFunctionStatement) stmt;
-                    Function function = new Function(compiledDeclarations.getDataverseName(), cfs
-                            .getFunctionIdentifier().getFunctionName(), cfs.getFunctionIdentifier().getArity(),
-                            cfs.getParamList(), cfs.getFunctionBody());
-                    try {
-                        FunctionUtils.getFunctionDecl(function);
-                    } catch (Exception e) {
-                        throw new AsterixException("Unable to compile function definition", e);
-                    }
-                    MetadataManager.INSTANCE.addFunction(mdTxnCtx, new Function(
-                            compiledDeclarations.getDataverseName(), cfs.getFunctionIdentifier().getFunctionName(), cfs
-                                    .getFunctionIdentifier().getArity(), cfs.getParamList(), cfs.getFunctionBody()));
-                    break;
-                }
+			case CREATE_FUNCTION: {
+				CreateFunctionStatement cfs = (CreateFunctionStatement) stmt;
+				Function function = new Function(
+						compiledDeclarations.getDataverseName(), cfs
+								.getFunctionIdentifier().getFunctionName(), cfs
+								.getFunctionIdentifier().getArity(),
+						cfs.getParamList(), cfs.getFunctionBody());
+				try {
+					FunctionUtils.getFunctionDecl(function);
+				} catch (Exception e) {
+					throw new AsterixException(
+							"Unable to compile function definition", e);
+				}
+				MetadataManager.INSTANCE
+						.addFunction(mdTxnCtx, new Function(
+								compiledDeclarations.getDataverseName(), cfs
+										.getFunctionIdentifier()
+										.getFunctionName(), cfs
+										.getFunctionIdentifier().getArity(),
+								cfs.getParamList(), cfs.getFunctionBody()));
+				break;
+			}
 
-                case FUNCTION_DROP: {
-                    checkForDataverseConnection(true);
-                    FunctionDropStatement stmtDropFunction = (FunctionDropStatement) stmt;
-                    String functionName = stmtDropFunction.getFunctionName().getValue();
-                    FunctionIdentifier fId = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, functionName,
-                            stmtDropFunction.getArity(), false);
-                    if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(ARTIFACT_KIND.FUNCTION, fId)) {
-                        throw new AsterixException("Invalid Operation cannot drop function " + functionName
-                                + " (protected by system)");
-                    }
-                    Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx,
-                            compiledDeclarations.getDataverseName(), functionName, stmtDropFunction.getArity());
-                    if (function == null) {
-                        if (!stmtDropFunction.getIfExists())
-                            throw new AlgebricksException("There is no function with this name " + functionName + ".");
-                    } else {
-                        MetadataManager.INSTANCE.dropFunction(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                                functionName, stmtDropFunction.getArity());
-                    }
-                    break;
-                }
-            }
-        }
+			case FUNCTION_DROP: {
+				checkForDataverseConnection(true);
+				FunctionDropStatement stmtDropFunction = (FunctionDropStatement) stmt;
+				String functionName = stmtDropFunction.getFunctionName()
+						.getValue();
+                    FunctionIdentifier fId = new FunctionIdentifier(
+						FunctionConstants.ASTERIX_NS, functionName,
+						stmtDropFunction.getArity());
+				if (AsterixBuiltinArtifactMap.isSystemProtectedArtifact(
+						ARTIFACT_KIND.FUNCTION, fId)) {
+					throw new AsterixException(
+							"Invalid Operation cannot drop function "
+									+ functionName + " (protected by system)");
+				}
+				Function function = MetadataManager.INSTANCE.getFunction(
+						mdTxnCtx, compiledDeclarations.getDataverseName(),
+						functionName, stmtDropFunction.getArity());
+				if (function == null) {
+					if (!stmtDropFunction.getIfExists())
+						throw new AlgebricksException(
+								"There is no function with this name "
+										+ functionName + ".");
+				} else {
+					MetadataManager.INSTANCE.dropFunction(mdTxnCtx,
+							compiledDeclarations.getDataverseName(),
+							functionName, stmtDropFunction.getArity());
+				}
+				break;
+			}
+			}
+		}
 
-        if (disconnectFromDataverse) {
-            if (compiledDeclarations.isConnectedToDataverse()) {
-                compiledDeclarations.disconnectFromDataverse();
-            }
-        }
-    }
+		if (disconnectFromDataverse) {
+			if (compiledDeclarations.isConnectedToDataverse()) {
+				compiledDeclarations.disconnectFromDataverse();
+			}
+		}
+	}
 
-    private void checkForDataverseConnection(boolean needConnection) throws AlgebricksException {
-        if (compiledDeclarations.isConnectedToDataverse() != needConnection) {
-            if (needConnection)
-                throw new AlgebricksException("You need first to connect to a dataverse.");
-            else
-                throw new AlgebricksException("You need first to disconnect from the dataverse.");
-        }
-    }
+	private void checkForDataverseConnection(boolean needConnection)
+			throws AlgebricksException {
+		if (compiledDeclarations.isConnectedToDataverse() != needConnection) {
+			if (needConnection)
+				throw new AlgebricksException(
+						"You need first to connect to a dataverse.");
+			else
+				throw new AlgebricksException(
+						"You need first to disconnect from the dataverse.");
+		}
+	}
 
-    private void runJob(IHyracksClientConnection hcc, JobSpecification jobSpec) throws Exception {
-        System.out.println(jobSpec.toString());
-        executeJobArray(hcc, new JobSpecification[] { jobSpec }, out, pdf);
-    }
+	private void runJob(IHyracksClientConnection hcc, JobSpecification jobSpec)
+			throws Exception {
+		System.out.println(jobSpec.toString());
+		executeJobArray(hcc, new JobSpecification[] { jobSpec }, out, pdf);
+	}
 
-    public void executeJobArray(IHyracksClientConnection hcc, JobSpecification[] specs, PrintWriter out,
-            DisplayFormat pdf) throws Exception {
-        for (int i = 0; i < specs.length; i++) {
-            specs[i].setMaxReattempts(0);
-            JobId jobId = hcc.startJob(GlobalConfig.HYRACKS_APP_NAME, specs[i]);
-            hcc.waitForCompletion(jobId);
-        }
-    }
+	public void executeJobArray(IHyracksClientConnection hcc,
+			JobSpecification[] specs, PrintWriter out, DisplayFormat pdf)
+			throws Exception {
+		for (int i = 0; i < specs.length; i++) {
+			specs[i].setMaxReattempts(0);
+			JobId jobId = hcc.startJob(GlobalConfig.HYRACKS_APP_NAME, specs[i]);
+			hcc.waitForCompletion(jobId);
+		}
+	}
 
-    private void runCreateDatasetJob(IHyracksClientConnection hcc, String datasetName) throws AsterixException,
-            AlgebricksException, Exception {
-        runJob(hcc, DatasetOperations.createDatasetJobSpec(datasetName, compiledDeclarations));
-    }
+	private void runCreateDatasetJob(IHyracksClientConnection hcc,
+			String datasetName) throws AsterixException, AlgebricksException,
+			Exception {
+		runJob(hcc, DatasetOperations.createDatasetJobSpec(datasetName,
+				compiledDeclarations));
+	}
 
-    private void runCreateIndexJob(IHyracksClientConnection hcc, CreateIndexStatement stmtCreateIndex) throws Exception {
-        // TODO: Eventually CreateIndexStatement and CompiledCreateIndexStatement should be replaced by the corresponding metadata entity.
-        // For now we must still convert to a CompiledCreateIndexStatement here.
-        CompiledCreateIndexStatement createIndexStmt = new CompiledCreateIndexStatement(stmtCreateIndex.getIndexName()
-                .getValue(), stmtCreateIndex.getDatasetName().getValue(), stmtCreateIndex.getFieldExprs(),
-                stmtCreateIndex.getGramLength(), stmtCreateIndex.getIndexType());
-        JobSpecification spec = IndexOperations.buildSecondaryIndexCreationJobSpec(createIndexStmt,
-                compiledDeclarations);
-        if (spec == null) {
-            throw new AsterixException("Failed to create job spec for creating index '"
-                    + stmtCreateIndex.getDatasetName() + "." + stmtCreateIndex.getIndexName() + "'");
-        }
-        runJob(hcc, spec);
-    }
+	private void runCreateIndexJob(IHyracksClientConnection hcc,
+			CreateIndexStatement stmtCreateIndex) throws Exception {
+		// TODO: Eventually CreateIndexStatement and
+		// CompiledCreateIndexStatement should be replaced by the corresponding
+		// metadata entity.
+		// For now we must still convert to a CompiledCreateIndexStatement here.
+		CompiledCreateIndexStatement createIndexStmt = new CompiledCreateIndexStatement(
+				stmtCreateIndex.getIndexName().getValue(), stmtCreateIndex
+						.getDatasetName().getValue(),
+				stmtCreateIndex.getFieldExprs(),
+				stmtCreateIndex.getGramLength(), stmtCreateIndex.getIndexType());
+		JobSpecification spec = IndexOperations
+				.buildSecondaryIndexCreationJobSpec(createIndexStmt,
+						compiledDeclarations);
+		if (spec == null) {
+			throw new AsterixException(
+					"Failed to create job spec for creating index '"
+							+ stmtCreateIndex.getDatasetName() + "."
+							+ stmtCreateIndex.getIndexName() + "'");
+		}
+		runJob(hcc, spec);
+	}
 
-    private void compileDatasetDropStatement(IHyracksClientConnection hcc, MetadataTransactionContext mdTxnCtx,
-            String datasetName) throws Exception {
-        CompiledDatasetDropStatement cds = new CompiledDatasetDropStatement(datasetName);
-        Dataset ds = MetadataManager.INSTANCE
-                .getDataset(mdTxnCtx, compiledDeclarations.getDataverseName(), datasetName);
-        if (ds.getDatasetType() == DatasetType.INTERNAL || ds.getDatasetType() == DatasetType.FEED) {
-            JobSpecification[] jobs = DatasetOperations.createDropDatasetJobSpec(cds, compiledDeclarations);
-            for (JobSpecification job : jobs)
-                runJob(hcc, job);
-        }
-        MetadataManager.INSTANCE.dropDataset(mdTxnCtx, compiledDeclarations.getDataverseName(), datasetName);
-    }
+	private void compileDatasetDropStatement(IHyracksClientConnection hcc,
+			MetadataTransactionContext mdTxnCtx, String datasetName)
+			throws Exception {
+		CompiledDatasetDropStatement cds = new CompiledDatasetDropStatement(
+				datasetName);
+		Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx,
+				compiledDeclarations.getDataverseName(), datasetName);
+		if (ds.getDatasetType() == DatasetType.INTERNAL
+				|| ds.getDatasetType() == DatasetType.FEED) {
+			JobSpecification[] jobs = DatasetOperations
+					.createDropDatasetJobSpec(cds, compiledDeclarations);
+			for (JobSpecification job : jobs)
+				runJob(hcc, job);
+		}
+		MetadataManager.INSTANCE.dropDataset(mdTxnCtx,
+				compiledDeclarations.getDataverseName(), datasetName);
+	}
 
-    public AqlCompiledMetadataDeclarations getCompiledDeclarations() {
-        return compiledDeclarations;
-    }
+	public AqlCompiledMetadataDeclarations getCompiledDeclarations() {
+		return compiledDeclarations;
+	}
 
-    private void compileIndexDropStatement(IHyracksClientConnection hcc, MetadataTransactionContext mdTxnCtx,
-            String datasetName, String indexName) throws Exception {
-        CompiledIndexDropStatement cds = new CompiledIndexDropStatement(datasetName, indexName);
-        runJob(hcc, IndexOperations.buildDropSecondaryIndexJobSpec(cds, compiledDeclarations));
-        MetadataManager.INSTANCE.dropIndex(mdTxnCtx, compiledDeclarations.getDataverseName(), datasetName, indexName);
-    }
+	private void compileIndexDropStatement(IHyracksClientConnection hcc,
+			MetadataTransactionContext mdTxnCtx, String datasetName,
+			String indexName) throws Exception {
+		CompiledIndexDropStatement cds = new CompiledIndexDropStatement(
+				datasetName, indexName);
+		runJob(hcc, IndexOperations.buildDropSecondaryIndexJobSpec(cds,
+				compiledDeclarations));
+		MetadataManager.INSTANCE
+				.dropIndex(mdTxnCtx, compiledDeclarations.getDataverseName(),
+						datasetName, indexName);
+	}
 
-    private Map<String, IAType> computeTypes(MetadataTransactionContext mdTxnCtx, TypeDecl tDec)
-            throws AlgebricksException, MetadataException {
-        Map<String, IAType> typeMap = new HashMap<String, IAType>();
-        Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes = new HashMap<String, Map<ARecordType, List<Integer>>>();
-        Map<String, List<AbstractCollectionType>> incompleteItemTypes = new HashMap<String, List<AbstractCollectionType>>();
-        Map<String, List<String>> incompleteTopLevelTypeReferences = new HashMap<String, List<String>>();
+	private Map<String, IAType> computeTypes(
+			MetadataTransactionContext mdTxnCtx, TypeDecl tDec)
+			throws AlgebricksException, MetadataException {
+		Map<String, IAType> typeMap = new HashMap<String, IAType>();
+		Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes = new HashMap<String, Map<ARecordType, List<Integer>>>();
+		Map<String, List<AbstractCollectionType>> incompleteItemTypes = new HashMap<String, List<AbstractCollectionType>>();
+		Map<String, List<String>> incompleteTopLevelTypeReferences = new HashMap<String, List<String>>();
 
-        firstPass(tDec, typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences);
-        secondPass(mdTxnCtx, typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences);
+		firstPass(tDec, typeMap, incompleteFieldTypes, incompleteItemTypes,
+				incompleteTopLevelTypeReferences);
+		secondPass(mdTxnCtx, typeMap, incompleteFieldTypes,
+				incompleteItemTypes, incompleteTopLevelTypeReferences);
 
-        return typeMap;
-    }
+		return typeMap;
+	}
 
-    private void secondPass(MetadataTransactionContext mdTxnCtx, Map<String, IAType> typeMap,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
-            Map<String, List<AbstractCollectionType>> incompleteItemTypes,
-            Map<String, List<String>> incompleteTopLevelTypeReferences) throws AlgebricksException, MetadataException {
-        // solve remaining top level references
-        for (String trefName : incompleteTopLevelTypeReferences.keySet()) {
-            IAType t;// = typeMap.get(trefName);
-            Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                    trefName);
-            if (dt == null) {
-                throw new AlgebricksException("Could not resolve type " + trefName);
-            } else
-                t = dt.getDatatype();
-            for (String tname : incompleteTopLevelTypeReferences.get(trefName)) {
-                typeMap.put(tname, t);
-            }
-        }
-        // solve remaining field type references
-        for (String trefName : incompleteFieldTypes.keySet()) {
-            IAType t;// = typeMap.get(trefName);
-            Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                    trefName);
-            if (dt == null) {
-                throw new AlgebricksException("Could not resolve type " + trefName);
-            } else
-                t = dt.getDatatype();
-            Map<ARecordType, List<Integer>> fieldsToFix = incompleteFieldTypes.get(trefName);
-            for (ARecordType recType : fieldsToFix.keySet()) {
-                List<Integer> positions = fieldsToFix.get(recType);
-                IAType[] fldTypes = recType.getFieldTypes();
-                for (Integer pos : positions) {
-                    if (fldTypes[pos] == null) {
-                        fldTypes[pos] = t;
-                    } else { // nullable
-                        AUnionType nullableUnion = (AUnionType) fldTypes[pos];
-                        nullableUnion.setTypeAtIndex(t, 1);
-                    }
-                }
-            }
-        }
-        // solve remaining item type references
-        for (String trefName : incompleteItemTypes.keySet()) {
-            IAType t;// = typeMap.get(trefName);
-            Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, compiledDeclarations.getDataverseName(),
-                    trefName);
-            if (dt == null) {
-                throw new AlgebricksException("Could not resolve type " + trefName);
-            } else
-                t = dt.getDatatype();
-            for (AbstractCollectionType act : incompleteItemTypes.get(trefName)) {
-                act.setItemType(t);
-            }
-        }
-    }
+	private void secondPass(MetadataTransactionContext mdTxnCtx,
+			Map<String, IAType> typeMap,
+			Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
+			Map<String, List<AbstractCollectionType>> incompleteItemTypes,
+			Map<String, List<String>> incompleteTopLevelTypeReferences)
+			throws AlgebricksException, MetadataException {
+		// solve remaining top level references
+		for (String trefName : incompleteTopLevelTypeReferences.keySet()) {
+			IAType t;// = typeMap.get(trefName);
+			Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
+					compiledDeclarations.getDataverseName(), trefName);
+			if (dt == null) {
+				throw new AlgebricksException("Could not resolve type "
+						+ trefName);
+			} else
+				t = dt.getDatatype();
+			for (String tname : incompleteTopLevelTypeReferences.get(trefName)) {
+				typeMap.put(tname, t);
+			}
+		}
+		// solve remaining field type references
+		for (String trefName : incompleteFieldTypes.keySet()) {
+			IAType t;// = typeMap.get(trefName);
+			Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
+					compiledDeclarations.getDataverseName(), trefName);
+			if (dt == null) {
+				throw new AlgebricksException("Could not resolve type "
+						+ trefName);
+			} else
+				t = dt.getDatatype();
+			Map<ARecordType, List<Integer>> fieldsToFix = incompleteFieldTypes
+					.get(trefName);
+			for (ARecordType recType : fieldsToFix.keySet()) {
+				List<Integer> positions = fieldsToFix.get(recType);
+				IAType[] fldTypes = recType.getFieldTypes();
+				for (Integer pos : positions) {
+					if (fldTypes[pos] == null) {
+						fldTypes[pos] = t;
+					} else { // nullable
+						AUnionType nullableUnion = (AUnionType) fldTypes[pos];
+						nullableUnion.setTypeAtIndex(t, 1);
+					}
+				}
+			}
+		}
+		// solve remaining item type references
+		for (String trefName : incompleteItemTypes.keySet()) {
+			IAType t;// = typeMap.get(trefName);
+			Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx,
+					compiledDeclarations.getDataverseName(), trefName);
+			if (dt == null) {
+				throw new AlgebricksException("Could not resolve type "
+						+ trefName);
+			} else
+				t = dt.getDatatype();
+			for (AbstractCollectionType act : incompleteItemTypes.get(trefName)) {
+				act.setItemType(t);
+			}
+		}
+	}
 
-    private void firstPass(TypeDecl td, Map<String, IAType> typeMap,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
-            Map<String, List<AbstractCollectionType>> incompleteItemTypes,
-            Map<String, List<String>> incompleteTopLevelTypeReferences) throws AlgebricksException {
+	private void firstPass(TypeDecl td, Map<String, IAType> typeMap,
+			Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
+			Map<String, List<AbstractCollectionType>> incompleteItemTypes,
+			Map<String, List<String>> incompleteTopLevelTypeReferences)
+			throws AlgebricksException {
 
-        TypeExpression texpr = td.getTypeDef();
-        String tdname = td.getIdent().getValue();
-        if (builtinTypeMap.get(tdname) != null) {
-            throw new AlgebricksException("Cannot redefine builtin type " + tdname + " .");
-        }
-        switch (texpr.getTypeKind()) {
-            case TYPEREFERENCE: {
-                TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
-                IAType t = solveTypeReference(tre, typeMap);
-                if (t != null) {
-                    typeMap.put(tdname, t);
-                } else {
-                    addIncompleteTopLevelTypeReference(tdname, tre, incompleteTopLevelTypeReferences);
-                }
-                break;
-            }
-            case RECORD: {
-                RecordTypeDefinition rtd = (RecordTypeDefinition) texpr;
-                ARecordType recType = computeRecordType(tdname, rtd, typeMap, incompleteFieldTypes, incompleteItemTypes);
-                typeMap.put(tdname, recType);
-                break;
-            }
-            case ORDEREDLIST: {
-                OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
-                AOrderedListType olType = computeOrderedListType(tdname, oltd, typeMap, incompleteItemTypes,
-                        incompleteFieldTypes);
-                typeMap.put(tdname, olType);
-                break;
-            }
-            case UNORDEREDLIST: {
-                UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
-                AUnorderedListType ulType = computeUnorderedListType(tdname, ultd, typeMap, incompleteItemTypes,
-                        incompleteFieldTypes);
-                typeMap.put(tdname, ulType);
-                break;
-            }
-            default: {
-                throw new IllegalStateException();
-            }
-        }
-    }
+		TypeExpression texpr = td.getTypeDef();
+		String tdname = td.getIdent().getValue();
+		if (builtinTypeMap.get(tdname) != null) {
+			throw new AlgebricksException("Cannot redefine builtin type "
+					+ tdname + " .");
+		}
+		switch (texpr.getTypeKind()) {
+		case TYPEREFERENCE: {
+			TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
+			IAType t = solveTypeReference(tre, typeMap);
+			if (t != null) {
+				typeMap.put(tdname, t);
+			} else {
+				addIncompleteTopLevelTypeReference(tdname, tre,
+						incompleteTopLevelTypeReferences);
+			}
+			break;
+		}
+		case RECORD: {
+			RecordTypeDefinition rtd = (RecordTypeDefinition) texpr;
+			ARecordType recType = computeRecordType(tdname, rtd, typeMap,
+					incompleteFieldTypes, incompleteItemTypes);
+			typeMap.put(tdname, recType);
+			break;
+		}
+		case ORDEREDLIST: {
+			OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
+			AOrderedListType olType = computeOrderedListType(tdname, oltd,
+					typeMap, incompleteItemTypes, incompleteFieldTypes);
+			typeMap.put(tdname, olType);
+			break;
+		}
+		case UNORDEREDLIST: {
+			UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
+			AUnorderedListType ulType = computeUnorderedListType(tdname, ultd,
+					typeMap, incompleteItemTypes, incompleteFieldTypes);
+			typeMap.put(tdname, ulType);
+			break;
+		}
+		default: {
+			throw new IllegalStateException();
+		}
+		}
+	}
 
-    private AOrderedListType computeOrderedListType(String typeName, OrderedListTypeDefinition oltd,
-            Map<String, IAType> typeMap, Map<String, List<AbstractCollectionType>> incompleteItemTypes,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
-        TypeExpression tExpr = oltd.getItemTypeExpression();
-        AOrderedListType aolt = new AOrderedListType(null, typeName);
-        setCollectionItemType(tExpr, typeMap, incompleteItemTypes, incompleteFieldTypes, aolt);
-        return aolt;
-    }
+	private AOrderedListType computeOrderedListType(String typeName,
+			OrderedListTypeDefinition oltd, Map<String, IAType> typeMap,
+			Map<String, List<AbstractCollectionType>> incompleteItemTypes,
+			Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
+		TypeExpression tExpr = oltd.getItemTypeExpression();
+		AOrderedListType aolt = new AOrderedListType(null, typeName);
+		setCollectionItemType(tExpr, typeMap, incompleteItemTypes,
+				incompleteFieldTypes, aolt);
+		return aolt;
+	}
 
-    private AUnorderedListType computeUnorderedListType(String typeName, UnorderedListTypeDefinition ultd,
-            Map<String, IAType> typeMap, Map<String, List<AbstractCollectionType>> incompleteItemTypes,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
-        TypeExpression tExpr = ultd.getItemTypeExpression();
-        AUnorderedListType ault = new AUnorderedListType(null, typeName);
-        setCollectionItemType(tExpr, typeMap, incompleteItemTypes, incompleteFieldTypes, ault);
-        return ault;
-    }
+	private AUnorderedListType computeUnorderedListType(String typeName,
+			UnorderedListTypeDefinition ultd, Map<String, IAType> typeMap,
+			Map<String, List<AbstractCollectionType>> incompleteItemTypes,
+			Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
+		TypeExpression tExpr = ultd.getItemTypeExpression();
+		AUnorderedListType ault = new AUnorderedListType(null, typeName);
+		setCollectionItemType(tExpr, typeMap, incompleteItemTypes,
+				incompleteFieldTypes, ault);
+		return ault;
+	}
 
-    private void setCollectionItemType(TypeExpression tExpr, Map<String, IAType> typeMap,
-            Map<String, List<AbstractCollectionType>> incompleteItemTypes,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, AbstractCollectionType act) {
-        switch (tExpr.getTypeKind()) {
-            case ORDEREDLIST: {
-                OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) tExpr;
-                IAType t = computeOrderedListType(null, oltd, typeMap, incompleteItemTypes, incompleteFieldTypes);
-                act.setItemType(t);
-                break;
-            }
-            case UNORDEREDLIST: {
-                UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) tExpr;
-                IAType t = computeUnorderedListType(null, ultd, typeMap, incompleteItemTypes, incompleteFieldTypes);
-                act.setItemType(t);
-                break;
-            }
-            case RECORD: {
-                RecordTypeDefinition rtd = (RecordTypeDefinition) tExpr;
-                IAType t = computeRecordType(null, rtd, typeMap, incompleteFieldTypes, incompleteItemTypes);
-                act.setItemType(t);
-                break;
-            }
-            case TYPEREFERENCE: {
-                TypeReferenceExpression tre = (TypeReferenceExpression) tExpr;
-                IAType tref = solveTypeReference(tre, typeMap);
-                if (tref != null) {
-                    act.setItemType(tref);
-                } else {
-                    addIncompleteCollectionTypeReference(act, tre, incompleteItemTypes);
-                }
-                break;
-            }
-            default: {
-                throw new IllegalStateException();
-            }
-        }
-    }
+	private void setCollectionItemType(TypeExpression tExpr,
+			Map<String, IAType> typeMap,
+			Map<String, List<AbstractCollectionType>> incompleteItemTypes,
+			Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
+			AbstractCollectionType act) {
+		switch (tExpr.getTypeKind()) {
+		case ORDEREDLIST: {
+			OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) tExpr;
+			IAType t = computeOrderedListType(null, oltd, typeMap,
+					incompleteItemTypes, incompleteFieldTypes);
+			act.setItemType(t);
+			break;
+		}
+		case UNORDEREDLIST: {
+			UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) tExpr;
+			IAType t = computeUnorderedListType(null, ultd, typeMap,
+					incompleteItemTypes, incompleteFieldTypes);
+			act.setItemType(t);
+			break;
+		}
+		case RECORD: {
+			RecordTypeDefinition rtd = (RecordTypeDefinition) tExpr;
+			IAType t = computeRecordType(null, rtd, typeMap,
+					incompleteFieldTypes, incompleteItemTypes);
+			act.setItemType(t);
+			break;
+		}
+		case TYPEREFERENCE: {
+			TypeReferenceExpression tre = (TypeReferenceExpression) tExpr;
+			IAType tref = solveTypeReference(tre, typeMap);
+			if (tref != null) {
+				act.setItemType(tref);
+			} else {
+				addIncompleteCollectionTypeReference(act, tre,
+						incompleteItemTypes);
+			}
+			break;
+		}
+		default: {
+			throw new IllegalStateException();
+		}
+		}
+	}
 
-    private ARecordType computeRecordType(String typeName, RecordTypeDefinition rtd, Map<String, IAType> typeMap,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
-            Map<String, List<AbstractCollectionType>> incompleteItemTypes) {
-        List<String> names = rtd.getFieldNames();
-        int n = names.size();
-        String[] fldNames = new String[n];
-        IAType[] fldTypes = new IAType[n];
-        int i = 0;
-        for (String s : names) {
-            fldNames[i++] = s;
-        }
-        boolean isOpen = rtd.getRecordKind() == RecordKind.OPEN;
-        ARecordType recType = new ARecordType(typeName, fldNames, fldTypes, isOpen);
-        for (int j = 0; j < n; j++) {
-            TypeExpression texpr = rtd.getFieldTypes().get(j);
-            switch (texpr.getTypeKind()) {
-                case TYPEREFERENCE: {
-                    TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
-                    IAType tref = solveTypeReference(tre, typeMap);
-                    if (tref != null) {
-                        if (!rtd.getNullableFields().get(j)) { // not nullable
-                            fldTypes[j] = tref;
-                        } else { // nullable
-                            fldTypes[j] = makeUnionWithNull(null, tref);
-                        }
-                    } else {
-                        addIncompleteFieldTypeReference(recType, j, tre, incompleteFieldTypes);
-                        if (rtd.getNullableFields().get(j)) {
-                            fldTypes[j] = makeUnionWithNull(null, null);
-                        }
-                    }
-                    break;
-                }
-                case RECORD: {
-                    RecordTypeDefinition recTypeDef2 = (RecordTypeDefinition) texpr;
-                    IAType t2 = computeRecordType(null, recTypeDef2, typeMap, incompleteFieldTypes, incompleteItemTypes);
-                    if (!rtd.getNullableFields().get(j)) { // not nullable
-                        fldTypes[j] = t2;
-                    } else { // nullable
-                        fldTypes[j] = makeUnionWithNull(null, t2);
-                    }
-                    break;
-                }
-                case ORDEREDLIST: {
-                    OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
-                    IAType t2 = computeOrderedListType(null, oltd, typeMap, incompleteItemTypes, incompleteFieldTypes);
-                    fldTypes[j] = (rtd.getNullableFields().get(j)) ? makeUnionWithNull(null, t2) : t2;
-                    break;
-                }
-                case UNORDEREDLIST: {
-                    UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
-                    IAType t2 = computeUnorderedListType(null, ultd, typeMap, incompleteItemTypes, incompleteFieldTypes);
-                    fldTypes[j] = (rtd.getNullableFields().get(j)) ? makeUnionWithNull(null, t2) : t2;
-                    break;
-                }
-                default: {
-                    throw new IllegalStateException();
-                }
-            }
+	private ARecordType computeRecordType(String typeName,
+			RecordTypeDefinition rtd, Map<String, IAType> typeMap,
+			Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
+			Map<String, List<AbstractCollectionType>> incompleteItemTypes) {
+		List<String> names = rtd.getFieldNames();
+		int n = names.size();
+		String[] fldNames = new String[n];
+		IAType[] fldTypes = new IAType[n];
+		int i = 0;
+		for (String s : names) {
+			fldNames[i++] = s;
+		}
+		boolean isOpen = rtd.getRecordKind() == RecordKind.OPEN;
+		ARecordType recType = new ARecordType(typeName, fldNames, fldTypes,
+				isOpen);
+		for (int j = 0; j < n; j++) {
+			TypeExpression texpr = rtd.getFieldTypes().get(j);
+			switch (texpr.getTypeKind()) {
+			case TYPEREFERENCE: {
+				TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
+				IAType tref = solveTypeReference(tre, typeMap);
+				if (tref != null) {
+					if (!rtd.getNullableFields().get(j)) { // not nullable
+						fldTypes[j] = tref;
+					} else { // nullable
+						fldTypes[j] = makeUnionWithNull(null, tref);
+					}
+				} else {
+					addIncompleteFieldTypeReference(recType, j, tre,
+							incompleteFieldTypes);
+					if (rtd.getNullableFields().get(j)) {
+						fldTypes[j] = makeUnionWithNull(null, null);
+					}
+				}
+				break;
+			}
+			case RECORD: {
+				RecordTypeDefinition recTypeDef2 = (RecordTypeDefinition) texpr;
+				IAType t2 = computeRecordType(null, recTypeDef2, typeMap,
+						incompleteFieldTypes, incompleteItemTypes);
+				if (!rtd.getNullableFields().get(j)) { // not nullable
+					fldTypes[j] = t2;
+				} else { // nullable
+					fldTypes[j] = makeUnionWithNull(null, t2);
+				}
+				break;
+			}
+			case ORDEREDLIST: {
+				OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
+				IAType t2 = computeOrderedListType(null, oltd, typeMap,
+						incompleteItemTypes, incompleteFieldTypes);
+				fldTypes[j] = (rtd.getNullableFields().get(j)) ? makeUnionWithNull(
+						null, t2) : t2;
+				break;
+			}
+			case UNORDEREDLIST: {
+				UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
+				IAType t2 = computeUnorderedListType(null, ultd, typeMap,
+						incompleteItemTypes, incompleteFieldTypes);
+				fldTypes[j] = (rtd.getNullableFields().get(j)) ? makeUnionWithNull(
+						null, t2) : t2;
+				break;
+			}
+			default: {
+				throw new IllegalStateException();
+			}
+			}
 
-        }
+		}
 
-        return recType;
-    }
+		return recType;
+	}
 
-    private AUnionType makeUnionWithNull(String unionTypeName, IAType type) {
-        ArrayList<IAType> unionList = new ArrayList<IAType>(2);
-        unionList.add(BuiltinType.ANULL);
-        unionList.add(type);
-        return new AUnionType(unionList, unionTypeName);
-    }
+	private AUnionType makeUnionWithNull(String unionTypeName, IAType type) {
+		ArrayList<IAType> unionList = new ArrayList<IAType>(2);
+		unionList.add(BuiltinType.ANULL);
+		unionList.add(type);
+		return new AUnionType(unionList, unionTypeName);
+	}
 
-    private void addIncompleteCollectionTypeReference(AbstractCollectionType collType, TypeReferenceExpression tre,
-            Map<String, List<AbstractCollectionType>> incompleteItemTypes) {
-        String typeName = tre.getIdent().getValue();
-        List<AbstractCollectionType> typeList = incompleteItemTypes.get(typeName);
-        if (typeList == null) {
-            typeList = new LinkedList<AbstractCollectionType>();
-            incompleteItemTypes.put(typeName, typeList);
-        }
-        typeList.add(collType);
-    }
+	private void addIncompleteCollectionTypeReference(
+			AbstractCollectionType collType, TypeReferenceExpression tre,
+			Map<String, List<AbstractCollectionType>> incompleteItemTypes) {
+		String typeName = tre.getIdent().getValue();
+		List<AbstractCollectionType> typeList = incompleteItemTypes
+				.get(typeName);
+		if (typeList == null) {
+			typeList = new LinkedList<AbstractCollectionType>();
+			incompleteItemTypes.put(typeName, typeList);
+		}
+		typeList.add(collType);
+	}
 
-    private void addIncompleteFieldTypeReference(ARecordType recType, int fldPosition, TypeReferenceExpression tre,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
-        String typeName = tre.getIdent().getValue();
-        Map<ARecordType, List<Integer>> refMap = incompleteFieldTypes.get(typeName);
-        if (refMap == null) {
-            refMap = new HashMap<ARecordType, List<Integer>>();
-            incompleteFieldTypes.put(typeName, refMap);
-        }
-        List<Integer> typeList = refMap.get(recType);
-        if (typeList == null) {
-            typeList = new ArrayList<Integer>();
-            refMap.put(recType, typeList);
-        }
-        typeList.add(fldPosition);
-    }
+	private void addIncompleteFieldTypeReference(ARecordType recType,
+			int fldPosition, TypeReferenceExpression tre,
+			Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes) {
+		String typeName = tre.getIdent().getValue();
+		Map<ARecordType, List<Integer>> refMap = incompleteFieldTypes
+				.get(typeName);
+		if (refMap == null) {
+			refMap = new HashMap<ARecordType, List<Integer>>();
+			incompleteFieldTypes.put(typeName, refMap);
+		}
+		List<Integer> typeList = refMap.get(recType);
+		if (typeList == null) {
+			typeList = new ArrayList<Integer>();
+			refMap.put(recType, typeList);
+		}
+		typeList.add(fldPosition);
+	}
 
-    private void addIncompleteTopLevelTypeReference(String tdeclName, TypeReferenceExpression tre,
-            Map<String, List<String>> incompleteTopLevelTypeReferences) {
-        String name = tre.getIdent().getValue();
-        List<String> refList = incompleteTopLevelTypeReferences.get(name);
-        if (refList == null) {
-            refList = new LinkedList<String>();
-            incompleteTopLevelTypeReferences.put(name, refList);
-        }
-        refList.add(tdeclName);
-    }
+	private void addIncompleteTopLevelTypeReference(String tdeclName,
+			TypeReferenceExpression tre,
+			Map<String, List<String>> incompleteTopLevelTypeReferences) {
+		String name = tre.getIdent().getValue();
+		List<String> refList = incompleteTopLevelTypeReferences.get(name);
+		if (refList == null) {
+			refList = new LinkedList<String>();
+			incompleteTopLevelTypeReferences.put(name, refList);
+		}
+		refList.add(tdeclName);
+	}
 
-    private IAType solveTypeReference(TypeReferenceExpression tre, Map<String, IAType> typeMap) {
-        String name = tre.getIdent().getValue();
-        IAType builtin = builtinTypeMap.get(name);
-        if (builtin != null) {
-            return builtin;
-        } else {
-            return typeMap.get(name);
-        }
-    }
+	private IAType solveTypeReference(TypeReferenceExpression tre,
+			Map<String, IAType> typeMap) {
+		String name = tre.getIdent().getValue();
+		IAType builtin = builtinTypeMap.get(name);
+		if (builtin != null) {
+			return builtin;
+		} else {
+			return typeMap.get(name);
+		}
+	}
 
-    public static interface ICompiledStatement {
+	public static interface ICompiledStatement {
 
-        public abstract Kind getKind();
-    }
+		public abstract Kind getKind();
+	}
 
-    public static class CompiledLoadFromFileStatement implements ICompiledStatement, IParseFileSplitsDecl {
-        private String datasetName;
-        private FileSplit[] splits;
-        private boolean alreadySorted;
-        private Character delimChar;
+	public static class CompiledLoadFromFileStatement implements
+			ICompiledStatement, IParseFileSplitsDecl {
+		private String datasetName;
+		private FileSplit[] splits;
+		private boolean alreadySorted;
+		private Character delimChar;
 
-        public CompiledLoadFromFileStatement(String datasetName, FileSplit[] splits, Character delimChar,
-                boolean alreadySorted) {
-            this.datasetName = datasetName;
-            this.splits = splits;
-            this.delimChar = delimChar;
-            this.alreadySorted = alreadySorted;
-        }
+		public CompiledLoadFromFileStatement(String datasetName,
+				FileSplit[] splits, Character delimChar, boolean alreadySorted) {
+			this.datasetName = datasetName;
+			this.splits = splits;
+			this.delimChar = delimChar;
+			this.alreadySorted = alreadySorted;
+		}
 
-        public String getDatasetName() {
-            return datasetName;
-        }
+		public String getDatasetName() {
+			return datasetName;
+		}
 
-        @Override
-        public FileSplit[] getSplits() {
-            return splits;
-        }
+		@Override
+		public FileSplit[] getSplits() {
+			return splits;
+		}
 
-        @Override
-        public Character getDelimChar() {
-            return delimChar;
-        }
+		@Override
+		public Character getDelimChar() {
+			return delimChar;
+		}
 
-        public boolean alreadySorted() {
-            return alreadySorted;
-        }
+		public boolean alreadySorted() {
+			return alreadySorted;
+		}
 
-        @Override
-        public boolean isDelimitedFileFormat() {
-            return delimChar != null;
-        }
+		@Override
+		public boolean isDelimitedFileFormat() {
+			return delimChar != null;
+		}
 
-        @Override
-        public Kind getKind() {
-            return Kind.LOAD_FROM_FILE;
-        }
-    }
+		@Override
+		public Kind getKind() {
+			return Kind.LOAD_FROM_FILE;
+		}
+	}
 
-    public static class CompiledWriteFromQueryResultStatement implements ICompiledStatement {
+	public static class CompiledWriteFromQueryResultStatement implements
+			ICompiledStatement {
 
-        private String datasetName;
-        private Query query;
-        private int varCounter;
+		private String datasetName;
+		private Query query;
+		private int varCounter;
 
-        public CompiledWriteFromQueryResultStatement(String datasetName, Query query, int varCounter) {
-            this.datasetName = datasetName;
-            this.query = query;
-            this.varCounter = varCounter;
-        }
+		public CompiledWriteFromQueryResultStatement(String datasetName,
+				Query query, int varCounter) {
+			this.datasetName = datasetName;
+			this.query = query;
+			this.varCounter = varCounter;
+		}
 
-        public String getDatasetName() {
-            return datasetName;
-        }
+		public String getDatasetName() {
+			return datasetName;
+		}
 
-        public int getVarCounter() {
-            return varCounter;
-        }
+		public int getVarCounter() {
+			return varCounter;
+		}
 
-        public Query getQuery() {
-            return query;
-        }
+		public Query getQuery() {
+			return query;
+		}
 
-        @Override
-        public Kind getKind() {
-            return Kind.WRITE_FROM_QUERY_RESULT;
-        }
+		@Override
+		public Kind getKind() {
+			return Kind.WRITE_FROM_QUERY_RESULT;
+		}
 
-    }
+	}
 
-    public static class CompiledDatasetDropStatement implements ICompiledStatement {
-        private String datasetName;
+	public static class CompiledDatasetDropStatement implements
+			ICompiledStatement {
+		private String datasetName;
 
-        public CompiledDatasetDropStatement(String datasetName) {
-            this.datasetName = datasetName;
-        }
+		public CompiledDatasetDropStatement(String datasetName) {
+			this.datasetName = datasetName;
+		}
 
-        public String getDatasetName() {
-            return datasetName;
-        }
+		public String getDatasetName() {
+			return datasetName;
+		}
 
-        @Override
-        public Kind getKind() {
-            return Kind.DATASET_DROP;
-        }
-    }
+		@Override
+		public Kind getKind() {
+			return Kind.DATASET_DROP;
+		}
+	}
 
-    // added by yasser
-    public static class CompiledCreateDataverseStatement implements ICompiledStatement {
-        private String dataverseName;
-        private String format;
+	// added by yasser
+	public static class CompiledCreateDataverseStatement implements
+			ICompiledStatement {
+		private String dataverseName;
+		private String format;
 
-        public CompiledCreateDataverseStatement(String dataverseName, String format) {
-            this.dataverseName = dataverseName;
-            this.format = format;
-        }
+		public CompiledCreateDataverseStatement(String dataverseName,
+				String format) {
+			this.dataverseName = dataverseName;
+			this.format = format;
+		}
 
-        public String getDataverseName() {
-            return dataverseName;
-        }
+		public String getDataverseName() {
+			return dataverseName;
+		}
 
-        public String getFormat() {
-            return format;
-        }
+		public String getFormat() {
+			return format;
+		}
 
-        @Override
-        public Kind getKind() {
-            return Kind.CREATE_DATAVERSE;
-        }
-    }
+		@Override
+		public Kind getKind() {
+			return Kind.CREATE_DATAVERSE;
+		}
+	}
 
-    public static class CompiledNodeGroupDropStatement implements ICompiledStatement {
-        private String nodeGroupName;
+	public static class CompiledNodeGroupDropStatement implements
+			ICompiledStatement {
+		private String nodeGroupName;
 
-        public CompiledNodeGroupDropStatement(String nodeGroupName) {
-            this.nodeGroupName = nodeGroupName;
-        }
+		public CompiledNodeGroupDropStatement(String nodeGroupName) {
+			this.nodeGroupName = nodeGroupName;
+		}
 
-        public String getNodeGroupName() {
-            return nodeGroupName;
-        }
+		public String getNodeGroupName() {
+			return nodeGroupName;
+		}
 
-        @Override
-        public Kind getKind() {
-            return Kind.NODEGROUP_DROP;
-        }
-    }
+		@Override
+		public Kind getKind() {
+			return Kind.NODEGROUP_DROP;
+		}
+	}
 
-    public static class CompiledIndexDropStatement implements ICompiledStatement {
-        private String datasetName;
-        private String indexName;
+	public static class CompiledIndexDropStatement implements
+			ICompiledStatement {
+		private String datasetName;
+		private String indexName;
 
-        public CompiledIndexDropStatement(String datasetName, String indexName) {
-            this.datasetName = datasetName;
-            this.indexName = indexName;
-        }
+		public CompiledIndexDropStatement(String datasetName, String indexName) {
+			this.datasetName = datasetName;
+			this.indexName = indexName;
+		}
 
-        public String getDatasetName() {
-            return datasetName;
-        }
+		public String getDatasetName() {
+			return datasetName;
+		}
 
-        public String getIndexName() {
-            return indexName;
-        }
+		public String getIndexName() {
+			return indexName;
+		}
 
-        @Override
-        public Kind getKind() {
-            return Kind.INDEX_DROP;
-        }
-    }
+		@Override
+		public Kind getKind() {
+			return Kind.INDEX_DROP;
+		}
+	}
 
-    public static class CompiledDataverseDropStatement implements ICompiledStatement {
-        private String dataverseName;
-        private boolean ifExists;
+	public static class CompiledDataverseDropStatement implements
+			ICompiledStatement {
+		private String dataverseName;
+		private boolean ifExists;
 
-        public CompiledDataverseDropStatement(String dataverseName, boolean ifExists) {
-            this.dataverseName = dataverseName;
-            this.ifExists = ifExists;
-        }
+		public CompiledDataverseDropStatement(String dataverseName,
+				boolean ifExists) {
+			this.dataverseName = dataverseName;
+			this.ifExists = ifExists;
+		}
 
-        public String getDataverseName() {
-            return dataverseName;
-        }
+		public String getDataverseName() {
+			return dataverseName;
+		}
 
-        public boolean getIfExists() {
-            return ifExists;
-        }
+		public boolean getIfExists() {
+			return ifExists;
+		}
 
-        @Override
-        public Kind getKind() {
-            return Kind.DATAVERSE_DROP;
-        }
-    }
+		@Override
+		public Kind getKind() {
+			return Kind.DATAVERSE_DROP;
+		}
+	}
 
-    public static class CompiledTypeDropStatement implements ICompiledStatement {
-        private String typeName;
+	public static class CompiledTypeDropStatement implements ICompiledStatement {
+		private String typeName;
 
-        public CompiledTypeDropStatement(String nodeGroupName) {
-            this.typeName = nodeGroupName;
-        }
+		public CompiledTypeDropStatement(String nodeGroupName) {
+			this.typeName = nodeGroupName;
+		}
 
-        public String getTypeName() {
-            return typeName;
-        }
+		public String getTypeName() {
+			return typeName;
+		}
 
-        @Override
-        public Kind getKind() {
-            return Kind.TYPE_DROP;
-        }
-    }
+		@Override
+		public Kind getKind() {
+			return Kind.TYPE_DROP;
+		}
+	}
 }
diff --git a/asterix-app/src/test/resources/optimizerts/results/fj-dblp-csx.plan b/asterix-app/src/test/resources/optimizerts/results/fj-dblp-csx.plan
index 3130442..3d1699e 100644
--- a/asterix-app/src/test/resources/optimizerts/results/fj-dblp-csx.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/fj-dblp-csx.plan
@@ -24,12 +24,12 @@
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
                                       }
                                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                                  -- STABLE_SORT [$$46(ASC), $$6(ASC)]  |LOCAL|
+                                  -- STABLE_SORT [$$46(ASC), $$5(ASC)]  |LOCAL|
                                     -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
                                       -- STREAM_PROJECT  |PARTITIONED|
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- HYBRID_HASH_JOIN [$$4][$$26]  |PARTITIONED|
-                                            -- HASH_PARTITION_EXCHANGE [$$4]  |PARTITIONED|
+                                          -- HYBRID_HASH_JOIN [$$3][$$26]  |PARTITIONED|
+                                            -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
                                               -- STREAM_PROJECT  |PARTITIONED|
                                                 -- UNNEST  |PARTITIONED|
                                                   -- ASSIGN  |PARTITIONED|
@@ -63,12 +63,12 @@
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
                                       }
                                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                                  -- STABLE_SORT [$$47(ASC), $$15(ASC)]  |LOCAL|
+                                  -- STABLE_SORT [$$47(ASC), $$14(ASC)]  |LOCAL|
                                     -- HASH_PARTITION_EXCHANGE [$$47]  |PARTITIONED|
                                       -- STREAM_PROJECT  |PARTITIONED|
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- HYBRID_HASH_JOIN [$$13][$$35]  |PARTITIONED|
-                                            -- HASH_PARTITION_EXCHANGE [$$13]  |PARTITIONED|
+                                          -- HYBRID_HASH_JOIN [$$12][$$35]  |PARTITIONED|
+                                            -- HASH_PARTITION_EXCHANGE [$$12]  |PARTITIONED|
                                               -- STREAM_PROJECT  |PARTITIONED|
                                                 -- UNNEST  |PARTITIONED|
                                                   -- ASSIGN  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/fj-phase1.plan b/asterix-app/src/test/resources/optimizerts/results/fj-phase1.plan
index 3042fae..c930bc7 100644
--- a/asterix-app/src/test/resources/optimizerts/results/fj-phase1.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/fj-phase1.plan
@@ -10,12 +10,12 @@
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
                   }
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-              -- STABLE_SORT [$$23(ASC), $$7(ASC)]  |LOCAL|
+              -- STABLE_SORT [$$23(ASC), $$6(ASC)]  |LOCAL|
                 -- HASH_PARTITION_EXCHANGE [$$23]  |PARTITIONED|
                   -- STREAM_PROJECT  |PARTITIONED|
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- HYBRID_HASH_JOIN [$$2][$$7]  |PARTITIONED|
-                        -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
+                      -- HYBRID_HASH_JOIN [$$1][$$6]  |PARTITIONED|
+                        -- HASH_PARTITION_EXCHANGE [$$1]  |PARTITIONED|
                           -- STREAM_PROJECT  |PARTITIONED|
                             -- UNNEST  |PARTITIONED|
                               -- ASSIGN  |PARTITIONED|
@@ -23,7 +23,7 @@
                                   -- DATASOURCE_SCAN  |PARTITIONED|
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                        -- HASH_PARTITION_EXCHANGE [$$7]  |PARTITIONED|
+                        -- HASH_PARTITION_EXCHANGE [$$6]  |PARTITIONED|
                           -- RUNNING_AGGREGATE  |PARTITIONED|
                             -- STREAM_PROJECT  |PARTITIONED|
                               -- SORT_MERGE_EXCHANGE [$$24(DESC) ]  |PARTITIONED|
@@ -35,13 +35,13 @@
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
                                             }
                                       -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$30(ASC)] HASH:[$$30]  |PARTITIONED|
-                                        -- PRE_CLUSTERED_GROUP_BY[$$6]  |LOCAL|
+                                        -- PRE_CLUSTERED_GROUP_BY[$$5]  |LOCAL|
                                                 {
                                                   -- AGGREGATE  |LOCAL|
                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
                                                 }
                                           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                                            -- STABLE_SORT [$$6(ASC)]  |LOCAL|
+                                            -- STABLE_SORT [$$5(ASC)]  |LOCAL|
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                 -- STREAM_PROJECT  |PARTITIONED|
                                                   -- UNNEST  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/fj-phase2-with-hints.plan b/asterix-app/src/test/resources/optimizerts/results/fj-phase2-with-hints.plan
index bac7a04..ef6d4e3 100644
--- a/asterix-app/src/test/resources/optimizerts/results/fj-phase2-with-hints.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/fj-phase2-with-hints.plan
@@ -9,14 +9,14 @@
                 -- PRE_CLUSTERED_GROUP_BY[$$27]  |PARTITIONED|
                         {
                           -- AGGREGATE  |LOCAL|
-                            -- IN_MEMORY_STABLE_SORT [$$5(ASC)]  |LOCAL|
+                            -- IN_MEMORY_STABLE_SORT [$$4(ASC)]  |LOCAL|
                               -- STREAM_SELECT  |LOCAL|
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
                         }
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- STREAM_PROJECT  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- IN_MEMORY_HASH_JOIN [$$3][$$8]  |PARTITIONED|
+                        -- IN_MEMORY_HASH_JOIN [$$2][$$7]  |PARTITIONED|
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                             -- STREAM_PROJECT  |PARTITIONED|
                               -- UNNEST  |PARTITIONED|
@@ -29,8 +29,8 @@
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
                             -- RUNNING_AGGREGATE  |PARTITIONED|
                               -- STREAM_PROJECT  |PARTITIONED|
-                                -- SORT_MERGE_EXCHANGE [$$28(ASC), $$8(ASC) ]  |PARTITIONED|
-                                  -- STABLE_SORT [$$28(ASC), $$8(ASC)]  |LOCAL|
+                                -- SORT_MERGE_EXCHANGE [$$28(ASC), $$7(ASC) ]  |PARTITIONED|
+                                  -- STABLE_SORT [$$28(ASC), $$7(ASC)]  |LOCAL|
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                       -- EXTERNAL_GROUP_BY[$$36]  |PARTITIONED|
                                               {
@@ -38,7 +38,7 @@
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
                                               }
                                         -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
-                                          -- EXTERNAL_GROUP_BY[$$7]  |LOCAL|
+                                          -- EXTERNAL_GROUP_BY[$$6]  |LOCAL|
                                                   {
                                                     -- AGGREGATE  |LOCAL|
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
diff --git a/asterix-app/src/test/resources/optimizerts/results/unnest_list_in_subplan.plan b/asterix-app/src/test/resources/optimizerts/results/unnest_list_in_subplan.plan
index 0a2d8a3..d249c29 100644
--- a/asterix-app/src/test/resources/optimizerts/results/unnest_list_in_subplan.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/unnest_list_in_subplan.plan
@@ -14,8 +14,8 @@
                 -- HASH_PARTITION_EXCHANGE [$$20]  |PARTITIONED|
                   -- STREAM_PROJECT  |PARTITIONED|
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- HYBRID_HASH_JOIN [$$4][$$22]  |PARTITIONED|
-                        -- HASH_PARTITION_EXCHANGE [$$4]  |PARTITIONED|
+                      -- HYBRID_HASH_JOIN [$$3][$$22]  |PARTITIONED|
+                        -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
                           -- STREAM_PROJECT  |PARTITIONED|
                             -- UNNEST  |PARTITIONED|
                               -- ASSIGN  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/runtimets/ignore.txt b/asterix-app/src/test/resources/runtimets/ignore.txt
index dc40231..1cf8519 100644
--- a/asterix-app/src/test/resources/runtimets/ignore.txt
+++ b/asterix-app/src/test/resources/runtimets/ignore.txt
@@ -32,3 +32,8 @@
 open-closed/heterog-list02
 open-closed/heterog-list03
 open-closed/c2c
+quantifiers/somesat_03.aql
+quantifiers/somesat_04.aql
+quantifiers/somesat_05.aql
+quantifiers/everysat_02.aql
+quantifiers/everysat_03.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/add-null.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/add-null.aql
new file mode 100644
index 0000000..caa30d7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/add-null.aql
@@ -0,0 +1,12 @@
+/*
+ * Description      :   Add anything plus null, the result should be null.
+ * Expected Result  :   Success
+ * Date             :   19th July 2012
+ */
+
+write output to nc1:"rttest/constructor_add-null.adm";
+
+let $x := 1
+let $y := 10
+let $z := 20
+return ($x+$y+$z+null)
diff --git a/asterix-app/src/test/resources/runtimets/queries/dml/drop-index.aql b/asterix-app/src/test/resources/runtimets/queries/dml/drop-index.aql
new file mode 100644
index 0000000..0c87734
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/dml/drop-index.aql
@@ -0,0 +1,50 @@
+/*
+ * Description     : Drop secondary index.
+ * Expected Result : Success
+ * Date            : 12th July 2012
+ *
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type Schema as closed {
+unique1:  int32,
+unique2:  int32,
+two:  int32,
+four:  int32,
+ten:  int32,
+twenty:  int32,
+onePercent: int32,
+tenPercent:  int32,
+twentyPercent:  int32,
+fiftyPercent:  int32,
+unique3:  int32,
+evenOnePercent: int32,
+oddOnePercent:  int32,
+stringu1:  string,
+stringu2:  string,
+string4:  string
+}
+
+create dataset t1(Schema) partitioned by key unique2;
+
+// Load data
+load dataset t1
+using "edu.uci.ics.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/wisc/onektup.adm"),("format"="delimited-text"),("delimiter"="|")) pre-sorted;
+
+// create secondary indexes
+create index idx_t1_str1 on t1(stringu1);
+create index idx_t1_unique1 on t1(unique1);
+
+// drop secondary indexes
+drop index t1.idx_t1_str1;
+drop index t1.idx_t1_unique1;
+
+write output to nc1:"rttest/dml_drop-index.adm";
+
+for $a in dataset('t1')
+where $a.unique1 > 10 and $a.stringu1="DGAAAAXXXXXXXXXXXXXXXXXXX"
+return $a
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/abs0.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/abs0.aql
new file mode 100644
index 0000000..3908231
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/abs0.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_abs0.adm";
+
+
+let $c0 := int8("-0")
+let $c1 := int16("-0")
+let $c2 := int32("-0")
+let $c3 := int64("-0")
+let $c4 := int8("0")
+let $c5 := int16("0")
+let $c6 := int32("0")
+let $c7 := int64("0")
+return {"f0": numeric-abs($c0), "f1": numeric-abs($c1),"f2": numeric-abs($c2), "f3": numeric-abs($c3),
+	"f4": numeric-abs($c4),"f5": numeric-abs($c5) ,"f6": numeric-abs($c6), "f7": numeric-abs($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/abs1.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/abs1.aql
new file mode 100644
index 0000000..9d36528
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/abs1.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_abs1.adm";
+
+
+let $c0 := int8("-20")
+let $c1 := int16("-23")
+let $c2 := int32("-29")
+let $c3 := int64("-21")
+let $c4 := int8("20")
+let $c5 := int16("22")
+let $c6 := int32("23")
+let $c7 := int64("27")
+return {"f0": numeric-abs($c0), "f1": numeric-abs($c1),"f2": numeric-abs($c2), "f3": numeric-abs($c3),
+	"f4": numeric-abs($c4),"f5": numeric-abs($c5) ,"f6": numeric-abs($c6), "f7": numeric-abs($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/abs2.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/abs2.aql
new file mode 100644
index 0000000..411ae00
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/abs2.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_abs2.adm";
+
+
+let $c0 := float("-20.1")
+let $c1 := float("-20.56e-30")
+let $c2 := float("NaN")
+let $c3 := float("INF")
+let $c4 := float("-INF")
+let $c5 := float("-0.0")
+let $c6 := float("0.0")
+return {"f0": numeric-abs($c0), "f1": numeric-abs($c1),"f2": numeric-abs($c2),
+        "f3": numeric-abs($c3),"f4": numeric-abs($c4),"f5": numeric-abs($c5), "f6": numeric-abs($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/abs3.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/abs3.aql
new file mode 100644
index 0000000..4364409
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/abs3.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_abs3.adm";
+
+
+let $c0 := double("-20.1")
+let $c1 := double("-20.56e-30")
+let $c2 := double("NaN")
+let $c3 := double("INF")
+let $c4 := double("-INF")
+let $c5 := double("-0.0")
+let $c6 := double("0.0")
+return {"d0": numeric-abs($c0), "d1": numeric-abs($c1),"d2": numeric-abs($c2),
+        "d3": numeric-abs($c3),"d4": numeric-abs($c4),"d5": numeric-abs($c5), "d6": numeric-abs($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/abs4.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/abs4.aql
new file mode 100644
index 0000000..b2db5fd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/abs4.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_abs4.adm";
+
+let $c0 := int8("-20")
+return {"f0": numeric-abs($c0), "f1": numeric-abs(-1.11),"f2": numeric-abs(12.9), "f3": numeric-abs(1.11)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling0.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling0.aql
new file mode 100644
index 0000000..82e314f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling0.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_ceiling0.adm";
+
+
+let $c0 := int8("-0")
+let $c1 := int16("-0")
+let $c2 := int32("-0")
+let $c3 := int64("-0")
+let $c4 := int8("0")
+let $c5 := int16("0")
+let $c6 := int32("0")
+let $c7 := int64("0")
+return {"f0": numeric-ceiling($c0), "f1": numeric-ceiling($c1),"f2": numeric-ceiling($c2), "f3": numeric-ceiling($c3),
+	"f4": numeric-ceiling($c4),"f5": numeric-ceiling($c5) ,"f6": numeric-ceiling($c6), "f7": numeric-ceiling($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling1.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling1.aql
new file mode 100644
index 0000000..88e8d63
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling1.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_ceiling1.adm";
+
+
+let $c0 := int8("-20")
+let $c1 := int16("-23")
+let $c2 := int32("-29")
+let $c3 := int64("-21")
+let $c4 := int8("20")
+let $c5 := int16("22")
+let $c6 := int32("23")
+let $c7 := int64("27")
+return {"f0": numeric-ceiling($c0), "f1": numeric-ceiling($c1),"f2": numeric-ceiling($c2), "f3": numeric-ceiling($c3),
+	"f4": numeric-ceiling($c4),"f5": numeric-ceiling($c5) ,"f6": numeric-ceiling($c6), "f7": numeric-ceiling($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling2.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling2.aql
new file mode 100644
index 0000000..8f71213
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling2.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_ceiling2.adm";
+
+
+let $c0 := float("20.1")
+let $c1 := float("-20.56e-30")
+let $c2 := float("NaN")
+let $c3 := float("INF")
+let $c4 := float("-INF")
+let $c5 := float("-0.0")
+let $c6 := float("0.0")
+return {"f0": numeric-ceiling($c0), "f1": numeric-ceiling($c1),"f2": numeric-ceiling($c2),
+        "f3": numeric-ceiling($c3),"f4": numeric-ceiling($c4),"f5": numeric-ceiling($c5), "f6": numeric-ceiling($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling3.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling3.aql
new file mode 100644
index 0000000..67ad9db
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling3.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_ceiling3.adm";
+
+
+let $c0 := double("20.1")
+let $c1 := double("-20.56e-30")
+let $c2 := double("NaN")
+let $c3 := double("INF")
+let $c4 := double("-INF")
+let $c5 := double("-0.0")
+let $c6 := double("0.0")
+return {"d0": numeric-ceiling($c0), "d1": numeric-ceiling($c1),"d2": numeric-ceiling($c2),
+        "d3": numeric-ceiling($c3),"d4": numeric-ceiling($c4),"d5": numeric-ceiling($c5), "d6": numeric-ceiling($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling4.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling4.aql
new file mode 100644
index 0000000..a90851c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/ceiling4.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_ceiling4.adm";
+
+let $c0 := int8("-20")
+return {"f0": numeric-ceiling($c0), "f1": numeric-ceiling(-1.11),"f2": numeric-ceiling(12.9), "f3": numeric-ceiling(1.11)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/floor0.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/floor0.aql
new file mode 100644
index 0000000..adfab71
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/floor0.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_floor0.adm";
+
+
+let $c0 := int8("-0")
+let $c1 := int16("-0")
+let $c2 := int32("-0")
+let $c3 := int64("-0")
+let $c4 := int8("0")
+let $c5 := int16("0")
+let $c6 := int32("0")
+let $c7 := int64("0")
+return {"f0": numeric-floor($c0), "f1": numeric-floor($c1),"f2": numeric-floor($c2), "f3": numeric-floor($c3),
+	"f4": numeric-floor($c4),"f5": numeric-floor($c5) ,"f6": numeric-floor($c6), "f7": numeric-floor($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/floor1.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/floor1.aql
new file mode 100644
index 0000000..a119b67
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/floor1.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_floor1.adm";
+
+
+let $c0 := int8("-20")
+let $c1 := int16("-23")
+let $c2 := int32("-29")
+let $c3 := int64("-21")
+let $c4 := int8("20")
+let $c5 := int16("22")
+let $c6 := int32("23")
+let $c7 := int64("27")
+return {"f0": numeric-floor($c0), "f1": numeric-floor($c1),"f2": numeric-floor($c2), "f3": numeric-floor($c3),
+	"f4": numeric-floor($c4),"f5": numeric-floor($c5) ,"f6": numeric-floor($c6), "f7": numeric-floor($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/floor2.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/floor2.aql
new file mode 100644
index 0000000..7e575dd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/floor2.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_floor2.adm";
+
+
+let $c0 := float("20.1")
+let $c1 := float("-20.56e-30")
+let $c2 := float("NaN")
+let $c3 := float("INF")
+let $c4 := float("-INF")
+let $c5 := float("-0.0")
+let $c6 := float("0.0")
+return {"f0": numeric-floor($c0), "f1": numeric-floor($c1),"f2": numeric-floor($c2),
+        "f3": numeric-floor($c3),"f4": numeric-floor($c4),"f5": numeric-floor($c5), "f6": numeric-floor($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/floor3.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/floor3.aql
new file mode 100644
index 0000000..d975dfc
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/floor3.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_floor3.adm";
+
+
+let $c0 := double("20.1")
+let $c1 := double("-20.56e-30")
+let $c2 := double("NaN")
+let $c3 := double("INF")
+let $c4 := double("-INF")
+let $c5 := double("-0.0")
+let $c6 := double("0.0")
+return {"d0": numeric-floor($c0), "d1": numeric-floor($c1),"d2": numeric-floor($c2),
+        "d3": numeric-floor($c3),"d4": numeric-floor($c4),"d5": numeric-floor($c5), "d6": numeric-floor($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/floor4.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/floor4.aql
new file mode 100644
index 0000000..eae917d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/floor4.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_floor4.adm";
+
+let $c0 := int8("-20")
+return {"f0": numeric-floor($c0), "f1": numeric-floor(-1.11),"f2": numeric-floor(12.9), "f3": numeric-floor(1.11)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even0.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even0.aql
new file mode 100644
index 0000000..25232d0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even0.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even0.adm";
+
+
+let $c0 := int8("-0")
+let $c1 := int16("-0")
+let $c2 := int32("-0")
+let $c3 := int64("-0")
+let $c4 := int8("0")
+let $c5 := int16("0")
+let $c6 := int32("0")
+let $c7 := int64("0")
+return {"f0": numeric-round-half-to-even($c0), "f1": numeric-round-half-to-even($c1),"f2": numeric-round-half-to-even($c2), "f3": numeric-round-half-to-even($c3),
+	"f4": numeric-round-half-to-even($c4),"f5": numeric-round-half-to-even($c5) ,"f6": numeric-round-half-to-even($c6), "f7": numeric-round-half-to-even($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even1.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even1.aql
new file mode 100644
index 0000000..eeccdd7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even1.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even1.adm";
+
+
+let $c0 := int8("-20")
+let $c1 := int16("-23")
+let $c2 := int32("-29")
+let $c3 := int64("-21")
+let $c4 := int8("20")
+let $c5 := int16("22")
+let $c6 := int32("23")
+let $c7 := int64("27")
+return {"f0": numeric-round-half-to-even($c0), "f1": numeric-round-half-to-even($c1),"f2": numeric-round-half-to-even($c2), "f3": numeric-round-half-to-even($c3),
+	"f4": numeric-round-half-to-even($c4),"f5": numeric-round-half-to-even($c5) ,"f6": numeric-round-half-to-even($c6), "f7": numeric-round-half-to-even($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even2.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even2.aql
new file mode 100644
index 0000000..8b339ba
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even2.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even2.adm";
+
+
+let $c0 := float("0.5")
+let $c1 := float("-20.5")
+let $c2 := float("NaN")
+let $c3 := float("INF")
+let $c4 := float("-INF")
+let $c5 := float("-0.0")
+let $c6 := float("0.0")
+return {"f0": numeric-round-half-to-even($c0), "f1": numeric-round-half-to-even($c1),"f2": numeric-round-half-to-even($c2),
+        "f3": numeric-round-half-to-even($c3),"f4": numeric-round-half-to-even($c4),"f5": numeric-round-half-to-even($c5), "f6": numeric-round-half-to-even($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even20.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even20.aql
new file mode 100644
index 0000000..92088b4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even20.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even20.adm";
+
+
+let $c0 := int8("-0")
+let $c1 := int16("-0")
+let $c2 := int32("-0")
+let $c3 := int64("-0")
+let $c4 := int8("0")
+let $c5 := int16("0")
+let $c6 := int32("0")
+let $c7 := int64("0")
+return {"f0": numeric-round-half-to-even2($c0,2), "f1": numeric-round-half-to-even2($c1,2),"f2": numeric-round-half-to-even2($c2,2), "f3": numeric-round-half-to-even2($c3,2),
+	"f4": numeric-round-half-to-even2($c4,2),"f5": numeric-round-half-to-even2($c5,2) ,"f6": numeric-round-half-to-even2($c6,2), "f7": numeric-round-half-to-even2($c7,2)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even21.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even21.aql
new file mode 100644
index 0000000..c00cc25
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even21.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even21.adm";
+
+
+let $c0 := int8("-20")
+let $c1 := int16("-23")
+let $c2 := int32("-29")
+let $c3 := int64("-21")
+let $c4 := int8("20")
+let $c5 := int16("22")
+let $c6 := int32("23")
+let $c7 := int64("27")
+return {"f0": numeric-round-half-to-even2($c0,2), "f1": numeric-round-half-to-even2($c1,2),"f2": numeric-round-half-to-even2($c2,2), "f3": numeric-round-half-to-even2($c3,2),
+	"f4": numeric-round-half-to-even2($c4,2),"f5": numeric-round-half-to-even2($c5,2) ,"f6": numeric-round-half-to-even2($c6,2), "f7": numeric-round-half-to-even2($c7,2)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even22.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even22.aql
new file mode 100644
index 0000000..22ff5ad
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even22.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even22.adm";
+
+
+let $c0 := float("0.555")
+let $c1 := float("0.322")
+let $c2 := float("NaN")
+let $c3 := float("INF")
+let $c4 := float("-INF")
+let $c5 := float("-0.0")
+let $c6 := float("0.0")
+return {"d0": numeric-round-half-to-even2($c0,2), "d1": numeric-round-half-to-even2($c1,2),"d2": numeric-round-half-to-even2($c2,3),
+        "d3": numeric-round-half-to-even2($c3,4),"d4": numeric-round-half-to-even2($c4,5),"d5": numeric-round-half-to-even2($c5,6), "d6": numeric-round-half-to-even2($c6,0)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even23.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even23.aql
new file mode 100644
index 0000000..cbbcd10
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even23.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even23.adm";
+
+
+let $c0 := double("0.555")
+let $c1 := double("0.322")
+let $c2 := double("NaN")
+let $c3 := double("INF")
+let $c4 := double("-INF")
+let $c5 := double("-0.0")
+let $c6 := double("0.0")
+return {"d0": numeric-round-half-to-even2($c0,2), "d1": numeric-round-half-to-even2($c1,2),"d2": numeric-round-half-to-even2($c2,3),
+        "d3": numeric-round-half-to-even2($c3,4),"d4": numeric-round-half-to-even2($c4,5),"d5": numeric-round-half-to-even2($c5,6), "d6": numeric-round-half-to-even2($c6,0)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even24.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even24.aql
new file mode 100644
index 0000000..8fe21fe
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even24.aql
@@ -0,0 +1,14 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even24.adm";
+
+
+let $c0 := double("0.015")
+let $c1 := double("0.025")
+let $c2 := double("3.567812E+3")
+let $c3 := double("4.7564E-3")
+let $c4 := double("35612.25")
+return {"d0": numeric-round-half-to-even2($c0,2), "d1": numeric-round-half-to-even2($c1,2),"d2": numeric-round-half-to-even2($c2,2),
+        "d3": numeric-round-half-to-even2($c3,2),"d4": numeric-round-half-to-even2($c4,-2)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even3.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even3.aql
new file mode 100644
index 0000000..6d10ae1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even3.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even3.adm";
+
+
+let $c0 := double("0.5")
+let $c1 := double("-20.5")
+let $c2 := double("NaN")
+let $c3 := double("INF")
+let $c4 := double("-INF")
+let $c5 := double("-0.0")
+let $c6 := double("0.0")
+return {"d0": numeric-round-half-to-even($c0), "d1": numeric-round-half-to-even($c1), "d2": numeric-round-half-to-even($c2),
+        "d3": numeric-round-half-to-even($c3), "d4": numeric-round-half-to-even($c4), "d5": numeric-round-half-to-even($c5), "d6": numeric-round-half-to-even($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even4.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even4.aql
new file mode 100644
index 0000000..3c24b0b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even4.aql
@@ -0,0 +1,10 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even4.adm";
+
+
+let $c0 := double("1.5")
+let $c1 := double("2.5")
+return {"d0": numeric-round-half-to-even($c0), "d1": numeric-round-half-to-even($c1)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even5.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even5.aql
new file mode 100644
index 0000000..b89388f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round-half-to-even5.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round-half-to-even5.adm";
+
+let $c0 := int8("-20")
+return {"f0": numeric-round-half-to-even($c0), "f1": numeric-round-half-to-even(-1.5),"f2": numeric-round-half-to-even(12.5), "f3": numeric-round-half-to-even(1.5)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round0.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round0.aql
new file mode 100644
index 0000000..37887e5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round0.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round0.adm";
+
+
+let $c0 := int8("-0")
+let $c1 := int16("-0")
+let $c2 := int32("-0")
+let $c3 := int64("-0")
+let $c4 := int8("0")
+let $c5 := int16("0")
+let $c6 := int32("0")
+let $c7 := int64("0")
+return {"f0": numeric-round($c0), "f1": numeric-round($c1),"f2": numeric-round($c2), "f3": numeric-round($c3),
+	"f4": numeric-round($c4),"f5": numeric-round($c5) ,"f6": numeric-round($c6), "f7": numeric-round($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round1.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round1.aql
new file mode 100644
index 0000000..5c25bf8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round1.aql
@@ -0,0 +1,17 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round1.adm";
+
+
+let $c0 := int8("-20")
+let $c1 := int16("-23")
+let $c2 := int32("-29")
+let $c3 := int64("-21")
+let $c4 := int8("20")
+let $c5 := int16("22")
+let $c6 := int32("23")
+let $c7 := int64("27")
+return {"f0": numeric-round($c0), "f1": numeric-round($c1),"f2": numeric-round($c2), "f3": numeric-round($c3),
+	"f4": numeric-round($c4),"f5": numeric-round($c5) ,"f6": numeric-round($c6), "f7": numeric-round($c7)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round2.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round2.aql
new file mode 100644
index 0000000..e5e75bb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round2.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round2.adm";
+
+
+let $c0 := float("20.1")
+let $c1 := float("-20.56e-30")
+let $c2 := float("NaN")
+let $c3 := float("INF")
+let $c4 := float("-INF")
+let $c5 := float("-0.0")
+let $c6 := float("0.0")
+return {"f0": numeric-round($c0), "f1": numeric-round($c1),"f2": numeric-round($c2),
+        "f3": numeric-round($c3),"f4": numeric-round($c4),"f5": numeric-round($c5), "f6": numeric-round($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round3.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round3.aql
new file mode 100644
index 0000000..54e2685
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round3.aql
@@ -0,0 +1,16 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round3.adm";
+
+
+let $c0 := double("20.1")
+let $c1 := double("-20.56e-30")
+let $c2 := double("NaN")
+let $c3 := double("INF")
+let $c4 := double("-INF")
+let $c5 := double("-0.0")
+let $c6 := double("0.0")
+return {"d0": numeric-round($c0), "d1": numeric-round($c1),"d2": numeric-round($c2),
+        "d3": numeric-round($c3),"d4": numeric-round($c4),"d5": numeric-round($c5), "d6": numeric-round($c6)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/numeric/round4.aql b/asterix-app/src/test/resources/runtimets/queries/numeric/round4.aql
new file mode 100644
index 0000000..5dccfd7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/numeric/round4.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/numeric_round4.adm";
+
+let $c0 := int8("-20")
+return {"f0": numeric-round($c0), "f1": numeric-round(-1.11),"f2": numeric-round(12.9), "f3": numeric-round(1.11)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/quantifiers/everysat_02.aql b/asterix-app/src/test/resources/runtimets/queries/quantifiers/everysat_02.aql
new file mode 100644
index 0000000..fad06ba
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/quantifiers/everysat_02.aql
@@ -0,0 +1,29 @@
+/*
+ * Description      : Test Quantified Expressions 
+ *                  : every <variable-name> in [ordered-list], <variable-name> in [ordered-list] satisfies expression
+ * Expected Result  : Success
+ * Date             : 5th July 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/quantifiers_everysat_02.adm";
+
+let $a := [
+every $x in [1, 2] satisfies $x + $x = 3,
+every $x in [1, 1] satisfies $x + $x = 2,
+every $x in [1, 2] satisfies $x - 2 = 2,
+every $x in [2, 2] satisfies $x - 2 = 0,
+every $x in [1, 2] satisfies $x * 2 = 4,
+every $x in [1, 2] satisfies $x / 2 = 1,
+every $x in [1, 2] satisfies $x = 1 or $x = 2,
+every $x in [1, 2] satisfies $x = 1 and ($x +1) = 2,
+every $x in ["A","B","C"] satisfies $x = "A",
+every $x in [1,2,3], $y in [4,5,6] satisfies $x + $y = 5,
+every $x in [1,2,3], $y in [4,5,6] satisfies $x - $y = 5,
+every $x in [1,2,3], $y in [4,5,6] satisfies $x * $y = 10
+]
+for $i in $a
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/quantifiers/everysat_03.aql b/asterix-app/src/test/resources/runtimets/queries/quantifiers/everysat_03.aql
new file mode 100644
index 0000000..7f9824e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/quantifiers/everysat_03.aql
@@ -0,0 +1,33 @@
+/*
+ * Description      : Test Quantified Expressions 
+ *                  : every <variable-name> in [ordered-list], <variable-name> in [ordered-list] satisfies expression
+ * Expected Result  : Success
+ * Date             : 5th July 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/quantifiers_everysat_02.adm";
+
+let $a := [
+every $x in [1, 2] satisfies avg([$x, 1]) = 1,
+every $x in [1, 2] satisfies string($x) = "1",
+every $x in [1, 2] satisfies string-length(string($x)) = 1,
+every $x in [[1, 2],[10],[1,5,7,8]] satisfies count($x) = 1,
+every $x in [[2],[10],[8]] satisfies count($x) = 1,
+every $x in [1, 2] satisfies boolean("true"),
+every $x in [1, 2] satisfies not($x),
+every $x in [1,2,3], $y in [4,5,6] satisfies $x + $y = 5,
+every $x in [1,2,3], $y in [4,5,6] satisfies $x - $y = 5,
+every $x in [1,2,3], $y in [4,5,6] satisfies $x * $y = 10,
+every $x in [1,2,3], $y in [4,5,6] satisfies string($x) = string($y),
+every $x in [1,2,3], $y in [4,5,6] satisfies int32($x) = int32($y),
+every $x in [1,2,3], $y in [4,5,6] satisfies float($x) = float($y),
+every $x in [1,2,3], $y in [4,5,6] satisfies double($x) = double($y),
+every $x in ["true", "false"], $y in ["false","true"] satisfies boolean($x) = boolean($y),
+every $x in ["1980-05-05T13:13:13Z", "1980-05-05T13:13:13Z"], $y in ["1980-05-05T13:13:13Z","1980-05-05T13:13:13Z"] satisfies datetime($x) = datetime($y)
+]
+for $i in $a
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_03.aql b/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_03.aql
new file mode 100644
index 0000000..5995b9b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_03.aql
@@ -0,0 +1,30 @@
+/*
+ * Description     :  Test quantified expressions; some variable in [ordered list] satisfies expression.
+ * Expected Result : Success
+ * Date            : 6th July 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/quantifiers_somesat_03.adm";
+
+let $a := [
+some $x in [1, 2] satisfies $x + $x = 3,
+some $x in [1, 2] satisfies $x + $x = 2,
+some $x in [1, 2] satisfies $x - 2 = 2,
+some $x in [1, 2] satisfies $x - 2 = 0,
+some $x in [1, 2] satisfies $x * 2 = 4,
+some $x in [1, 2] satisfies $x / 2 = 1,
+some $x in [1, 2] satisfies avg([$x,1]) = 1,
+some $x in [1, 2] satisfies boolean("true"),
+some $x in [1, 2] satisfies boolean("false"),
+some $x in [1, 2] satisfies not($x),
+some $x in [1, 2] satisfies $x = 1 or $x = 2,
+some $x in [1, 2] satisfies $x = 1 and ($x +1) = 2 
+]
+for $i in $a
+return $i
+
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_04.aql b/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_04.aql
new file mode 100644
index 0000000..8d92cbb
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_04.aql
@@ -0,0 +1,28 @@
+/*
+ * Description      : Test Quantified Expressions
+ *                  : some <variable-name> in [ordered-list] satisfies function expression
+ *                  : some <variable-name> in [ordered-list],<variable-name> in [ordered-list] satisfies expression
+ * Expected Result  : Success
+ * Date             : 5th July 2012
+ */
+
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/quantifiers_somesat_04.adm";
+
+let $a := [
+some $x in ["foo","foobar","foot","fox"] satisfies string-length($x) = 1,
+some $x in [1,2,3,4,5,6,7,8] satisfies count($x) = 8,
+some $x in [1, 2] satisfies $x = 1 or $x = 2,
+some $x in [1, 2] satisfies $x = 1 and ($x +1) = 2,
+some $x in ["A","B","C"] satisfies $x = "A",
+some $x in [1,2,3], $y in [4,5,6] satisfies $x + $y = 5,
+some $x in [1,2,3], $y in [4,5,6] satisfies $x - $y = 5,
+some $x in [1,2,3], $y in [4,5,6] satisfies $x * $y = 10,
+some $x in [1,2,3], $y in [4,5,6] satisfies $x / $y = 2
+]
+for $i in $a
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_05.aql b/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_05.aql
new file mode 100644
index 0000000..fefd86d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/quantifiers/somesat_05.aql
@@ -0,0 +1,24 @@
+/*
+ * Description      :  Test Quantified Expressions 
+ *                  :  some <variable-name> in [ordered-list], <variable-name> in [ordered-list] satisfies function expression
+ * Expected Result  :  Success
+ * Date             :  5th July 2012
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/quantifiers_somesat_05.adm";
+
+let $a := [
+some $x in ["foo","foobar","footnote"], $y in ["foofoo","fool","foolish","foot","foo"] satisfies string($x) = string($y),
+some $x in ["1","2","3"], $y in ["4","5","6"] satisfies int32($x) = int32($y),
+some $x in ["1.1","2.2","3.3"], $y in ["4.4","5.5","6.6"] satisfies float($x) = float($y),
+some $x in ["1.1d","2.2d","3.3d"], $y in ["4.4d","5.5d","6.6d"] satisfies double($x) = double($y),
+some $x in ["true", "false"], $y in ["false","true"] satisfies boolean($x) = boolean($y),
+some $x in ["1980-05-05T13:13:13Z", "1980-05-05T13:13:13Z"], $y in ["1980-05-05T13:13:13Z","1980-05-05T13:13:13Z"] satisfies datetime($x) = datetime($y),
+some $x in ["1985-07-05Z", "1985-07-05Z"], $y in ["1985-07-05Z","1985-07-05Z"] satisfies date($x) = date($y)
+]
+for $i in $a
+return $i
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/codepoint-to-string1.aql b/asterix-app/src/test/resources/runtimets/queries/string/codepoint-to-string1.aql
new file mode 100644
index 0000000..a97e441
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/codepoint-to-string1.aql
@@ -0,0 +1,9 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_codepoint-to-string1.adm";
+
+let $x :=  [20013, 25991, 23383, 31526]
+let $c := codepoint-to-string($x)
+return {"result1": $c}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/codepoint-to-string2.aql b/asterix-app/src/test/resources/runtimets/queries/string/codepoint-to-string2.aql
new file mode 100644
index 0000000..829a082
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/codepoint-to-string2.aql
@@ -0,0 +1,12 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_codepoint-to-string2.adm";
+
+let $x1 :=  []
+let $c1 := codepoint-to-string($x1)
+
+let $x2 :=  [97,98,99]
+let $c2 := codepoint-to-string($x2)
+return {"f1": $c1, "f2" : $c2}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/concat1.aql b/asterix-app/src/test/resources/runtimets/queries/string/concat1.aql
new file mode 100644
index 0000000..a6ce63b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/concat1.aql
@@ -0,0 +1,12 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_concat1.adm";
+
+let $x :=  ["aa", "25991", "bb", "31526"]
+let $c := string-concat($x)
+
+let $x1 :=  []
+let $c1 := string-concat($x1)
+return {"result1": $c,"result2": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/end-with1.aql b/asterix-app/src/test/resources/runtimets/queries/string/end-with1.aql
new file mode 100644
index 0000000..98e0624
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/end-with1.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_end-with1.adm";
+
+let $c1 := end-with("hello world","werld")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/end-with2.aql b/asterix-app/src/test/resources/runtimets/queries/string/end-with2.aql
new file mode 100644
index 0000000..0e53f94
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/end-with2.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_end-with2.adm";
+
+let $c1 := end-with("hello world"," world")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/end-with3.aql b/asterix-app/src/test/resources/runtimets/queries/string/end-with3.aql
new file mode 100644
index 0000000..f71c320
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/end-with3.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_end-with3.adm";
+
+let $c1 := end-with("ends","")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/end-with4.aql b/asterix-app/src/test/resources/runtimets/queries/string/end-with4.aql
new file mode 100644
index 0000000..ca02d57
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/end-with4.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_end-with4.adm";
+
+let $c1 := end-with("ends","ss")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/end-with5.aql b/asterix-app/src/test/resources/runtimets/queries/string/end-with5.aql
new file mode 100644
index 0000000..510beb3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/end-with5.aql
@@ -0,0 +1,14 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_end-with5.adm";
+
+let $c1 := end-with("ends","s")
+let $c2 := end-with("start",null)
+let $c3 := end-with(null,null)
+let $c4 := end-with("",null)
+let $c5 := end-with("","")
+let $c6 := end-with(null,"")
+
+return {"f1": $c1, "f2": $c2, "f3": $c3, "f4": $c4, "f5": $c5, "f6": $c6}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/length.aql b/asterix-app/src/test/resources/runtimets/queries/string/length.aql
new file mode 100644
index 0000000..d78d986
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/length.aql
@@ -0,0 +1,10 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_length.adm";
+
+let $c1 := string-length("hellow")
+let $c2 := string-length("")
+let $c3 := string-length(null)
+return {"result1": $c1, "result2": $c2, "result3": $c3}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/lowercase.aql b/asterix-app/src/test/resources/runtimets/queries/string/lowercase.aql
new file mode 100644
index 0000000..4c45007
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/lowercase.aql
@@ -0,0 +1,10 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_lowercase.adm";
+
+let $c1 := lowercase("HEllow")
+let $c2 := lowercase("")
+let $c3 := lowercase(null)
+return {"result1": $c1, "result2": $c2, "result3": $c3}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches1.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches1.aql
new file mode 100644
index 0000000..f81932a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches1.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_matches1.adm";
+
+let $c1 := matches("abracadabra","bra")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches2.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches2.aql
new file mode 100644
index 0000000..af5246e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches2.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_matches2.adm";
+
+let $c1 := matches("abracadabra","^a.*a$")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches21.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches21.aql
new file mode 100644
index 0000000..19f9591
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches21.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_matches21.adm";
+
+let $c1 := matches2("abracadabra","Bra","")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches22.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches22.aql
new file mode 100644
index 0000000..b8d7b96
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches22.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_matches22.adm";
+
+let $c1 := matches2("abracadabra","Bra","i")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches23.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches23.aql
new file mode 100644
index 0000000..508699d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches23.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_matches23.adm";
+
+let $c1 := matches2("helloworld","hello world","x")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matches3.aql b/asterix-app/src/test/resources/runtimets/queries/string/matches3.aql
new file mode 100644
index 0000000..19c6350
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matches3.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_matches3.adm";
+
+let $c1 := matches("abracadabra","^bra")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/matchesnull.aql b/asterix-app/src/test/resources/runtimets/queries/string/matchesnull.aql
new file mode 100644
index 0000000..8e2f1a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/matchesnull.aql
@@ -0,0 +1,13 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_matchesnull.adm";
+
+let $c1 := matches("helloworld",null)
+let $c2 := matches("",null)
+let $c3 := matches(null,null)
+let $c4 := matches2("helloworld",null, "")
+let $c5 := matches2("",null, "i")
+let $c6 := matches2(null,null, null)
+return {"result1": $c1, "result2": $c2, "result3": $c3, "result4": $c4, "result5": $c5, "result6": $c6}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/replace1.aql b/asterix-app/src/test/resources/runtimets/queries/string/replace1.aql
new file mode 100644
index 0000000..3a9e932
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/replace1.aql
@@ -0,0 +1,10 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_replace1.adm";
+
+let $c1 := replace("abracadabra", "a", "")
+let $c2 := replace("abracadabra", "a(.)", "a$1$1")
+let $c3 := replace("darted", "^(.*?)d(.*)$", "$1c$2")
+return {"result1": $c1, "result2": $c2, "result3": $c3}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/replace2.aql b/asterix-app/src/test/resources/runtimets/queries/string/replace2.aql
new file mode 100644
index 0000000..9b924f2
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/replace2.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_replace2.adm";
+
+let $c1 := replace("abracadabra", "bra", "*")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/replace21.aql b/asterix-app/src/test/resources/runtimets/queries/string/replace21.aql
new file mode 100644
index 0000000..77c0c90
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/replace21.aql
@@ -0,0 +1,10 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_replace21.adm";
+
+let $c1 := replace2("abracadabra","Bra", "kkk" , "")
+let $c2 := replace2("abracadabra","Bra", "kkk" ,"i")
+let $c3 := replace2("helloworld","hello world", "kkk" , "x")
+return {"result1": $c1,"result2": $c2,"result3": $c3}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/replace22.aql b/asterix-app/src/test/resources/runtimets/queries/string/replace22.aql
new file mode 100644
index 0000000..2a0d5d6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/replace22.aql
@@ -0,0 +1,15 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_replace22.adm";
+
+let $c1 := replace2("abracadabra","", null , null)
+let $c2 := replace2("abracadabra","bra", "XXX" ,"")
+let $c3 := replace2(null,"hello world", "XxXx" , "x")
+let $c4 := replace2("abracadabra","bra", "XXX" ,null)
+let $c5 := replace2("abracadabra",null, "XXX" ,null)
+let $c6 := replace2("abracadabra","Bra", null ,"i")
+let $c7 := replace2("abracadabra","Bra", "" ,"i")
+let $c8 := replace2("abracadabra","", "XXX" ,"")
+return {"result1": $c1,"result2": $c2,"result3": $c3,"result4": $c4,"result5": $c5,"result6": $c6,"result7": $c7,"result8": $c8}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/replace3.aql b/asterix-app/src/test/resources/runtimets/queries/string/replace3.aql
new file mode 100644
index 0000000..c1892dd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/replace3.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_replace3.adm";
+
+let $c1 := replace("abracadabra", "a.*a", "*")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/start-with1.aql b/asterix-app/src/test/resources/runtimets/queries/string/start-with1.aql
new file mode 100644
index 0000000..11ac150
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/start-with1.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_start-with1.adm";
+
+let $c1 := start-with("start","st")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/start-with2.aql b/asterix-app/src/test/resources/runtimets/queries/string/start-with2.aql
new file mode 100644
index 0000000..6d02c9a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/start-with2.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_start-with2.adm";
+
+let $c1 := start-with("start","t")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/start-with3.aql b/asterix-app/src/test/resources/runtimets/queries/string/start-with3.aql
new file mode 100644
index 0000000..a70dc33
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/start-with3.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_start-with3.adm";
+
+let $c1 := start-with("start","start")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/start-with4.aql b/asterix-app/src/test/resources/runtimets/queries/string/start-with4.aql
new file mode 100644
index 0000000..3629093
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/start-with4.aql
@@ -0,0 +1,14 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_start-with4.adm";
+
+let $c1 := start-with("start","")
+let $c2 := start-with("start",null)
+let $c3 := start-with(null,null)
+let $c4 := start-with("",null)
+let $c5 := start-with("","")
+let $c6 := start-with(null,"")
+
+return {"f1": $c1, "f2": $c2, "f3": $c3, "f4": $c4, "f5": $c5, "f6": $c6}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/start-with5.aql b/asterix-app/src/test/resources/runtimets/queries/string/start-with5.aql
new file mode 100644
index 0000000..33a0b8e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/start-with5.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_start-with5.adm";
+
+let $c1 := start-with("","s")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/string-concat1.aql b/asterix-app/src/test/resources/runtimets/queries/string/string-concat1.aql
new file mode 100644
index 0000000..b31e33c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/string-concat1.aql
@@ -0,0 +1,9 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_string-concat1.adm";
+
+let $x :=  ["aa", "25991", "bb", "31526"]
+let $c := string-concat($x)
+return {"result1": $c}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/string-equal1.aql b/asterix-app/src/test/resources/runtimets/queries/string/string-equal1.aql
new file mode 100644
index 0000000..62ec56d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/string-equal1.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_string-equal1.adm";
+
+let $c1 := string-equal("test","tess")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/string-equal2.aql b/asterix-app/src/test/resources/runtimets/queries/string/string-equal2.aql
new file mode 100644
index 0000000..a102802
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/string-equal2.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_string-equal2.adm";
+
+let $c1 := string-equal("test","test")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/string-equal3.aql b/asterix-app/src/test/resources/runtimets/queries/string/string-equal3.aql
new file mode 100644
index 0000000..2749390
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/string-equal3.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_string-equal3.adm";
+
+let $c1 := string-equal("test11","test")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/string-equal4.aql b/asterix-app/src/test/resources/runtimets/queries/string/string-equal4.aql
new file mode 100644
index 0000000..f1cf243
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/string-equal4.aql
@@ -0,0 +1,11 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_string-equal4.adm";
+
+let $c1 := string-equal("","")
+let $c3 := string-equal(null,"")
+let $c4 := string-equal("",null)
+let $c5 := string-equal(null,null)
+return {"result1": $c1, "result3": $c3, "result4": $c4, "result5": $c5}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/string-join1.aql b/asterix-app/src/test/resources/runtimets/queries/string/string-join1.aql
new file mode 100644
index 0000000..0ea2bdd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/string-join1.aql
@@ -0,0 +1,11 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_string-join1.adm";
+
+let $x :=  ["aa", "25991", "bb", "31526"]
+let $s := "::"
+let $c := string-join($x,$s)
+let $c1 := string-join($x,"")
+return {"result0": $c,"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/string-to-codepoint.aql b/asterix-app/src/test/resources/runtimets/queries/string/string-to-codepoint.aql
new file mode 100644
index 0000000..2f1daba
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/string-to-codepoint.aql
@@ -0,0 +1,9 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_string-to-codepoint.adm";
+
+let $x :=  "abcd"
+let $c := string-to-codepoint($x)
+return {"result1": $c}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/string-to-codepoint1.aql b/asterix-app/src/test/resources/runtimets/queries/string/string-to-codepoint1.aql
new file mode 100644
index 0000000..5bcfd16
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/string-to-codepoint1.aql
@@ -0,0 +1,10 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_string-to-codepoint1.adm";
+
+let $x :=  ""
+let $c := string-to-codepoint($x)
+
+return {"result1": $c}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring-after-1.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring-after-1.aql
new file mode 100644
index 0000000..6c45bc8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring-after-1.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring-after-1.adm";
+
+let $c1 := substring-after("HEllow","El")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring-after-2.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring-after-2.aql
new file mode 100644
index 0000000..78d6cad
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring-after-2.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring-after-2.adm";
+
+let $c1 := substring-after("HEllow","1")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring-after-3.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring-after-3.aql
new file mode 100644
index 0000000..91c3cab
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring-after-3.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring-after-3.adm";
+
+let $c1 := substring-after("HEllow","HEllow")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring-after-4.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring-after-4.aql
new file mode 100644
index 0000000..73a983f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring-after-4.aql
@@ -0,0 +1,12 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring-after-4.adm";
+
+let $c1 := substring-after("HEllow","")
+let $c2 := substring-after("HEllow",null)
+let $c3 := substring-after("",null)
+let $c4 := substring-after("","")
+let $c5 := substring-after(null,null)
+return {"result1": $c1, "result2": $c2, "result3": $c3, "result4": $c4, "result5": $c5}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring-before-1.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring-before-1.aql
new file mode 100644
index 0000000..1fe3a36
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring-before-1.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring-before-1.adm";
+
+let $c1 := substring-before("HEllow","ll")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring-before-2.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring-before-2.aql
new file mode 100644
index 0000000..4f59c43
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring-before-2.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring-before-2.adm";
+
+let $c1 := substring-before("HEllow","HEllow")
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring-before-3.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring-before-3.aql
new file mode 100644
index 0000000..9e40615
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring-before-3.aql
@@ -0,0 +1,12 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring-before-3.adm";
+
+let $c1 := substring-before("HEllow","")
+let $c2 := substring-before("HEllow",null)
+let $c3 := substring-before("",null)
+let $c4 := substring-before("","")
+let $c5 := substring-before(null,null)
+return {"result1": $c1, "result2": $c2, "result3": $c3, "result4": $c4, "result5": $c5}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring2-1.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring2-1.aql
new file mode 100644
index 0000000..78beb56
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring2-1.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring2-1.adm";
+
+let $c1 := substring2("HEllow",2)
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring2-2.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring2-2.aql
new file mode 100644
index 0000000..b310c9f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring2-2.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring2-2.adm";
+
+let $c1 := substring2("HEllow",0)
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring2-3.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring2-3.aql
new file mode 100644
index 0000000..70725b6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring2-3.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring2-3.adm";
+
+let $c1 := substring2("HEllow",10)
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/queries/string/substring2-4.aql b/asterix-app/src/test/resources/runtimets/queries/string/substring2-4.aql
new file mode 100644
index 0000000..1a1065a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/string/substring2-4.aql
@@ -0,0 +1,8 @@
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+write output to nc1:"rttest/string_substring2-4.adm";
+
+let $c1 := substring2("HEllow",-1)
+return {"result1": $c1}
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/add-null.adm b/asterix-app/src/test/resources/runtimets/results/constructor/add-null.adm
new file mode 100644
index 0000000..19765bd
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/add-null.adm
@@ -0,0 +1 @@
+null
diff --git a/asterix-app/src/test/resources/runtimets/results/dml/drop-index.adm b/asterix-app/src/test/resources/runtimets/results/dml/drop-index.adm
new file mode 100644
index 0000000..f3c688b
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/dml/drop-index.adm
@@ -0,0 +1 @@
+{ "unique1": 84, "unique2": 10, "two": 0, "four": 0, "ten": 4, "twenty": 4, "onePercent": 84, "tenPercent": 4, "twentyPercent": 4, "fiftyPercent": 0, "unique3": 84, "evenOnePercent": 168, "oddOnePercent": 169, "stringu1": "DGAAAAXXXXXXXXXXXXXXXXXXX", "stringu2": "KAAAAAXXXXXXXXXXXXXXXXXXX", "string4": "OOOOXXXXXXXXXXXXXXXXXXXXXX" }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/abs0.adm b/asterix-app/src/test/resources/runtimets/results/numeric/abs0.adm
new file mode 100644
index 0000000..61c5048
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/abs0.adm
@@ -0,0 +1 @@
+{ "f0": 0i8, "f1": 0i16, "f2": 0, "f3": 0i64, "f4": 0i8, "f5": 0i16, "f6": 0, "f7": 0i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/abs1.adm b/asterix-app/src/test/resources/runtimets/results/numeric/abs1.adm
new file mode 100644
index 0000000..263ae97
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/abs1.adm
@@ -0,0 +1 @@
+{ "f0": 20i8, "f1": 23i16, "f2": 29, "f3": 21i64, "f4": 20i8, "f5": 22i16, "f6": 23, "f7": 27i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/abs2.adm b/asterix-app/src/test/resources/runtimets/results/numeric/abs2.adm
new file mode 100644
index 0000000..a4bcbe8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/abs2.adm
@@ -0,0 +1 @@
+{ "f0": 20.1f, "f1": 2.056E-29f, "f2": NaNf, "f3": Infinityf, "f4": Infinityf, "f5": 0.0f, "f6": 0.0f }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/abs3.adm b/asterix-app/src/test/resources/runtimets/results/numeric/abs3.adm
new file mode 100644
index 0000000..4da3272
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/abs3.adm
@@ -0,0 +1 @@
+{ "d0": 20.1d, "d1": 2.056E-29d, "d2": NaNd, "d3": Infinityd, "d4": Infinityd, "d5": 0.0d, "d6": 0.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/abs4.adm b/asterix-app/src/test/resources/runtimets/results/numeric/abs4.adm
new file mode 100644
index 0000000..f365181
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/abs4.adm
@@ -0,0 +1 @@
+{ "f0": 20i8, "f1": 1.11d, "f2": 12.9d, "f3": 1.11d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/ceiling0.adm b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling0.adm
new file mode 100644
index 0000000..61c5048
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling0.adm
@@ -0,0 +1 @@
+{ "f0": 0i8, "f1": 0i16, "f2": 0, "f3": 0i64, "f4": 0i8, "f5": 0i16, "f6": 0, "f7": 0i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/ceiling1.adm b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling1.adm
new file mode 100644
index 0000000..bf278a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling1.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -23i16, "f2": -29, "f3": -21i64, "f4": 20i8, "f5": 22i16, "f6": 23, "f7": 27i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/ceiling2.adm b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling2.adm
new file mode 100644
index 0000000..96e5d3d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling2.adm
@@ -0,0 +1 @@
+{ "f0": 21.0f, "f1": -0.0f, "f2": NaNf, "f3": Infinityf, "f4": -Infinityf, "f5": -0.0f, "f6": 0.0f }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/ceiling3.adm b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling3.adm
new file mode 100644
index 0000000..bf497d4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling3.adm
@@ -0,0 +1 @@
+{ "d0": 21.0d, "d1": -0.0d, "d2": NaNd, "d3": Infinityd, "d4": -Infinityd, "d5": -0.0d, "d6": 0.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/ceiling4.adm b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling4.adm
new file mode 100644
index 0000000..dcc17c0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/ceiling4.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -1.0d, "f2": 13.0d, "f3": 2.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/floor0.adm b/asterix-app/src/test/resources/runtimets/results/numeric/floor0.adm
new file mode 100644
index 0000000..61c5048
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/floor0.adm
@@ -0,0 +1 @@
+{ "f0": 0i8, "f1": 0i16, "f2": 0, "f3": 0i64, "f4": 0i8, "f5": 0i16, "f6": 0, "f7": 0i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/floor1.adm b/asterix-app/src/test/resources/runtimets/results/numeric/floor1.adm
new file mode 100644
index 0000000..bf278a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/floor1.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -23i16, "f2": -29, "f3": -21i64, "f4": 20i8, "f5": 22i16, "f6": 23, "f7": 27i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/floor2.adm b/asterix-app/src/test/resources/runtimets/results/numeric/floor2.adm
new file mode 100644
index 0000000..078d159
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/floor2.adm
@@ -0,0 +1 @@
+{ "f0": 20.0f, "f1": -1.0f, "f2": NaNf, "f3": Infinityf, "f4": -Infinityf, "f5": -0.0f, "f6": 0.0f }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/floor3.adm b/asterix-app/src/test/resources/runtimets/results/numeric/floor3.adm
new file mode 100644
index 0000000..58bdd79
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/floor3.adm
@@ -0,0 +1 @@
+{ "d0": 20.0d, "d1": -1.0d, "d2": NaNd, "d3": Infinityd, "d4": -Infinityd, "d5": -0.0d, "d6": 0.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/floor4.adm b/asterix-app/src/test/resources/runtimets/results/numeric/floor4.adm
new file mode 100644
index 0000000..3e972b3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/floor4.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -2.0d, "f2": 12.0d, "f3": 1.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even0.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even0.adm
new file mode 100644
index 0000000..61c5048
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even0.adm
@@ -0,0 +1 @@
+{ "f0": 0i8, "f1": 0i16, "f2": 0, "f3": 0i64, "f4": 0i8, "f5": 0i16, "f6": 0, "f7": 0i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even1.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even1.adm
new file mode 100644
index 0000000..bf278a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even1.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -23i16, "f2": -29, "f3": -21i64, "f4": 20i8, "f5": 22i16, "f6": 23, "f7": 27i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even2.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even2.adm
new file mode 100644
index 0000000..f5f9e3f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even2.adm
@@ -0,0 +1 @@
+{ "f0": 0.0f, "f1": -20.0f, "f2": NaNf, "f3": Infinityf, "f4": -Infinityf, "f5": -0.0f, "f6": 0.0f }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even20.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even20.adm
new file mode 100644
index 0000000..61c5048
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even20.adm
@@ -0,0 +1 @@
+{ "f0": 0i8, "f1": 0i16, "f2": 0, "f3": 0i64, "f4": 0i8, "f5": 0i16, "f6": 0, "f7": 0i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even21.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even21.adm
new file mode 100644
index 0000000..bf278a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even21.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -23i16, "f2": -29, "f3": -21i64, "f4": 20i8, "f5": 22i16, "f6": 23, "f7": 27i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even22.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even22.adm
new file mode 100644
index 0000000..3f0cead
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even22.adm
@@ -0,0 +1 @@
+{ "d0": 0.56f, "d1": 0.32f, "d2": NaNf, "d3": Infinityf, "d4": -Infinityf, "d5": -0.0f, "d6": 0.0f }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even23.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even23.adm
new file mode 100644
index 0000000..914a79e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even23.adm
@@ -0,0 +1 @@
+{ "d0": 0.56d, "d1": 0.32d, "d2": NaNd, "d3": Infinityd, "d4": -Infinityd, "d5": -0.0d, "d6": 0.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even24.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even24.adm
new file mode 100644
index 0000000..956f0ac
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even24.adm
@@ -0,0 +1 @@
+{ "d0": 0.02d, "d1": 0.02d, "d2": 3567.81d, "d3": 0.0d, "d4": 35600.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even3.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even3.adm
new file mode 100644
index 0000000..60b7c52
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even3.adm
@@ -0,0 +1 @@
+{ "d0": 0.0d, "d1": -20.0d, "d2": NaNd, "d3": Infinityd, "d4": -Infinityd, "d5": -0.0d, "d6": 0.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even4.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even4.adm
new file mode 100644
index 0000000..5620cde
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even4.adm
@@ -0,0 +1 @@
+{ "d0": 2.0d, "d1": 2.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even5.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even5.adm
new file mode 100644
index 0000000..a53f62f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even5.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -2.0d, "f2": 12.0d, "f3": 2.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round0.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round0.adm
new file mode 100644
index 0000000..61c5048
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round0.adm
@@ -0,0 +1 @@
+{ "f0": 0i8, "f1": 0i16, "f2": 0, "f3": 0i64, "f4": 0i8, "f5": 0i16, "f6": 0, "f7": 0i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round1.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round1.adm
new file mode 100644
index 0000000..bf278a1
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round1.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -23i16, "f2": -29, "f3": -21i64, "f4": 20i8, "f5": 22i16, "f6": 23, "f7": 27i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round2.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round2.adm
new file mode 100644
index 0000000..791c1da
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round2.adm
@@ -0,0 +1 @@
+{ "f0": 20.0f, "f1": 0.0f, "f2": 0.0f, "f3": 2.14748365E9f, "f4": -2.14748365E9f, "f5": 0.0f, "f6": 0.0f }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round3.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round3.adm
new file mode 100644
index 0000000..1b1936d
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round3.adm
@@ -0,0 +1 @@
+{ "d0": 20.0d, "d1": 0.0d, "d2": 0.0d, "d3": 9.223372036854776E18d, "d4": -9.223372036854776E18d, "d5": 0.0d, "d6": 0.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/numeric/round4.adm b/asterix-app/src/test/resources/runtimets/results/numeric/round4.adm
new file mode 100644
index 0000000..ce70363
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/numeric/round4.adm
@@ -0,0 +1 @@
+{ "f0": -20i8, "f1": -1.0d, "f2": 13.0d, "f3": 1.0d }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/codepoint-to-string1.adm b/asterix-app/src/test/resources/runtimets/results/string/codepoint-to-string1.adm
new file mode 100644
index 0000000..fdbb861
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/codepoint-to-string1.adm
@@ -0,0 +1 @@
+{ "result1": "中文字符" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/codepoint-to-string2.adm b/asterix-app/src/test/resources/runtimets/results/string/codepoint-to-string2.adm
new file mode 100644
index 0000000..8ab1bd7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/codepoint-to-string2.adm
@@ -0,0 +1 @@
+{ "f1": "", "f2": "abc" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/concat1.adm b/asterix-app/src/test/resources/runtimets/results/string/concat1.adm
new file mode 100644
index 0000000..cea6e76
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/concat1.adm
@@ -0,0 +1 @@
+{ "result1": "aa25991bb31526", "result2": "" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/end-with1.adm b/asterix-app/src/test/resources/runtimets/results/string/end-with1.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/end-with1.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/end-with2.adm b/asterix-app/src/test/resources/runtimets/results/string/end-with2.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/end-with2.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/end-with3.adm b/asterix-app/src/test/resources/runtimets/results/string/end-with3.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/end-with3.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/end-with4.adm b/asterix-app/src/test/resources/runtimets/results/string/end-with4.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/end-with4.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/end-with5.adm b/asterix-app/src/test/resources/runtimets/results/string/end-with5.adm
new file mode 100644
index 0000000..c13d3dc
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/end-with5.adm
@@ -0,0 +1 @@
+{ "f1": true, "f2": false, "f3": true, "f4": false, "f5": true, "f6": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/length.adm b/asterix-app/src/test/resources/runtimets/results/string/length.adm
new file mode 100644
index 0000000..45a976e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/length.adm
@@ -0,0 +1 @@
+{ "result1": 6, "result2": 0, "result3": null }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/lowercase.adm b/asterix-app/src/test/resources/runtimets/results/string/lowercase.adm
new file mode 100644
index 0000000..a20b9aa
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/lowercase.adm
@@ -0,0 +1 @@
+{ "result1": "hellow", "result2": "", "result3": null }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/matches1.adm b/asterix-app/src/test/resources/runtimets/results/string/matches1.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/matches1.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/matches2.adm b/asterix-app/src/test/resources/runtimets/results/string/matches2.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/matches2.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/matches21.adm b/asterix-app/src/test/resources/runtimets/results/string/matches21.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/matches21.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/matches22.adm b/asterix-app/src/test/resources/runtimets/results/string/matches22.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/matches22.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/matches23.adm b/asterix-app/src/test/resources/runtimets/results/string/matches23.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/matches23.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/matches3.adm b/asterix-app/src/test/resources/runtimets/results/string/matches3.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/matches3.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/matchesnull.adm b/asterix-app/src/test/resources/runtimets/results/string/matchesnull.adm
new file mode 100644
index 0000000..6126426
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/matchesnull.adm
@@ -0,0 +1 @@
+{ "result1": false, "result2": false, "result3": true, "result4": false, "result5": false, "result6": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/replace1.adm b/asterix-app/src/test/resources/runtimets/results/string/replace1.adm
new file mode 100644
index 0000000..5f992ce
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/replace1.adm
@@ -0,0 +1 @@
+{ "result1": "brcdbr", "result2": "abbraccaddabbra", "result3": "carted" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/replace2.adm b/asterix-app/src/test/resources/runtimets/results/string/replace2.adm
new file mode 100644
index 0000000..fa45140
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/replace2.adm
@@ -0,0 +1 @@
+{ "result1": "a*cada*" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/replace21.adm b/asterix-app/src/test/resources/runtimets/results/string/replace21.adm
new file mode 100644
index 0000000..9fd2e6a
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/replace21.adm
@@ -0,0 +1 @@
+{ "result1": "abracadabra", "result2": "akkkcadakkk", "result3": "kkk" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/replace22.adm b/asterix-app/src/test/resources/runtimets/results/string/replace22.adm
new file mode 100644
index 0000000..21ca784
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/replace22.adm
@@ -0,0 +1 @@
+{ "result1": "abracadabra", "result2": "aXXXcadaXXX", "result3": null, "result4": "aXXXcadaXXX", "result5": "XXXaXXXbXXXrXXXaXXXcXXXaXXXdXXXaXXXbXXXrXXXaXXX", "result6": "acada", "result7": "acada", "result8": "XXXaXXXbXXXrXXXaXXXcXXXaXXXdXXXaXXXbXXXrXXXaXXX" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/replace3.adm b/asterix-app/src/test/resources/runtimets/results/string/replace3.adm
new file mode 100644
index 0000000..3882682
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/replace3.adm
@@ -0,0 +1 @@
+{ "result1": "*" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/start-with1.adm b/asterix-app/src/test/resources/runtimets/results/string/start-with1.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/start-with1.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/start-with2.adm b/asterix-app/src/test/resources/runtimets/results/string/start-with2.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/start-with2.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/start-with3.adm b/asterix-app/src/test/resources/runtimets/results/string/start-with3.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/start-with3.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/start-with4.adm b/asterix-app/src/test/resources/runtimets/results/string/start-with4.adm
new file mode 100644
index 0000000..c13d3dc
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/start-with4.adm
@@ -0,0 +1 @@
+{ "f1": true, "f2": false, "f3": true, "f4": false, "f5": true, "f6": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/start-with5.adm b/asterix-app/src/test/resources/runtimets/results/string/start-with5.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/start-with5.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-concat1.adm b/asterix-app/src/test/resources/runtimets/results/string/string-concat1.adm
new file mode 100644
index 0000000..a5becc3
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-concat1.adm
@@ -0,0 +1 @@
+{ "result1": "aa25991bb31526" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-equal-true1.adm b/asterix-app/src/test/resources/runtimets/results/string/string-equal-true1.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-equal-true1.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-equal1.adm b/asterix-app/src/test/resources/runtimets/results/string/string-equal1.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-equal1.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-equal2.adm b/asterix-app/src/test/resources/runtimets/results/string/string-equal2.adm
new file mode 100644
index 0000000..538da31
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-equal2.adm
@@ -0,0 +1 @@
+{ "result1": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-equal3.adm b/asterix-app/src/test/resources/runtimets/results/string/string-equal3.adm
new file mode 100644
index 0000000..ea9ca72
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-equal3.adm
@@ -0,0 +1 @@
+{ "result1": false }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-equal4.adm b/asterix-app/src/test/resources/runtimets/results/string/string-equal4.adm
new file mode 100644
index 0000000..71a9bb6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-equal4.adm
@@ -0,0 +1 @@
+{ "result1": true, "result3": false, "result4": false, "result5": true }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-join1.adm b/asterix-app/src/test/resources/runtimets/results/string/string-join1.adm
new file mode 100644
index 0000000..7276381
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-join1.adm
@@ -0,0 +1 @@
+{ "result0": "aa::25991::bb::31526", "result1": "aa25991bb31526" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-to-codepoint.adm b/asterix-app/src/test/resources/runtimets/results/string/string-to-codepoint.adm
new file mode 100644
index 0000000..c67c60e
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-to-codepoint.adm
@@ -0,0 +1 @@
+{ "result1": [ 97, 98, 99, 100 ] }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/string-to-codepoint1.adm b/asterix-app/src/test/resources/runtimets/results/string/string-to-codepoint1.adm
new file mode 100644
index 0000000..46eca36
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/string-to-codepoint1.adm
@@ -0,0 +1 @@
+{ "result1": [  ] }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring-after-1.adm b/asterix-app/src/test/resources/runtimets/results/string/substring-after-1.adm
new file mode 100644
index 0000000..197a7af
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring-after-1.adm
@@ -0,0 +1 @@
+{ "result1": "low" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring-after-2.adm b/asterix-app/src/test/resources/runtimets/results/string/substring-after-2.adm
new file mode 100644
index 0000000..04393a4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring-after-2.adm
@@ -0,0 +1 @@
+{ "result1": "" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring-after-3.adm b/asterix-app/src/test/resources/runtimets/results/string/substring-after-3.adm
new file mode 100644
index 0000000..04393a4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring-after-3.adm
@@ -0,0 +1 @@
+{ "result1": "" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring-after-4.adm b/asterix-app/src/test/resources/runtimets/results/string/substring-after-4.adm
new file mode 100644
index 0000000..9406ef5
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring-after-4.adm
@@ -0,0 +1 @@
+{ "result1": "HEllow", "result2": "HEllow", "result3": "", "result4": "", "result5": "" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring-before-1.adm b/asterix-app/src/test/resources/runtimets/results/string/substring-before-1.adm
new file mode 100644
index 0000000..1c6a7d7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring-before-1.adm
@@ -0,0 +1 @@
+{ "result1": "HE" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring-before-2.adm b/asterix-app/src/test/resources/runtimets/results/string/substring-before-2.adm
new file mode 100644
index 0000000..04393a4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring-before-2.adm
@@ -0,0 +1 @@
+{ "result1": "" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring-before-3.adm b/asterix-app/src/test/resources/runtimets/results/string/substring-before-3.adm
new file mode 100644
index 0000000..9ce64e4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring-before-3.adm
@@ -0,0 +1 @@
+{ "result1": "", "result2": "", "result3": "", "result4": "", "result5": "" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring2-1.adm b/asterix-app/src/test/resources/runtimets/results/string/substring2-1.adm
new file mode 100644
index 0000000..411e803
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring2-1.adm
@@ -0,0 +1 @@
+{ "result1": "Ellow" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring2-2.adm b/asterix-app/src/test/resources/runtimets/results/string/substring2-2.adm
new file mode 100644
index 0000000..5b0c7b9
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring2-2.adm
@@ -0,0 +1 @@
+{ "result1": "HEllow" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring2-3.adm b/asterix-app/src/test/resources/runtimets/results/string/substring2-3.adm
new file mode 100644
index 0000000..04393a4
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring2-3.adm
@@ -0,0 +1 @@
+{ "result1": "" }
diff --git a/asterix-app/src/test/resources/runtimets/results/string/substring2-4.adm b/asterix-app/src/test/resources/runtimets/results/string/substring2-4.adm
new file mode 100644
index 0000000..5b0c7b9
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/string/substring2-4.adm
@@ -0,0 +1 @@
+{ "result1": "HEllow" }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/base/ILiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/base/ILiteral.java
deleted file mode 100644
index 31cb27e..0000000
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/base/ILiteral.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2009-2010 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.base;
-
-import java.io.Serializable;
-
-public interface ILiteral extends Serializable {
-    public enum Type {
-        STRING,
-        INTEGER,
-        NULL,
-        TRUE,
-        FALSE,
-        FLOAT,
-        DOUBLE
-    }
-
-    public Type getLiteralType();
-
-    public String getStringValue();
-
-}
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/base/Literal.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/base/Literal.java
new file mode 100644
index 0000000..f6c779a
--- /dev/null
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/base/Literal.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2009-2010 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.base;
+
+import java.io.Serializable;
+
+public abstract class Literal implements Serializable {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -6468144574890768345L;
+
+    public enum Type {
+        STRING,
+        INTEGER,
+        NULL,
+        TRUE,
+        FALSE,
+        FLOAT,
+        DOUBLE,
+        LONG
+    }
+
+    abstract public Object getValue();
+    
+    abstract public Type getLiteralType();
+
+    public String getStringValue() {
+        return getValue().toString();
+    }    
+    
+    @Override
+    public int hashCode() {
+        return getValue().hashCode();
+    }    
+
+    public boolean equals(Object obj) {
+        if (!(obj instanceof Literal)) {
+            return false;
+        }
+        Literal literal = (Literal)obj;
+        return getValue().equals(literal.getValue());
+    } 
+    
+    @Override
+    public String toString() {
+        return getStringValue();
+    }    
+}
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/LiteralExpr.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/LiteralExpr.java
index ba94cfc..496b0e0 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/LiteralExpr.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/LiteralExpr.java
@@ -1,26 +1,26 @@
 package edu.uci.ics.asterix.aql.expression;
 
 import edu.uci.ics.asterix.aql.base.Expression;
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 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;
 
 public class LiteralExpr implements Expression {
-    private ILiteral value;
+    private Literal value;
 
     public LiteralExpr() {
     }
 
-    public LiteralExpr(ILiteral value) {
+    public LiteralExpr(Literal value) {
         this.value = value;
     }
 
-    public ILiteral getValue() {
+    public Literal getValue() {
         return value;
     }
 
-    public void setValue(ILiteral value) {
+    public void setValue(Literal value) {
         this.value = value;
     }
 
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/visitor/AQLPrintVisitor.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/visitor/AQLPrintVisitor.java
index f01991b..1c681b1 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/visitor/AQLPrintVisitor.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/expression/visitor/AQLPrintVisitor.java
@@ -6,7 +6,7 @@
 
 import edu.uci.ics.asterix.aql.base.Clause;
 import edu.uci.ics.asterix.aql.base.Expression;
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 import edu.uci.ics.asterix.aql.base.Statement;
 import edu.uci.ics.asterix.aql.expression.BeginFeedStatement;
 import edu.uci.ics.asterix.aql.expression.CallExpr;
@@ -103,9 +103,9 @@
 
     @Override
     public void visit(LiteralExpr l, Integer step) {
-        ILiteral lc = l.getValue();
-        if (lc.getLiteralType().equals(ILiteral.Type.TRUE) || lc.getLiteralType().equals(ILiteral.Type.FALSE)
-                || lc.getLiteralType().equals(ILiteral.Type.NULL)) {
+    	Literal lc = l.getValue();
+        if (lc.getLiteralType().equals(Literal.Type.TRUE) || lc.getLiteralType().equals(Literal.Type.FALSE)
+                || lc.getLiteralType().equals(Literal.Type.NULL)) {
             out.println(skip(step) + "LiteralExpr [" + l.getValue().getLiteralType() + "]");
         } else {
             out.println(skip(step) + "LiteralExpr [" + l.getValue().getLiteralType() + "] ["
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/DoubleLiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/DoubleLiteral.java
index d35f5f3..fb0c827 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/DoubleLiteral.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/DoubleLiteral.java
@@ -14,9 +14,9 @@
  */
 package edu.uci.ics.asterix.aql.literal;
 
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 
-public class DoubleLiteral implements ILiteral {
+public class DoubleLiteral extends Literal {
     /**
      * 
      */
@@ -28,10 +28,12 @@
         this.value = value;
     }
 
+    @Override    
     public Double getValue() {
         return value;
     }
 
+
     public void setValue(Double value) {
         this.value = value;
     }
@@ -40,28 +42,4 @@
     public Type getLiteralType() {
         return Type.DOUBLE;
     }
-
-    @Override
-    public String getStringValue() {
-        return value.toString();
-    }
-
-    @Override
-    public String toString() {
-        return getStringValue();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (!(obj instanceof DoubleLiteral)) {
-            return false;
-        }
-        DoubleLiteral d = (DoubleLiteral) obj;
-        return d.getValue() == value;
-    }
-
-    @Override
-    public int hashCode() {
-        return value.hashCode();
-    }
 }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/FalseLiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/FalseLiteral.java
index 17b4254..7f19b84 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/FalseLiteral.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/FalseLiteral.java
@@ -14,9 +14,9 @@
  */
 package edu.uci.ics.asterix.aql.literal;
 
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 
-public class FalseLiteral implements ILiteral {
+public class FalseLiteral extends Literal {
 
     private static final long serialVersionUID = -750814844423165149L;
 
@@ -49,4 +49,9 @@
     public int hashCode() {
         return (int) serialVersionUID;
     }
+
+    @Override
+    public Boolean getValue() {
+        return Boolean.FALSE;
+    }
 }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/FloatLiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/FloatLiteral.java
index f77ed39..b2db6a1 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/FloatLiteral.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/FloatLiteral.java
@@ -14,9 +14,9 @@
  */
 package edu.uci.ics.asterix.aql.literal;
 
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 
-public class FloatLiteral implements ILiteral {
+public class FloatLiteral extends Literal {
     /**
      * 
      */
@@ -28,10 +28,12 @@
         this.value = value;
     }
 
+    @Override
     public Float getValue() {
         return value;
     }
 
+    
     public void setValue(Float value) {
         this.value = value;
     }
@@ -40,28 +42,4 @@
     public Type getLiteralType() {
         return Type.FLOAT;
     }
-
-    @Override
-    public String getStringValue() {
-        return value.toString();
-    }
-
-    @Override
-    public String toString() {
-        return getStringValue();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (!(obj instanceof FloatLiteral)) {
-            return false;
-        }
-        FloatLiteral f = (FloatLiteral) obj;
-        return f.getValue() == value;
-    }
-
-    @Override
-    public int hashCode() {
-        return value.hashCode();
-    }
 }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/IntegerLiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/IntegerLiteral.java
index 52cf7fa..f29feb8 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/IntegerLiteral.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/IntegerLiteral.java
@@ -14,9 +14,9 @@
  */
 package edu.uci.ics.asterix.aql.literal;
 
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 
-public class IntegerLiteral implements ILiteral {
+public class IntegerLiteral extends Literal {
     /**
      * 
      */
@@ -37,32 +37,7 @@
     }
 
     @Override
-    public String toString() {
-        return getStringValue();
-    }
-
-    @Override
     public Type getLiteralType() {
         return Type.INTEGER;
     }
-
-    @Override
-    public String getStringValue() {
-        return value.toString();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (!(obj instanceof IntegerLiteral)) {
-            return false;
-        }
-        IntegerLiteral i = (IntegerLiteral) obj;
-        return value.equals(i.getValue());
-    }
-
-    @Override
-    public int hashCode() {
-        return value;
-    }
-
 }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/LongIntegerLiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/LongIntegerLiteral.java
new file mode 100644
index 0000000..7e02f04
--- /dev/null
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/LongIntegerLiteral.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2009-2010 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.literal;
+
+import edu.uci.ics.asterix.aql.base.Literal;
+
+public class LongIntegerLiteral extends Literal {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -8633520244871361967L;
+    private Long value;
+
+    public LongIntegerLiteral(Long value) {
+        super();
+        this.value = value;
+    }
+
+    @Override
+    public Long getValue() {
+        return value;
+    }
+
+    public void setValue(Long value) {
+        this.value = value;
+    }
+
+    @Override
+    public Type getLiteralType() {
+        return Type.LONG;
+    }
+}
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/NullLiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/NullLiteral.java
index b421afa..efcb9c6 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/NullLiteral.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/NullLiteral.java
@@ -14,9 +14,9 @@
  */
 package edu.uci.ics.asterix.aql.literal;
 
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 
-public class NullLiteral implements ILiteral {
+public class NullLiteral extends Literal {
 
     /**
      * 
@@ -39,11 +39,6 @@
     }
 
     @Override
-    public String toString() {
-        return getStringValue();
-    }
-
-    @Override
     public boolean equals(Object obj) {
         return obj == INSTANCE;
     }
@@ -52,4 +47,9 @@
     public int hashCode() {
         return (int) serialVersionUID;
     }
+
+    @Override
+    public Object getValue() {
+        return null;
+    }    
 }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/StringLiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/StringLiteral.java
index ad5588f..0fd586c 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/StringLiteral.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/StringLiteral.java
@@ -1,8 +1,8 @@
 package edu.uci.ics.asterix.aql.literal;
 
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 
-public class StringLiteral implements ILiteral {
+public class StringLiteral extends Literal {
 
     private static final long serialVersionUID = -6342491706277606168L;
     private String value;
@@ -29,24 +29,4 @@
     public String getStringValue() {
         return value;
     }
-
-    @Override
-    public String toString() {
-        return getStringValue();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (!(obj instanceof StringLiteral)) {
-            return false;
-        }
-        StringLiteral s = (StringLiteral) obj;
-        return value.equals(s.getValue());
-    }
-
-    @Override
-    public int hashCode() {
-        return value.hashCode();
-    }
-
 }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/TrueLiteral.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/TrueLiteral.java
index dedd52b..80d7966 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/TrueLiteral.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/literal/TrueLiteral.java
@@ -1,8 +1,8 @@
 package edu.uci.ics.asterix.aql.literal;
 
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 
-public class TrueLiteral implements ILiteral {
+public class TrueLiteral extends Literal {
     private static final long serialVersionUID = -8513245514578847512L;
 
     private TrueLiteral() {
@@ -34,4 +34,9 @@
     public int hashCode() {
         return (int) serialVersionUID;
     }
+
+    @Override
+    public Boolean getValue() {
+        return Boolean.TRUE;
+    }
 }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/AqlRewriter.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/AqlRewriter.java
index fdb56be..8f0a3ff 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/AqlRewriter.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/rewrites/AqlRewriter.java
@@ -83,7 +83,9 @@
     private String dataverseName;
 
     private enum DfsColor {
-        WHITE, GRAY, BLACK
+        WHITE,
+        GRAY,
+        BLACK
     }
 
     public AqlRewriter(Query topExpr, int varCounter, MetadataTransactionContext txnContext, String dataverseName) {
@@ -156,15 +158,15 @@
         List<AsterixFunction> functionCalls = getFunctionCalls(expression);
         for (AsterixFunction funId : functionCalls) {
             if (AsterixBuiltinFunctions.isBuiltinCompilerFunction(new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-                    funId.getFunctionName(), false))) {
+                    funId.getFunctionName()))) {
                 continue;
             }
 
-            if (AsterixBuiltinFunctions.isBuiltinCompilerFunction(new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS,
-                    funId.getFunctionName(), false))) {
+            if (AsterixBuiltinFunctions.isBuiltinCompilerFunction(new FunctionIdentifier(
+                    AlgebricksBuiltinFunctions.ALGEBRICKS_NS, funId.getFunctionName()))) {
                 continue;
             }
-            
+
             if (declaredFunctions != null && declaredFunctions.contains(funId)) {
                 continue;
             }
@@ -179,8 +181,8 @@
     }
 
     private FunctionDecl getFunctionDecl(AsterixFunction funId) throws AsterixException {
-        Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, dataverseName, funId.getFunctionName(), funId
-                .getArity());
+        Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, dataverseName, funId.getFunctionName(),
+                funId.getArity());
         if (function == null) {
             throw new AsterixException(" unknown function " + funId);
         }
diff --git a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/util/FunctionUtils.java b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/util/FunctionUtils.java
index d246a92..1a30693 100644
--- a/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/util/FunctionUtils.java
+++ b/asterix-aql/src/main/java/edu/uci/ics/asterix/aql/util/FunctionUtils.java
@@ -77,19 +77,17 @@
     public static IFunctionInfo getFunctionInfo(MetadataTransactionContext mdTxnCtx, String dataverseName,
             AsterixFunction asterixFunction) throws MetadataException {
         FunctionIdentifier fid = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-                asterixFunction.getFunctionName(), asterixFunction.getArity(), true);
+                asterixFunction.getFunctionName(), asterixFunction.getArity());
         IFunctionInfo finfo = AsterixBuiltinFunctions.getAsterixFunctionInfo(fid);
         if (fid == null) {
             fid = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS, asterixFunction.getFunctionName(),
-                    asterixFunction.getArity(), true);
+                    asterixFunction.getArity());
         }
         if (fid == null) {
-            Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, dataverseName, asterixFunction
-                    .getFunctionName(), asterixFunction.getArity());
+            Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, dataverseName,
+                    asterixFunction.getFunctionName(), asterixFunction.getArity());
             if (function != null) {
-                finfo = new AsterixFunctionInfo(dataverseName, asterixFunction, false);
-                // todo: for external functions, we shall construct another kind of function info (that extends AsterixFunctionInfo)
-                // and has additional information.
+                finfo = new AsterixFunctionInfo(dataverseName, asterixFunction);
             }
         }
         return finfo; // could be null
diff --git a/asterix-aql/src/main/javacc/AQL.jj b/asterix-aql/src/main/javacc/AQL.jj
index b59dbd3..0767c4e 100644
--- a/asterix-aql/src/main/javacc/AQL.jj
+++ b/asterix-aql/src/main/javacc/AQL.jj
@@ -20,8 +20,9 @@
 import edu.uci.ics.asterix.aql.literal.FloatLiteral;
 import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
 import edu.uci.ics.asterix.aql.literal.FalseLiteral;
-import edu.uci.ics.asterix.aql.base.ILiteral;
+import edu.uci.ics.asterix.aql.base.Literal;
 import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
+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;
@@ -1478,10 +1479,11 @@
 	{
 		if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
 		{
-			ILiteral lit = ((LiteralExpr)expr).getValue();
-			if(lit.getLiteralType() == ILiteral.Type.INTEGER) {
+			Literal lit = ((LiteralExpr)expr).getValue();
+			if(lit.getLiteralType() == Literal.Type.INTEGER || 
+			   lit.getLiteralType() == Literal.Type.LONG) {
 				idx = Integer.valueOf(lit.getStringValue());
-			}	
+			}
 			else {
 				throw new ParseException("Index should be an INTEGER");				
             }
@@ -1509,7 +1511,7 @@
   Expression expr = null;
 }
 {
-  //ILiteral | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression
+  //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression
 	(
 	  expr =Literal() 
 	   | expr = FunctionCallExpr()
@@ -1545,7 +1547,11 @@
  	 | <INTEGER_LITERAL>
     {
       t= getToken(0);
-	  lit.setValue(new IntegerLiteral(new Integer(t.image)));
+	  try {
+	      lit.setValue(new IntegerLiteral(new Integer(t.image)));
+	  } catch(NumberFormatException ex) {
+	      lit.setValue(new LongIntegerLiteral(new Long(t.image)));
+	  }
 	}
      | < FLOAT_LITERAL >
     {
@@ -1859,12 +1865,9 @@
 	extendCurrentScope();
 }
 {
-    "let" varExp = Variable()
+    "let" varExp = Variable() ":=" beExp = Expression()
     {
       getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
-	}
-     ":=" beExp = Expression()
-    {
       lc.setVarExpr(varExp);
       lc.setBeExpr(beExp);
       return lc;
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
index 36e8a4c..d676cb5 100644
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
@@ -20,6 +20,7 @@
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class AsterixAppRuntimeContext {
+    private static final int DEFAULT_BUFFER_CACHE_PAGE_SIZE = 32768;
     private final INCApplicationContext ncApplicationContext;
     
     private IndexRegistry<IIndex> indexRegistry;
@@ -52,7 +53,7 @@
     }
 
     private int getBufferCachePageSize() {
-        int pageSize = ncApplicationContext.getRootContext().getFrameSize();
+        int pageSize = DEFAULT_BUFFER_CACHE_PAGE_SIZE;
         String pageSizeStr = System.getProperty(GlobalConfig.BUFFER_CACHE_PAGE_SIZE_PROPERTY, null);
         if (pageSizeStr != null) {
             try {
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataCache.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataCache.java
index 65a6d8e..e205acf 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataCache.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/MetadataCache.java
@@ -35,267 +35,259 @@
  * simply ignored, i.e., updates are not not applied to the cache.
  */
 public class MetadataCache {
-	// Key is dataverse name.
-	protected final Map<String, Dataverse> dataverses = new HashMap<String, Dataverse>();
-	// Key is dataverse name. Key of value map is dataset name.
-	protected final Map<String, Map<String, Dataset>> datasets = new HashMap<String, Map<String, Dataset>>();
-	// Key is dataverse name. Key of value map is datatype name.
-	protected final Map<String, Map<String, Datatype>> datatypes = new HashMap<String, Map<String, Datatype>>();
-	// Key is dataverse name.
-	protected final Map<String, NodeGroup> nodeGroups = new HashMap<String, NodeGroup>();
-	// Key is function Identifier . Key of value map is function name.
-	protected final Map<FunctionIdentifier, Function> functions = new HashMap<FunctionIdentifier, Function>();
+    // Key is dataverse name.
+    protected final Map<String, Dataverse> dataverses = new HashMap<String, Dataverse>();
+    // Key is dataverse name. Key of value map is dataset name.
+    protected final Map<String, Map<String, Dataset>> datasets = new HashMap<String, Map<String, Dataset>>();
+    // Key is dataverse name. Key of value map is datatype name.
+    protected final Map<String, Map<String, Datatype>> datatypes = new HashMap<String, Map<String, Datatype>>();
+    // Key is dataverse name.
+    protected final Map<String, NodeGroup> nodeGroups = new HashMap<String, NodeGroup>();
+    // Key is function Identifier . Key of value map is function name.
+    protected final Map<FunctionIdentifier, Function> functions = new HashMap<FunctionIdentifier, Function>();
 
-	// Atomically executes all metadata operations in ctx's log.
-	public void commit(MetadataTransactionContext ctx) {
-		// Forward roll the operations written in ctx's log.
-		int logIx = 0;
-		ArrayList<MetadataLogicalOperation> opLog = ctx.getOpLog();
-		try {
-			for (logIx = 0; logIx < opLog.size(); logIx++) {
-				doOperation(opLog.get(logIx));
-			}
-		} catch (Exception e) {
-			// Undo operations.
-			try {
-				for (int i = logIx - 1; i >= 0; i--) {
-					undoOperation(opLog.get(i));
-				}
-			} catch (Exception e2) {
-				// We encountered an error in undo. This case should never
-				// happen. Our only remedy to ensure cache consistency
-				// is to clear everything.
-				clear();
-			}
-		} finally {
-			ctx.clear();
-		}
-	}
+    // Atomically executes all metadata operations in ctx's log.
+    public void commit(MetadataTransactionContext ctx) {
+        // Forward roll the operations written in ctx's log.
+        int logIx = 0;
+        ArrayList<MetadataLogicalOperation> opLog = ctx.getOpLog();
+        try {
+            for (logIx = 0; logIx < opLog.size(); logIx++) {
+                doOperation(opLog.get(logIx));
+            }
+        } catch (Exception e) {
+            // Undo operations.
+            try {
+                for (int i = logIx - 1; i >= 0; i--) {
+                    undoOperation(opLog.get(i));
+                }
+            } catch (Exception e2) {
+                // We encountered an error in undo. This case should never
+                // happen. Our only remedy to ensure cache consistency
+                // is to clear everything.
+                clear();
+            }
+        } finally {
+            ctx.clear();
+        }
+    }
 
-	public void clear() {
-		synchronized (dataverses) {
-			synchronized (nodeGroups) {
-				synchronized (datasets) {
-					synchronized (datatypes) {
-						synchronized (functions) {
-							dataverses.clear();
-							nodeGroups.clear();
-							datasets.clear();
-							datatypes.clear();
-						}
-					}
-				}
-			}
-		}
-	}
+    public void clear() {
+        synchronized (dataverses) {
+            synchronized (nodeGroups) {
+                synchronized (datasets) {
+                    synchronized (datatypes) {
+                        synchronized (functions) {
+                            dataverses.clear();
+                            nodeGroups.clear();
+                            datasets.clear();
+                            datatypes.clear();
+                        }
+                    }
+                }
+            }
+        }
+    }
 
-	public Object addDataverseIfNotExists(Dataverse dataverse) {
-		synchronized (dataverses) {
-			synchronized (datasets) {
-				synchronized (datatypes) {
-					synchronized (functions) {
-						if (!dataverses.containsKey(dataverse)) {
-							datasets.put(dataverse.getDataverseName(),
-									new HashMap<String, Dataset>());
-							datatypes.put(dataverse.getDataverseName(),
-									new HashMap<String, Datatype>());
-							return dataverses.put(dataverse.getDataverseName(),
-									dataverse);
-						}
-					}
-					return null;
-				}
-			}
-		}
-	}
+    public Object addDataverseIfNotExists(Dataverse dataverse) {
+        synchronized (dataverses) {
+            synchronized (datasets) {
+                synchronized (datatypes) {
+                    synchronized (functions) {
+                        if (!dataverses.containsKey(dataverse)) {
+                            datasets.put(dataverse.getDataverseName(), new HashMap<String, Dataset>());
+                            datatypes.put(dataverse.getDataverseName(), new HashMap<String, Datatype>());
+                            return dataverses.put(dataverse.getDataverseName(), dataverse);
+                        }
+                    }
+                    return null;
+                }
+            }
+        }
+    }
 
-	public Object addDatasetIfNotExists(Dataset dataset) {
-		synchronized (datasets) {
-			Map<String, Dataset> m = datasets.get(dataset.getDataverseName());
-			if (m == null) {
-				m = new HashMap<String, Dataset>();
-				datasets.put(dataset.getDataverseName(), m);
-			}
-			if (!m.containsKey(dataset.getDatasetName())) {
-				return m.put(dataset.getDatasetName(), dataset);
-			}
-			return null;
-		}
-	}
+    public Object addDatasetIfNotExists(Dataset dataset) {
+        synchronized (datasets) {
+            Map<String, Dataset> m = datasets.get(dataset.getDataverseName());
+            if (m == null) {
+                m = new HashMap<String, Dataset>();
+                datasets.put(dataset.getDataverseName(), m);
+            }
+            if (!m.containsKey(dataset.getDatasetName())) {
+                return m.put(dataset.getDatasetName(), dataset);
+            }
+            return null;
+        }
+    }
 
-	public Object addDatatypeIfNotExists(Datatype datatype) {
-		synchronized (datatypes) {
-			Map<String, Datatype> m = datatypes
-					.get(datatype.getDataverseName());
-			if (m == null) {
-				m = new HashMap<String, Datatype>();
-				datatypes.put(datatype.getDataverseName(), m);
-			}
-			if (!m.containsKey(datatype.getDatatypeName())) {
-				return m.put(datatype.getDatatypeName(), datatype);
-			}
-			return null;
-		}
-	}
+    public Object addDatatypeIfNotExists(Datatype datatype) {
+        synchronized (datatypes) {
+            Map<String, Datatype> m = datatypes.get(datatype.getDataverseName());
+            if (m == null) {
+                m = new HashMap<String, Datatype>();
+                datatypes.put(datatype.getDataverseName(), m);
+            }
+            if (!m.containsKey(datatype.getDatatypeName())) {
+                return m.put(datatype.getDatatypeName(), datatype);
+            }
+            return null;
+        }
+    }
 
-	public Object addNodeGroupIfNotExists(NodeGroup nodeGroup) {
-		synchronized (nodeGroups) {
-			if (!nodeGroups.containsKey(nodeGroup.getNodeGroupName())) {
-				return nodeGroups.put(nodeGroup.getNodeGroupName(), nodeGroup);
-			}
-			return null;
-		}
-	}
+    public Object addNodeGroupIfNotExists(NodeGroup nodeGroup) {
+        synchronized (nodeGroups) {
+            if (!nodeGroups.containsKey(nodeGroup.getNodeGroupName())) {
+                return nodeGroups.put(nodeGroup.getNodeGroupName(), nodeGroup);
+            }
+            return null;
+        }
+    }
 
-	public Object dropDataverse(Dataverse dataverse) {
-		synchronized (dataverses) {
-			synchronized (datasets) {
-				synchronized (datatypes) {
-					synchronized (functions) {
-						datasets.remove(dataverse.getDataverseName());
-						datatypes.remove(dataverse.getDataverseName());
-						return dataverses.remove(dataverse.getDataverseName());
-					}
-				}
-			}
-		}
-	}
+    public Object dropDataverse(Dataverse dataverse) {
+        synchronized (dataverses) {
+            synchronized (datasets) {
+                synchronized (datatypes) {
+                    synchronized (functions) {
+                        datasets.remove(dataverse.getDataverseName());
+                        datatypes.remove(dataverse.getDataverseName());
+                        return dataverses.remove(dataverse.getDataverseName());
+                    }
+                }
+            }
+        }
+    }
 
-	public Object dropDataset(Dataset dataset) {
-		synchronized (datasets) {
-			Map<String, Dataset> m = datasets.get(dataset.getDataverseName());
-			if (m == null) {
-				return null;
-			}
-			return m.remove(dataset.getDatasetName());
-		}
-	}
+    public Object dropDataset(Dataset dataset) {
+        synchronized (datasets) {
+            Map<String, Dataset> m = datasets.get(dataset.getDataverseName());
+            if (m == null) {
+                return null;
+            }
+            return m.remove(dataset.getDatasetName());
+        }
+    }
 
-	public Object dropDatatype(Datatype datatype) {
-		synchronized (datatypes) {
-			Map<String, Datatype> m = datatypes
-					.get(datatype.getDataverseName());
-			if (m == null) {
-				return null;
-			}
-			return m.remove(datatype.getDatatypeName());
-		}
-	}
+    public Object dropDatatype(Datatype datatype) {
+        synchronized (datatypes) {
+            Map<String, Datatype> m = datatypes.get(datatype.getDataverseName());
+            if (m == null) {
+                return null;
+            }
+            return m.remove(datatype.getDatatypeName());
+        }
+    }
 
-	public Object dropNodeGroup(NodeGroup nodeGroup) {
-		synchronized (nodeGroups) {
-			return nodeGroups.remove(nodeGroup.getNodeGroupName());
-		}
-	}
+    public Object dropNodeGroup(NodeGroup nodeGroup) {
+        synchronized (nodeGroups) {
+            return nodeGroups.remove(nodeGroup.getNodeGroupName());
+        }
+    }
 
-	public Dataverse getDataverse(String dataverseName) {
-		synchronized (dataverses) {
-			return dataverses.get(dataverseName);
-		}
-	}
+    public Dataverse getDataverse(String dataverseName) {
+        synchronized (dataverses) {
+            return dataverses.get(dataverseName);
+        }
+    }
 
-	public Dataset getDataset(String dataverseName, String datasetName) {
-		synchronized (datasets) {
-			Map<String, Dataset> m = datasets.get(dataverseName);
-			if (m == null) {
-				return null;
-			}
-			return m.get(datasetName);
-		}
-	}
+    public Dataset getDataset(String dataverseName, String datasetName) {
+        synchronized (datasets) {
+            Map<String, Dataset> m = datasets.get(dataverseName);
+            if (m == null) {
+                return null;
+            }
+            return m.get(datasetName);
+        }
+    }
 
-	public Datatype getDatatype(String dataverseName, String datatypeName) {
-		synchronized (datatypes) {
-			Map<String, Datatype> m = datatypes.get(dataverseName);
-			if (m == null) {
-				return null;
-			}
-			return m.get(datatypeName);
-		}
-	}
+    public Datatype getDatatype(String dataverseName, String datatypeName) {
+        synchronized (datatypes) {
+            Map<String, Datatype> m = datatypes.get(dataverseName);
+            if (m == null) {
+                return null;
+            }
+            return m.get(datatypeName);
+        }
+    }
 
-	public NodeGroup getNodeGroup(String nodeGroupName) {
-		synchronized (nodeGroups) {
-			return nodeGroups.get(nodeGroupName);
-		}
-	}
+    public NodeGroup getNodeGroup(String nodeGroupName) {
+        synchronized (nodeGroups) {
+            return nodeGroups.get(nodeGroupName);
+        }
+    }
 
-	public Function getFunction(String dataverse, String functionName, int arity) {
-		synchronized (functions) {
-			return functions.get(new FunctionIdentifier(dataverse,
-					functionName, arity, false));
-		}
-	}
+    public Function getFunction(String dataverse, String functionName, int arity) {
+        synchronized (functions) {
+            return functions.get(new FunctionIdentifier(dataverse, functionName, arity));
+        }
+    }
 
-	public List<Dataset> getDataverseDatasets(String dataverseName) {
-		List<Dataset> retDatasets = new ArrayList<Dataset>();
-		synchronized (datasets) {
-			Map<String, Dataset> m = datasets.get(dataverseName);
-			if (m == null) {
-				return retDatasets;
-			}
-			for (Map.Entry<String, Dataset> entry : m.entrySet()) {
-				retDatasets.add(entry.getValue());
-			}
-			return retDatasets;
-		}
-	}
+    public List<Dataset> getDataverseDatasets(String dataverseName) {
+        List<Dataset> retDatasets = new ArrayList<Dataset>();
+        synchronized (datasets) {
+            Map<String, Dataset> m = datasets.get(dataverseName);
+            if (m == null) {
+                return retDatasets;
+            }
+            for (Map.Entry<String, Dataset> entry : m.entrySet()) {
+                retDatasets.add(entry.getValue());
+            }
+            return retDatasets;
+        }
+    }
 
-	/**
-	 * Represents a logical operation against the metadata.
-	 */
-	protected class MetadataLogicalOperation {
-		// Entity to be added/dropped.
-		public final IMetadataEntity entity;
-		// True for add, false for drop.
-		public final boolean isAdd;
+    /**
+     * Represents a logical operation against the metadata.
+     */
+    protected class MetadataLogicalOperation {
+        // Entity to be added/dropped.
+        public final IMetadataEntity entity;
+        // True for add, false for drop.
+        public final boolean isAdd;
 
-		public MetadataLogicalOperation(IMetadataEntity entity, boolean isAdd) {
-			this.entity = entity;
-			this.isAdd = isAdd;
-		}
-	};
+        public MetadataLogicalOperation(IMetadataEntity entity, boolean isAdd) {
+            this.entity = entity;
+            this.isAdd = isAdd;
+        }
+    };
 
-	protected void doOperation(MetadataLogicalOperation op) {
-		if (op.isAdd) {
-			op.entity.addToCache(this);
-		} else {
-			op.entity.dropFromCache(this);
-		}
-	}
+    protected void doOperation(MetadataLogicalOperation op) {
+        if (op.isAdd) {
+            op.entity.addToCache(this);
+        } else {
+            op.entity.dropFromCache(this);
+        }
+    }
 
-	protected void undoOperation(MetadataLogicalOperation op) {
-		if (!op.isAdd) {
-			op.entity.addToCache(this);
-		} else {
-			op.entity.dropFromCache(this);
-		}
-	}
+    protected void undoOperation(MetadataLogicalOperation op) {
+        if (!op.isAdd) {
+            op.entity.addToCache(this);
+        } else {
+            op.entity.dropFromCache(this);
+        }
+    }
 
-	public Object addFunctionIfNotExists(Function function) {
-		synchronized (functions) {
-			FunctionIdentifier fId = new FunctionIdentifier(
-					function.getDataverseName(), function.getFunctionName(),
-					function.getFunctionArity(), false);
+    public Object addFunctionIfNotExists(Function function) {
+        synchronized (functions) {
+            FunctionIdentifier fId = new FunctionIdentifier(function.getDataverseName(), function.getFunctionName(),
+                    function.getFunctionArity());
 
-			Function fun = functions.get(fId);
-			if (fun == null) {
-				return functions.put(fId, function);
-			}
-			return null;
-		}
-	}
+            Function fun = functions.get(fId);
+            if (fun == null) {
+                return functions.put(fId, function);
+            }
+            return null;
+        }
+    }
 
-	public Object dropFunction(Function function) {
-		synchronized (functions) {
-			FunctionIdentifier fId = new FunctionIdentifier(
-					function.getDataverseName(), function.getFunctionName(),
-					function.getFunctionArity(), false);
-			Function fun = functions.get(fId);
-			if (fun == null) {
-				return null;
-			}
-			return functions.remove(fId);
-		}
-	}
+    public Object dropFunction(Function function) {
+        synchronized (functions) {
+            FunctionIdentifier fId = new FunctionIdentifier(function.getDataverseName(), function.getFunctionName(),
+                    function.getFunctionArity());
+            Function fun = functions.get(fId);
+            if (fun == null) {
+                return null;
+            }
+            return functions.remove(fId);
+        }
+    }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
index ee99c0d..417948f 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
@@ -22,6 +22,8 @@
 import edu.uci.ics.asterix.om.typecomputer.impl.ARectangleTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.AStringTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.BinaryBooleanOrNullFunctionTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.BinaryStringBoolOrNullTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.BinaryStringStringOrNullTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.CastRecordResultTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.ClosedRecordConstructorResultType;
 import edu.uci.ics.asterix.om.typecomputer.impl.FieldAccessByIndexResultType;
@@ -31,6 +33,8 @@
 import edu.uci.ics.asterix.om.typecomputer.impl.NonTaggedGetItemResultType;
 import edu.uci.ics.asterix.om.typecomputer.impl.NonTaggedLocalAvgTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.NonTaggedNumericAddSubMulDivTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.NonTaggedNumericRoundHalfToEven2TypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.NonTaggedNumericUnaryFunctionTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.NonTaggedSumTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.NonTaggedSwitchCaseComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.NonTaggedUnaryMinusTypeComputer;
@@ -56,8 +60,15 @@
 import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListOfAInt32TypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListOfAStringTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListOfAnyTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.QuadStringStringOrNullTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.ScalarVersionOfAggregateResultType;
+import edu.uci.ics.asterix.om.typecomputer.impl.Substring2TypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.SubstringTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.TripleStringBoolOrNullTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.TripleStringStringOrNullTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.UnaryBooleanOrNullFunctionTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.UnaryStringInt32OrNullTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.UnaryStringOrNullTypeComputer;
 import edu.uci.ics.asterix.om.typecomputer.impl.UnorderedListConstructorResultType;
 import edu.uci.ics.asterix.om.types.AOrderedListType;
 import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -97,253 +108,285 @@
     private final static Map<IFunctionInfo, IFunctionInfo> scalarToAggregateFunctionMap = new HashMap<IFunctionInfo, IFunctionInfo>();
     private static final Map<IFunctionInfo, SpatialFilterKind> spatialFilterFunctions = new HashMap<IFunctionInfo, SpatialFilterKind>();
 
-    public final static FunctionIdentifier TYPE_OF = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "type-of", 1,
-            true);
+    public final static FunctionIdentifier TYPE_OF = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "type-of", 1);
     public final static FunctionIdentifier GET_HANDLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "get-handle", 2, true);
+            "get-handle", 2);
     public final static FunctionIdentifier GET_DATA = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-data",
-            2, true);
+            2);
     public final static FunctionIdentifier EMBED_TYPE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "embed-type", 1, true);
+            "embed-type", 1);
 
     public final static FunctionIdentifier GET_ITEM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-item",
-            2, true);
+            2);
     public final static FunctionIdentifier ANY_COLLECTION_MEMBER = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "any-collection-member", 1, true);
-    public final static FunctionIdentifier LISTIFY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "listify", 1,
-            true);
+            "any-collection-member", 1);
+    public final static FunctionIdentifier LISTIFY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "listify", 1);
     // public final static FunctionIdentifier BAGIFY = new
     // FunctionIdentifier(ASTERIX_NS, "bagify", 1, true);
-    public final static FunctionIdentifier LEN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "len", 1, true);
+    public final static FunctionIdentifier LEN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "len", 1);
 
     public final static FunctionIdentifier CONCAT_NON_NULL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "concat-non-null", FunctionIdentifier.VARARGS, true);
+            "concat-non-null", FunctionIdentifier.VARARGS);
     public final static FunctionIdentifier EMPTY_STREAM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "empty-stream", 0, true);
+            "empty-stream", 0);
     public final static FunctionIdentifier NON_EMPTY_STREAM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "non-empty-stream", 0, true);
+            "non-empty-stream", 0);
     public final static FunctionIdentifier ORDERED_LIST_CONSTRUCTOR = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "ordered-list-constructor", FunctionIdentifier.VARARGS, true);
+            FunctionConstants.ASTERIX_NS, "ordered-list-constructor", FunctionIdentifier.VARARGS);
     public final static FunctionIdentifier UNORDERED_LIST_CONSTRUCTOR = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "unordered-list-constructor", FunctionIdentifier.VARARGS, true);
+            FunctionConstants.ASTERIX_NS, "unordered-list-constructor", FunctionIdentifier.VARARGS);
 
     // records
     public final static FunctionIdentifier CLOSED_RECORD_CONSTRUCTOR = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "closed-record-constructor", FunctionIdentifier.VARARGS, true);
+            FunctionConstants.ASTERIX_NS, "closed-record-constructor", FunctionIdentifier.VARARGS);
     public final static FunctionIdentifier OPEN_RECORD_CONSTRUCTOR = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "open-record-constructor", FunctionIdentifier.VARARGS, true);
+            FunctionConstants.ASTERIX_NS, "open-record-constructor", FunctionIdentifier.VARARGS);
     public final static FunctionIdentifier RECORD_TYPE_CONSTRUCTOR = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "record-type-constructor", FunctionIdentifier.VARARGS, true);
+            FunctionConstants.ASTERIX_NS, "record-type-constructor", FunctionIdentifier.VARARGS);
     public final static FunctionIdentifier FIELD_ACCESS_BY_INDEX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "field-access-by-index", 2, true);
+            "field-access-by-index", 2);
     public final static FunctionIdentifier FIELD_ACCESS_BY_NAME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "field-access-by-name", 2, true);
+            "field-access-by-name", 2);
 
     public final static FunctionIdentifier NUMERIC_UNARY_MINUS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-unary-minus", 1, true);
+            "numeric-unary-minus", 1);
 
     public final static FunctionIdentifier NUMERIC_SUBTRACT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-subtract", 2, true);
+            "numeric-subtract", 2);
     public final static FunctionIdentifier NUMERIC_MULTIPLY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-multiply", 2, true);
+            "numeric-multiply", 2);
     public final static FunctionIdentifier NUMERIC_DIVIDE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-divide", 2, true);
+            "numeric-divide", 2);
     public final static FunctionIdentifier NUMERIC_MOD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-mod", 2, true);
+            "numeric-mod", 2);
     public final static FunctionIdentifier NUMERIC_IDIV = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-idiv", 2, true);
-    public final static FunctionIdentifier CARET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "caret", 2,
-            true);
+            "numeric-idiv", 2);
+    public final static FunctionIdentifier CARET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "caret", 2);
 
-    public final static FunctionIdentifier DATASET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "dataset", 1,
-            true);
+	public final static FunctionIdentifier NUMERIC_ABS = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "numeric-abs", 1);
+	public final static FunctionIdentifier NUMERIC_CEILING = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "numeric-ceiling", 1);
+	public final static FunctionIdentifier NUMERIC_FLOOR = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "numeric-floor", 1);
+	public final static FunctionIdentifier NUMERIC_ROUND = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "numeric-round", 1);
+	public final static FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "numeric-round-half-to-even", 1);
+	public final static FunctionIdentifier NUMERIC_ROUND_HALF_TO_EVEN2 = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "numeric-round-half-to-even2", 2);
+	// String funcitons
+	public final static FunctionIdentifier STRING_EQUAL = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "string-equal", 2);
+	public final static FunctionIdentifier STRING_START_WITH = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "start-with", 2);
+	public final static FunctionIdentifier STRING_END_WITH = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "end-with", 2);
+	public final static FunctionIdentifier STRING_MATCHES = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "matches", 2);
+	public final static FunctionIdentifier STRING_MATCHES_WITH_FLAG = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "matches2", 3);
+	public final static FunctionIdentifier STRING_LOWERCASE = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "lowercase", 1);
+	public final static FunctionIdentifier STRING_REPLACE = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "replace", 3);
+	public final static FunctionIdentifier STRING_REPLACE_WITH_FLAG = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "replace2", 4);
+	public final static FunctionIdentifier STRING_LENGTH = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "string-length", 1);
+	public final static FunctionIdentifier SUBSTRING2 = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "substring2", 2);
+	public final static FunctionIdentifier SUBSTRING_BEFORE = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "substring-before", 2);
+	public final static FunctionIdentifier SUBSTRING_AFTER = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "substring-after", 2);
+	public final static FunctionIdentifier STRING_TO_CODEPOINT = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "string-to-codepoint", 1);
+	public final static FunctionIdentifier CODEPOINT_TO_STRING = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "codepoint-to-string", 1);
+	public final static FunctionIdentifier STRING_CONCAT = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "string-concat", 1);
+	public final static FunctionIdentifier STRING_JOIN = new FunctionIdentifier(
+			FunctionConstants.ASTERIX_NS, "string-join", 2);
+
+    public final static FunctionIdentifier DATASET = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "dataset", 1);
     public final static FunctionIdentifier FEED_INGEST = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "feed-ingest", 1, true);
+            "feed-ingest", 1);
 
     public final static FunctionIdentifier INDEX_SEARCH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "index-search", FunctionIdentifier.VARARGS, true);
+            "index-search", FunctionIdentifier.VARARGS);
 
     public final static FunctionIdentifier MAKE_FIELD_INDEX_HANDLE = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "make-field-index-handle", 2, true);
+            FunctionConstants.ASTERIX_NS, "make-field-index-handle", 2);
     public final static FunctionIdentifier MAKE_FIELD_NAME_HANDLE = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "make-field-name-handle", 1, true);
+            FunctionConstants.ASTERIX_NS, "make-field-name-handle", 1);
 
     public final static FunctionIdentifier SUBSTRING = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "substring", 3, true);
-    public final static FunctionIdentifier LIKE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "like", 2, true);
+            "substring", 3);
+    public final static FunctionIdentifier LIKE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "like", 2);
     public final static FunctionIdentifier CONTAINS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "contains",
-            2, true);
+            2);
     private final static FunctionIdentifier STARTS_WITH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "starts-with", 2, true);
+            "starts-with", 2);
     private final static FunctionIdentifier ENDS_WITH = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "ends-with", 2, true);
+            "ends-with", 2);
 
-    public final static FunctionIdentifier AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-avg", 1,
-            true);
-    public final static FunctionIdentifier COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-count", 1,
-            true);
-    public final static FunctionIdentifier SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sum", 1,
-            true);
-    public final static FunctionIdentifier MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-max", 1,
-            true);
-    public final static FunctionIdentifier MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-min", 1,
-            true);
+    public final static FunctionIdentifier AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-avg", 1);
+    public final static FunctionIdentifier COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-count", 1);
+    public final static FunctionIdentifier SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sum", 1);
+    public final static FunctionIdentifier MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-max", 1);
+    public final static FunctionIdentifier MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-min", 1);
     public final static FunctionIdentifier GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "agg-global-avg", 1, true);
+            "agg-global-avg", 1);
     public final static FunctionIdentifier LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "agg-local-avg", 1, true);
+            "agg-local-avg", 1);
 
-    public final static FunctionIdentifier SCALAR_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "avg", 1,
-            true);
+    public final static FunctionIdentifier SCALAR_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "avg", 1);
     public final static FunctionIdentifier SCALAR_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "count",
-            1, true);
-    public final static FunctionIdentifier SCALAR_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sum", 1,
-            true);
-    public final static FunctionIdentifier SCALAR_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "max", 1,
-            true);
-    public final static FunctionIdentifier SCALAR_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "min", 1,
-            true);
+            1);
+    public final static FunctionIdentifier SCALAR_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sum", 1);
+    public final static FunctionIdentifier SCALAR_MAX = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "max", 1);
+    public final static FunctionIdentifier SCALAR_MIN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "min", 1);
     public final static FunctionIdentifier SCALAR_GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "global-avg", 1, true);
+            "global-avg", 1);
     public final static FunctionIdentifier SCALAR_LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "local-avg", 1, true);
+            "local-avg", 1);
 
     // serializable aggregate functions
     public final static FunctionIdentifier SERIAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "avg-serial", 1, true);
+            "avg-serial", 1);
     public final static FunctionIdentifier SERIAL_COUNT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "count-serial", 1, true);
+            "count-serial", 1);
     public final static FunctionIdentifier SERIAL_SUM = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "sum-serial", 1, true);
+            "sum-serial", 1);
     public final static FunctionIdentifier SERIAL_GLOBAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "global-avg-serial", 1, true);
+            "global-avg-serial", 1);
     public final static FunctionIdentifier SERIAL_LOCAL_AVG = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "local-avg-serial", 1, true);
+            "local-avg-serial", 1);
 
-    public final static FunctionIdentifier YEAR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "year", 1, true);
+    public final static FunctionIdentifier YEAR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "year", 1);
 
     public final static FunctionIdentifier SCAN_COLLECTION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "scan-collection", 1, true);
+            "scan-collection", 1);
     public final static FunctionIdentifier SUBSET_COLLECTION = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "subset-collection", 3, true);
+            "subset-collection", 3);
 
-    public final static FunctionIdentifier RANGE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "range", 2,
-            true);
+    public final static FunctionIdentifier RANGE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "range", 2);
 
     // fuzzy functions:
     public final static FunctionIdentifier FUZZY_EQ = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "fuzzy-eq",
-            2, true);
+            2);
 
     public final static FunctionIdentifier PREFIX_LEN_JACCARD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "prefix-len-jaccard", 2, true);
+            "prefix-len-jaccard", 2);
 
     public final static FunctionIdentifier SIMILARITY_JACCARD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "similarity-jaccard", 2, true);
+            "similarity-jaccard", 2);
     public final static FunctionIdentifier SIMILARITY_JACCARD_CHECK = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "similarity-jaccard-check", 3, true);
+            FunctionConstants.ASTERIX_NS, "similarity-jaccard-check", 3);
     public final static FunctionIdentifier SIMILARITY_JACCARD_SORTED = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "similarity-jaccard-sorted", 2, true);
+            FunctionConstants.ASTERIX_NS, "similarity-jaccard-sorted", 2);
     public final static FunctionIdentifier SIMILARITY_JACCARD_SORTED_CHECK = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "similarity-jaccard-sorted-check", 3, true);
+            FunctionConstants.ASTERIX_NS, "similarity-jaccard-sorted-check", 3);
     public final static FunctionIdentifier SIMILARITY_JACCARD_PREFIX = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "similarity-jaccard-prefix", 6, true);
+            FunctionConstants.ASTERIX_NS, "similarity-jaccard-prefix", 6);
     public final static FunctionIdentifier SIMILARITY_JACCARD_PREFIX_CHECK = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "similarity-jaccard-prefix-check", 6, true);
+            FunctionConstants.ASTERIX_NS, "similarity-jaccard-prefix-check", 6);
 
     public final static FunctionIdentifier EDIT_DISTANCE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "edit-distance", 2, true);
+            "edit-distance", 2);
     public final static FunctionIdentifier EDIT_DISTANCE_CHECK = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "edit-distance-check", 3, true);
+            "edit-distance-check", 3);
     public final static FunctionIdentifier EDIT_DISTANCE_LIST_IS_FILTERABLE = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "edit-distance-list-is-filterable", 2, true);
+            FunctionConstants.ASTERIX_NS, "edit-distance-list-is-filterable", 2);
     public final static FunctionIdentifier EDIT_DISTANCE_STRING_IS_FILTERABLE = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "edit-distance-string-is-filterable", 4, true);
+            FunctionConstants.ASTERIX_NS, "edit-distance-string-is-filterable", 4);
 
     // tokenizers:
     public final static FunctionIdentifier WORD_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "word-tokens", 1, true);
+            "word-tokens", 1);
     public final static FunctionIdentifier HASHED_WORD_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "hashed-word-tokens", 1, true);
+            "hashed-word-tokens", 1);
     public final static FunctionIdentifier COUNTHASHED_WORD_TOKENS = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "counthashed-word-tokens", 1, true);
+            FunctionConstants.ASTERIX_NS, "counthashed-word-tokens", 1);
     public final static FunctionIdentifier GRAM_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "gram-tokens", 3, true);
+            "gram-tokens", 3);
     public final static FunctionIdentifier HASHED_GRAM_TOKENS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "hashed-gram-tokens", 3, true);
+            "hashed-gram-tokens", 3);
     public final static FunctionIdentifier COUNTHASHED_GRAM_TOKENS = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "counthashed-gram-tokens", 3, true);
+            FunctionConstants.ASTERIX_NS, "counthashed-gram-tokens", 3);
 
-    public final static FunctionIdentifier TID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tid", 0, true);
+    public final static FunctionIdentifier TID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tid", 0);
 
     // constructors:
     public final static FunctionIdentifier BOOLEAN_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "boolean", 1, false);
+            "boolean", 1);
     public final static FunctionIdentifier NULL_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "null", 1, false);
+            "null", 1);
     public final static FunctionIdentifier STRING_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "string", 1, false);
+            "string", 1);
     public final static FunctionIdentifier INT8_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "int8", 1, false);
+            "int8", 1);
     public final static FunctionIdentifier INT16_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "int16", 1, false);
+            "int16", 1);
     public final static FunctionIdentifier INT32_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "int32", 1, false);
+            "int32", 1);
     public final static FunctionIdentifier INT64_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "int64", 1, false);
+            "int64", 1);
     public final static FunctionIdentifier FLOAT_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "float", 1, false);
+            "float", 1);
     public final static FunctionIdentifier DOUBLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "double", 1, false);
+            "double", 1);
     public final static FunctionIdentifier POINT_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "point", 1, false);
+            "point", 1);
     public final static FunctionIdentifier POINT3D_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "point3d", 1, false);
+            "point3d", 1);
     public final static FunctionIdentifier LINE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "line", 1, false);
+            "line", 1);
     public final static FunctionIdentifier CIRCLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "circle", 1, false);
+            "circle", 1);
     public final static FunctionIdentifier RECTANGLE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "rectangle", 1, false);
+            "rectangle", 1);
     public final static FunctionIdentifier POLYGON_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "polygon", 1, false);
+            "polygon", 1);
     public final static FunctionIdentifier TIME_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "time", 1, false);
+            "time", 1);
     public final static FunctionIdentifier DATE_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "date", 1, false);
+            "date", 1);
     public final static FunctionIdentifier DATETIME_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "datetime", 1, false);
+            "datetime", 1);
     public final static FunctionIdentifier DURATION_CONSTRUCTOR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "duration", 1, false);
+            "duration", 1);
 
     // spatial
     public final static FunctionIdentifier CREATE_POINT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "create-point", 2, true);
+            "create-point", 2);
     public final static FunctionIdentifier CREATE_LINE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "create-line", 2, true);
+            "create-line", 2);
     public final static FunctionIdentifier CREATE_POLYGON = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "create-polygon", FunctionIdentifier.VARARGS, true);
+            "create-polygon", FunctionIdentifier.VARARGS);
     public final static FunctionIdentifier CREATE_CIRCLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "create-circle", 2, true);
+            "create-circle", 2);
     public final static FunctionIdentifier CREATE_RECTANGLE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "create-rectangle", 2, true);
+            "create-rectangle", 2);
     public final static FunctionIdentifier SPATIAL_INTERSECT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "spatial-intersect", 2, true);
+            "spatial-intersect", 2);
     public final static FunctionIdentifier SPATIAL_AREA = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "spatial-area", 1, true);
+            "spatial-area", 1);
     public final static FunctionIdentifier SPATIAL_DISTANCE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "spatial-distance", 2, true);
+            "spatial-distance", 2);
     public final static FunctionIdentifier CREATE_MBR = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "create-mbr", 3, true);
+            "create-mbr", 3);
     public final static FunctionIdentifier SPATIAL_CELL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "spatial-cell", 4, true);
+            "spatial-cell", 4);
     public final static FunctionIdentifier SWITCH_CASE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "switch-case", FunctionIdentifier.VARARGS, true);
-    public final static FunctionIdentifier REG_EXP = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "reg-exp", 2,
-            true);
+            "switch-case", FunctionIdentifier.VARARGS);
+    public final static FunctionIdentifier REG_EXP = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "reg-exp", 2);
+
     public final static FunctionIdentifier INJECT_FAILURE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "inject-failure", 2, true);
+            "inject-failure", 2);
     public final static FunctionIdentifier CAST_RECORD = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "cast-record", 1, true);
+            "cast-record", 1);
 
     public static final FunctionIdentifier EQ = AlgebricksBuiltinFunctions.EQ;
     public static final FunctionIdentifier LE = AlgebricksBuiltinFunctions.LE;
@@ -360,10 +403,10 @@
     public static IFunctionInfo getAsterixFunctionInfo(FunctionIdentifier fid) {
         IFunctionInfo finfo = asterixFunctionIdToInfo.get(fid);
         if (finfo == null) {
-            finfo = new AsterixFunctionInfo(fid, fid.isBuiltin());
-            if (fid.isBuiltin()) {
-                asterixFunctionIdToInfo.put(fid, finfo);
-            }
+            finfo = new AsterixFunctionInfo(fid);
+            //   if (fid.isBuiltin()) {
+            asterixFunctionIdToInfo.put(fid, finfo);
+            //  }
         }
         return finfo;
     }
@@ -480,6 +523,32 @@
         add(NUMERIC_DIVIDE, NonTaggedNumericAddSubMulDivTypeComputer.INSTANCE);
         add(NUMERIC_MOD, NonTaggedNumericAddSubMulDivTypeComputer.INSTANCE);
         add(NUMERIC_IDIV, AInt32TypeComputer.INSTANCE);
+        
+        // Xiaoyu Ma Add for new functions
+        add(NUMERIC_ABS, NonTaggedNumericUnaryFunctionTypeComputer.INSTANCE);
+        add(NUMERIC_CEILING, NonTaggedNumericUnaryFunctionTypeComputer.INSTANCE);
+        add(NUMERIC_FLOOR, NonTaggedNumericUnaryFunctionTypeComputer.INSTANCE);
+        add(NUMERIC_ROUND, NonTaggedNumericUnaryFunctionTypeComputer.INSTANCE);
+        add(NUMERIC_ROUND_HALF_TO_EVEN, NonTaggedNumericUnaryFunctionTypeComputer.INSTANCE);
+        add(NUMERIC_ROUND_HALF_TO_EVEN2, NonTaggedNumericRoundHalfToEven2TypeComputer.INSTANCE);
+        
+        add(STRING_TO_CODEPOINT, OrderedListOfAInt32TypeComputer.INSTANCE);
+        add(CODEPOINT_TO_STRING, AStringTypeComputer.INSTANCE);
+        add(STRING_CONCAT, AStringTypeComputer.INSTANCE);
+        add(SUBSTRING2, Substring2TypeComputer.INSTANCE);
+        add(STRING_LENGTH, UnaryStringInt32OrNullTypeComputer.INSTANCE);
+        add(STRING_LOWERCASE, UnaryStringOrNullTypeComputer.INSTANCE);
+        add(STRING_START_WITH, BinaryStringBoolOrNullTypeComputer.INSTANCE);
+        add(STRING_END_WITH, BinaryStringBoolOrNullTypeComputer.INSTANCE);
+        add(STRING_MATCHES, BinaryStringBoolOrNullTypeComputer.INSTANCE);
+        add(STRING_MATCHES_WITH_FLAG, TripleStringBoolOrNullTypeComputer.INSTANCE);
+        add(STRING_REPLACE, TripleStringStringOrNullTypeComputer.INSTANCE);
+        add(STRING_REPLACE_WITH_FLAG, QuadStringStringOrNullTypeComputer.INSTANCE);
+        add(SUBSTRING_BEFORE, BinaryStringStringOrNullTypeComputer.INSTANCE);
+        add(SUBSTRING_AFTER, BinaryStringStringOrNullTypeComputer.INSTANCE);
+        add(STRING_EQUAL, BinaryStringBoolOrNullTypeComputer.INSTANCE);
+        add(STRING_JOIN, AStringTypeComputer.INSTANCE);
+        
         add(OPEN_RECORD_CONSTRUCTOR, OpenRecordConstructorResultType.INSTANCE);
         add(ORDERED_LIST_CONSTRUCTOR, OrderedListConstructorResultType.INSTANCE);
         add(POINT_CONSTRUCTOR, OptionalAPointTypeComputer.INSTANCE);
@@ -551,7 +620,7 @@
                 }
             }
         });
-        add(SUBSTRING, AStringTypeComputer.INSTANCE);
+        add(SUBSTRING, SubstringTypeComputer.INSTANCE);
         add(SUM, NonTaggedSumTypeComputer.INSTANCE);
         add(SWITCH_CASE, NonTaggedSwitchCaseComputer.INSTANCE);
         add(REG_EXP, ABooleanTypeComputer.INSTANCE);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixFunctionInfo.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixFunctionInfo.java
index 8580d33..61e47c0 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixFunctionInfo.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixFunctionInfo.java
@@ -20,15 +20,13 @@
 public class AsterixFunctionInfo implements IFunctionInfo {
 
     private final FunctionIdentifier functionIdentifier;
-    
 
-    public AsterixFunctionInfo(String namespace, AsterixFunction asterixFunction, boolean isBuiltin) {
+    public AsterixFunctionInfo(String namespace, AsterixFunction asterixFunction) {
         this.functionIdentifier = new FunctionIdentifier(namespace, asterixFunction.getFunctionName(),
-                asterixFunction.getArity(), isBuiltin);
+                asterixFunction.getArity());
     }
 
-    public AsterixFunctionInfo(FunctionIdentifier functionIdentifier,
-            boolean isBuiltin) {
+    public AsterixFunctionInfo(FunctionIdentifier functionIdentifier) {
         this.functionIdentifier = functionIdentifier;
     }
 
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractBinaryStringTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractBinaryStringTypeComputer.java
new file mode 100644
index 0000000..0615de4
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractBinaryStringTypeComputer.java
@@ -0,0 +1,47 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeHelper;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+abstract public class AbstractBinaryStringTypeComputer implements IResultTypeComputer {
+    
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if(fce.getArguments().size() < 2)
+            throw new AlgebricksException("Wrong Argument Number.");        
+        ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
+        ILogicalExpression arg1 = fce.getArguments().get(1).getValue();
+        IAType t0, t1;
+        try {
+            t0 = (IAType) env.getType(arg0);
+            t1 = (IAType) env.getType(arg1);
+        } catch (AlgebricksException e) {
+            throw new AlgebricksException(e);
+        }
+        if ((t0.getTypeTag() != ATypeTag.NULL && t0.getTypeTag() != ATypeTag.STRING) ||
+            (t1.getTypeTag() != ATypeTag.NULL && t1.getTypeTag() != ATypeTag.STRING)) {
+            throw new AlgebricksException("Expects String Type.");
+        }      
+
+        return getResultType(t0, t1);
+    }    
+    
+    
+    public abstract IAType getResultType(IAType t0, IAType t1);
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractQuadStringTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractQuadStringTypeComputer.java
new file mode 100644
index 0000000..0baf221
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractQuadStringTypeComputer.java
@@ -0,0 +1,50 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public abstract class AbstractQuadStringTypeComputer implements IResultTypeComputer {
+    
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if(fce.getArguments().size() < 4)
+            throw new AlgebricksException("Wrong Argument Number.");        
+        ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
+        ILogicalExpression arg1 = fce.getArguments().get(1).getValue();
+        ILogicalExpression arg2 = fce.getArguments().get(2).getValue();  
+        ILogicalExpression arg3 = fce.getArguments().get(3).getValue();                
+        IAType t0, t1, t2, t3;
+        try {
+            t0 = (IAType) env.getType(arg0);
+            t1 = (IAType) env.getType(arg1);
+            t2 = (IAType) env.getType(arg2);    
+            t3 = (IAType) env.getType(arg3);              
+        } catch (AlgebricksException e) {
+            throw new AlgebricksException(e);
+        }
+        if ((t0.getTypeTag() != ATypeTag.NULL && t0.getTypeTag() != ATypeTag.STRING) || 
+            (t1.getTypeTag() != ATypeTag.NULL && t1.getTypeTag() != ATypeTag.STRING) ||
+            (t2.getTypeTag() != ATypeTag.NULL && t2.getTypeTag() != ATypeTag.STRING) ||
+            (t3.getTypeTag() != ATypeTag.NULL && t3.getTypeTag() != ATypeTag.STRING)) {
+            throw new NotImplementedException("Expects String Type.");
+        }
+
+        return getResultType(t0, t1, t2, t3);
+    }    
+    
+    
+    public abstract IAType getResultType(IAType t0, IAType t1, IAType t2, IAType t3);    
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractTripleStringTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractTripleStringTypeComputer.java
new file mode 100644
index 0000000..429f1f0
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/AbstractTripleStringTypeComputer.java
@@ -0,0 +1,46 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public abstract class AbstractTripleStringTypeComputer implements IResultTypeComputer {
+    
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if(fce.getArguments().size() < 3)
+            throw new AlgebricksException("Wrong Argument Number.");            
+        ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
+        ILogicalExpression arg1 = fce.getArguments().get(1).getValue();
+        ILogicalExpression arg2 = fce.getArguments().get(2).getValue();        
+        IAType t0, t1, t2;
+        try {
+            t0 = (IAType) env.getType(arg0);
+            t1 = (IAType) env.getType(arg1);
+            t2 = (IAType) env.getType(arg2);            
+        } catch (AlgebricksException e) {
+            throw new AlgebricksException(e);
+        }
+        if ((t0.getTypeTag() != ATypeTag.NULL   && t0.getTypeTag() != ATypeTag.STRING) || (t1.getTypeTag() != ATypeTag.NULL &&
+            t1.getTypeTag() != ATypeTag.STRING) || (t2.getTypeTag() != ATypeTag.NULL && t2.getTypeTag() != ATypeTag.STRING)) {
+            throw new AlgebricksException("Expects String Type.");
+        }
+
+        return getResultType(t0, t1, t2);
+    }    
+    
+    
+    public abstract IAType getResultType(IAType t0, IAType t1, IAType t2);
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/BinaryStringBoolOrNullTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/BinaryStringBoolOrNullTypeComputer.java
new file mode 100644
index 0000000..fa2a4a5
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/BinaryStringBoolOrNullTypeComputer.java
@@ -0,0 +1,23 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeHelper;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public class BinaryStringBoolOrNullTypeComputer extends AbstractBinaryStringTypeComputer {
+    public static final BinaryStringBoolOrNullTypeComputer INSTANCE = new BinaryStringBoolOrNullTypeComputer();
+    private BinaryStringBoolOrNullTypeComputer() {}    
+    
+    @Override
+    public IAType getResultType(IAType t0, IAType t1) {
+        if (TypeHelper.canBeNull(t0) || TypeHelper.canBeNull(t1)) {
+            return AUnionType.createNullableType(BuiltinType.ABOOLEAN);
+        }        	
+        return BuiltinType.ABOOLEAN;
+    }    
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/BinaryStringStringOrNullTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/BinaryStringStringOrNullTypeComputer.java
new file mode 100644
index 0000000..0b24ff9
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/BinaryStringStringOrNullTypeComputer.java
@@ -0,0 +1,25 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeHelper;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public class BinaryStringStringOrNullTypeComputer extends AbstractBinaryStringTypeComputer {
+    
+    public static final BinaryStringStringOrNullTypeComputer INSTANCE = new BinaryStringStringOrNullTypeComputer();
+    private BinaryStringStringOrNullTypeComputer() {}
+
+    @Override
+    public IAType getResultType(IAType t0, IAType t1) {
+        if (TypeHelper.canBeNull(t0) || TypeHelper.canBeNull(t1)) {
+            return AUnionType.createNullableType(BuiltinType.ASTRING);
+        }      	
+        return BuiltinType.ASTRING;
+    }
+    
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedNumericRoundHalfToEven2TypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedNumericRoundHalfToEven2TypeComputer.java
new file mode 100644
index 0000000..da90a06
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedNumericRoundHalfToEven2TypeComputer.java
@@ -0,0 +1,98 @@
+/*
+ * Numeric round half to even
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class NonTaggedNumericRoundHalfToEven2TypeComputer implements IResultTypeComputer {
+
+    public static final NonTaggedNumericRoundHalfToEven2TypeComputer INSTANCE =
+            new NonTaggedNumericRoundHalfToEven2TypeComputer();
+
+    private NonTaggedNumericRoundHalfToEven2TypeComputer() {
+    }
+
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if(fce.getArguments().size() < 2)
+        	throw new AlgebricksException("Argument number invalid.");
+        
+        ILogicalExpression arg1 = fce.getArguments().get(0).getValue();
+        ILogicalExpression arg2 = fce.getArguments().get(1).getValue();
+        
+        IAType t1 = (IAType) env.getType(arg1);
+        IAType t2 = (IAType) env.getType(arg2);
+        
+        List<IAType> unionList = new ArrayList<IAType>();
+        unionList.add(BuiltinType.ANULL);        
+
+        ATypeTag tag1, tag2;
+        if (t1.getTypeTag() == ATypeTag.UNION && NonTaggedFormatUtil.isOptionalField((AUnionType) t1))
+            tag1 = ((AUnionType) t1).getUnionList().get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST)
+                    .getTypeTag();
+        else
+            tag1 = t1.getTypeTag();
+
+        if (t2.getTypeTag() == ATypeTag.UNION && NonTaggedFormatUtil.isOptionalField((AUnionType) t2))
+            tag2 = ((AUnionType) t2).getUnionList().get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST)
+                    .getTypeTag();
+        else
+            tag2 = t2.getTypeTag();
+        
+        switch(tag2) {
+	        case INT8:
+	        case INT16:
+	        case INT32:
+	        case INT64:
+	            break;
+	        default:
+	            throw new AlgebricksException("Argument $precision cannot be type " + t2.getTypeName());
+        }        
+        
+        switch (tag1) {
+            case INT8:
+                unionList.add(BuiltinType.AINT8);
+                break;                
+            case INT16:
+                unionList.add(BuiltinType.AINT16);
+                break;                 
+            case INT32:
+                unionList.add(BuiltinType.AINT32);
+                break;                 
+            case INT64:
+                unionList.add(BuiltinType.AINT64);
+                break;                 
+            case FLOAT:
+                unionList.add(BuiltinType.AFLOAT);
+                break;                 
+            case DOUBLE:
+                unionList.add(BuiltinType.ADOUBLE);
+                break;
+            case NULL:
+                return BuiltinType.ANULL;
+            default: {
+                throw new NotImplementedException("Arithmetic operations are not implemented for " + t1.getTypeName());
+            }
+        }
+
+        return new AUnionType(unionList, "NumericFuncionsResult");
+    }
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedNumericUnaryFunctionTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedNumericUnaryFunctionTypeComputer.java
new file mode 100644
index 0000000..454104b
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedNumericUnaryFunctionTypeComputer.java
@@ -0,0 +1,79 @@
+/*
+ * Numeric Unary Functions like abs
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class NonTaggedNumericUnaryFunctionTypeComputer implements IResultTypeComputer {
+
+    private static final String errMsg = "Arithmetic operations are not implemented for ";
+    public static final NonTaggedNumericUnaryFunctionTypeComputer INSTANCE =
+            new NonTaggedNumericUnaryFunctionTypeComputer();
+
+    private NonTaggedNumericUnaryFunctionTypeComputer() {
+    }
+
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if(fce.getArguments().isEmpty())
+            throw new AlgebricksException("Wrong Argument Number.");
+        
+        ILogicalExpression arg1 = fce.getArguments().get(0).getValue();
+
+        IAType t = (IAType) env.getType(arg1);
+        ATypeTag tag = t.getTypeTag();
+
+        if (tag == ATypeTag.UNION
+                && NonTaggedFormatUtil.isOptionalField((AUnionType) env.getType(arg1))) {
+            return (IAType) env.getType(arg1);
+        }
+        
+        List<IAType> unionList = new ArrayList<IAType>();
+        unionList.add(BuiltinType.ANULL);
+        switch (tag) {
+            case INT8:
+                unionList.add(BuiltinType.AINT8);
+                break;                
+            case INT16:
+                unionList.add(BuiltinType.AINT16);
+                break;                 
+            case INT32:
+                unionList.add(BuiltinType.AINT32);
+                break;                 
+            case INT64:
+                unionList.add(BuiltinType.AINT64);
+                break;                 
+            case FLOAT:
+                unionList.add(BuiltinType.AFLOAT);
+                break;                 
+            case DOUBLE:
+                unionList.add(BuiltinType.ADOUBLE);
+                break;
+            case NULL:
+                return BuiltinType.ANULL;
+            default: {
+                throw new NotImplementedException(errMsg + t.getTypeName());
+            }
+        }
+
+        return new AUnionType(unionList, "NumericUnaryFuncionsResult");
+    }
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/QuadStringStringOrNullTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/QuadStringStringOrNullTypeComputer.java
new file mode 100644
index 0000000..876df7a
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/QuadStringStringOrNullTypeComputer.java
@@ -0,0 +1,25 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeHelper;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public class QuadStringStringOrNullTypeComputer  extends AbstractQuadStringTypeComputer {
+    public static final QuadStringStringOrNullTypeComputer INSTANCE = new QuadStringStringOrNullTypeComputer();
+    private QuadStringStringOrNullTypeComputer() {}
+
+    @Override
+    public IAType getResultType(IAType t0, IAType t1, IAType t2, IAType t3) {
+        if (TypeHelper.canBeNull(t0) || TypeHelper.canBeNull(t1) || 
+        	TypeHelper.canBeNull(t2) || TypeHelper.canBeNull(t3)) {
+            return AUnionType.createNullableType(BuiltinType.ASTRING);
+        }      	
+        return BuiltinType.ASTRING;
+    }
+    
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/Substring2TypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/Substring2TypeComputer.java
new file mode 100644
index 0000000..c5d224c
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/Substring2TypeComputer.java
@@ -0,0 +1,63 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+
+
+public class Substring2TypeComputer implements IResultTypeComputer {
+    public static final Substring2TypeComputer INSTANCE = new Substring2TypeComputer();
+    
+    
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if(fce.getArguments().size() < 2)
+            throw new AlgebricksException("Wrong Argument Number.");            
+        ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
+        ILogicalExpression arg1 = fce.getArguments().get(1).getValue();       
+        IAType t0, t1;
+        try {
+            t0 = (IAType) env.getType(arg0);
+            t1 = (IAType) env.getType(arg1);                  
+        } catch (AlgebricksException e) {
+            throw new AlgebricksException(e);
+        }
+        
+        ATypeTag tag0, tag1;
+        if (t0.getTypeTag() == ATypeTag.UNION && NonTaggedFormatUtil.isOptionalField((AUnionType) t0))
+            tag0 = ((AUnionType) t0).getUnionList().get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST)
+                    .getTypeTag();
+        else
+            tag0 = t0.getTypeTag();
+        
+        if (t1.getTypeTag() == ATypeTag.UNION && NonTaggedFormatUtil.isOptionalField((AUnionType) t1))
+            tag1 = ((AUnionType) t1).getUnionList().get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST)
+                    .getTypeTag();
+        else
+            tag1 = t1.getTypeTag();        
+        
+        if(tag0 != ATypeTag.NULL && tag0 != ATypeTag.STRING) {
+            throw new AlgebricksException("First argument should be String Type.");
+        }
+        
+        if(tag1 != ATypeTag.NULL && 
+           tag1 != ATypeTag.INT8 && 
+           tag1 != ATypeTag.INT16 && 
+           tag1 != ATypeTag.INT32 && 
+           tag1 != ATypeTag.INT64) {
+            throw new AlgebricksException("Second argument should be integer Type.");
+        }
+
+        return BuiltinType.ASTRING;
+    }   
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/SubstringTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/SubstringTypeComputer.java
new file mode 100644
index 0000000..b016de8
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/SubstringTypeComputer.java
@@ -0,0 +1,71 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+
+public class SubstringTypeComputer implements IResultTypeComputer {
+    public static final SubstringTypeComputer INSTANCE = new SubstringTypeComputer();
+
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if (fce.getArguments().size() < 3)
+            throw new AlgebricksException("Wrong Argument Number.");
+        ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
+        ILogicalExpression arg1 = fce.getArguments().get(1).getValue();
+        ILogicalExpression arg2 = fce.getArguments().get(2).getValue();
+        IAType t0, t1, t2;
+        try {
+            t0 = (IAType) env.getType(arg0);
+            t1 = (IAType) env.getType(arg1);
+            t2 = (IAType) env.getType(arg2);
+        } catch (AlgebricksException e) {
+            throw new AlgebricksException(e);
+        }
+
+        ATypeTag tag0, tag1, tag2;
+        if (t0.getTypeTag() == ATypeTag.UNION && NonTaggedFormatUtil.isOptionalField((AUnionType) t0))
+            tag0 = ((AUnionType) t0).getUnionList().get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST)
+                    .getTypeTag();
+        else
+            tag0 = t0.getTypeTag();
+
+        if (t1.getTypeTag() == ATypeTag.UNION && NonTaggedFormatUtil.isOptionalField((AUnionType) t1))
+            tag1 = ((AUnionType) t1).getUnionList().get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST)
+                    .getTypeTag();
+        else
+            tag1 = t1.getTypeTag();
+
+        if (t2.getTypeTag() == ATypeTag.UNION && NonTaggedFormatUtil.isOptionalField((AUnionType) t2))
+            tag2 = ((AUnionType) t2).getUnionList().get(NonTaggedFormatUtil.OPTIONAL_TYPE_INDEX_IN_UNION_LIST)
+                    .getTypeTag();
+        else
+            tag2 = t2.getTypeTag();
+
+        if (tag0 != ATypeTag.NULL && tag0 != ATypeTag.STRING) {
+            throw new AlgebricksException("First argument should be String Type.");
+        }
+
+        if (tag1 != ATypeTag.NULL && tag1 != ATypeTag.INT8 && tag1 != ATypeTag.INT16 && tag1 != ATypeTag.INT32
+                && tag1 != ATypeTag.INT64) {
+            throw new AlgebricksException("Second argument should be integer Type.");
+        }
+
+        if (tag2 != ATypeTag.NULL && tag2 != ATypeTag.INT8 && tag2 != ATypeTag.INT16 && tag2 != ATypeTag.INT32
+                && tag2 != ATypeTag.INT64) {
+            throw new AlgebricksException("Third argument should be integer Type.");
+        }
+
+        return BuiltinType.ASTRING;
+    }
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/TripleStringBoolOrNullTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/TripleStringBoolOrNullTypeComputer.java
new file mode 100644
index 0000000..0bac1df
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/TripleStringBoolOrNullTypeComputer.java
@@ -0,0 +1,23 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeHelper;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public class TripleStringBoolOrNullTypeComputer  extends AbstractTripleStringTypeComputer {
+    public static final TripleStringBoolOrNullTypeComputer INSTANCE = new TripleStringBoolOrNullTypeComputer();
+    private TripleStringBoolOrNullTypeComputer() {}    
+    @Override
+    public IAType getResultType(IAType t0, IAType t1, IAType t2) {
+        if (TypeHelper.canBeNull(t0) || TypeHelper.canBeNull(t1) || TypeHelper.canBeNull(t2)) {
+            return AUnionType.createNullableType(BuiltinType.ABOOLEAN);
+        }    	
+        return BuiltinType.ABOOLEAN;
+    }
+    
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/TripleStringStringOrNullTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/TripleStringStringOrNullTypeComputer.java
new file mode 100644
index 0000000..10154b0
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/TripleStringStringOrNullTypeComputer.java
@@ -0,0 +1,23 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeHelper;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public class TripleStringStringOrNullTypeComputer  extends AbstractTripleStringTypeComputer {
+    public static final TripleStringStringOrNullTypeComputer INSTANCE = new TripleStringStringOrNullTypeComputer();
+    private TripleStringStringOrNullTypeComputer() {}
+
+    @Override
+    public IAType getResultType(IAType t0, IAType t1, IAType t2) {
+        if (TypeHelper.canBeNull(t0) || TypeHelper.canBeNull(t1) || TypeHelper.canBeNull(t2)) {
+            return AUnionType.createNullableType(BuiltinType.ASTRING);
+        }      	
+        return BuiltinType.ASTRING;
+    } 
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/UnaryStringInt32OrNullTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/UnaryStringInt32OrNullTypeComputer.java
new file mode 100644
index 0000000..bcd45a7
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/UnaryStringInt32OrNullTypeComputer.java
@@ -0,0 +1,59 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeHelper;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public class UnaryStringInt32OrNullTypeComputer implements IResultTypeComputer  {   
+    
+    public static final UnaryStringInt32OrNullTypeComputer INSTANCE = new UnaryStringInt32OrNullTypeComputer();
+    private UnaryStringInt32OrNullTypeComputer() {}
+    
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if(fce.getArguments().isEmpty())
+            throw new AlgebricksException("Wrong Argument Number.");        
+        ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
+        IAType t0;
+        try {
+            t0 = (IAType) env.getType(arg0);
+        } catch (AlgebricksException e) {
+            throw new AlgebricksException(e);
+        }
+        if (t0.getTypeTag() != ATypeTag.NULL &&
+            t0.getTypeTag() != ATypeTag.STRING ) {
+            throw new NotImplementedException("Expects String Type.");
+        }     
+        
+        List<IAType> unionList = new ArrayList<IAType>();
+        unionList.add(BuiltinType.ANULL);
+        if(t0.getTypeTag() == ATypeTag.NULL) {
+            return BuiltinType.ANULL;
+        }
+        
+        if(t0.getTypeTag() == ATypeTag.STRING) {
+            unionList.add(BuiltinType.AINT32);
+        }        
+        
+        return new AUnionType(unionList, "String-length-Result");
+    }      
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/UnaryStringOrNullTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/UnaryStringOrNullTypeComputer.java
new file mode 100644
index 0000000..d26a43f
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/UnaryStringOrNullTypeComputer.java
@@ -0,0 +1,52 @@
+package edu.uci.ics.asterix.om.typecomputer.impl;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.asterix.om.types.TypeHelper;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public class UnaryStringOrNullTypeComputer implements IResultTypeComputer  {   
+    
+    public static final UnaryStringOrNullTypeComputer INSTANCE = new UnaryStringOrNullTypeComputer();
+    private UnaryStringOrNullTypeComputer() {}
+    
+    @Override
+    public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+            IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+        AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
+        if(fce.getArguments().isEmpty())
+            throw new AlgebricksException("Wrong Argument Number.");        
+        ILogicalExpression arg0 = fce.getArguments().get(0).getValue();
+        IAType t0;
+        try {
+            t0 = (IAType) env.getType(arg0);
+        } catch (AlgebricksException e) {
+            throw new AlgebricksException(e);
+        }
+        
+        if (TypeHelper.canBeNull(t0)) {
+            return AUnionType.createNullableType(BuiltinType.ASTRING);
+        }            
+        
+        if (t0.getTypeTag() == ATypeTag.NULL)
+        	return BuiltinType.ANULL;
+        
+        if(t0.getTypeTag() == ATypeTag.STRING) 
+        	return BuiltinType.ASTRING;
+        
+        throw new AlgebricksException("Expects String Type.");        
+    }      
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
index 0e2f825..1cf6ba7 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
@@ -17,8 +17,8 @@
     private String[] fieldNames;
     private IAType[] fieldTypes;
     private boolean isOpen;
-    private transient final List<IRecordTypeAnnotation> annotations = new ArrayList<IRecordTypeAnnotation>();
-    private transient final Map<String, Integer> typeMap = new HashMap<String, Integer>();
+    private final List<IRecordTypeAnnotation> annotations = new ArrayList<IRecordTypeAnnotation>();
+    private final Map<String, Integer> typeMap = new HashMap<String, Integer>();
 
     public ARecordType(String typeName, String[] fieldNames, IAType[] fieldTypes, boolean isOpen) {
         super(typeName);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/collections/ListifyAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/collections/ListifyAggregateDescriptor.java
index 05aa2ea..8ddcb3f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/collections/ListifyAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/collections/ListifyAggregateDescriptor.java
@@ -13,8 +13,7 @@
 public class ListifyAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "listify", 1,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "listify", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new ListifyAggregateDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableAvgAggregateDescriptor.java
index c8cfbbe..cfbfa4e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableAvgAggregateDescriptor.java
@@ -35,8 +35,7 @@
 public class SerializableAvgAggregateDescriptor extends AbstractSerializableAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "avg-serial", 1,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "avg-serial", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SerializableAvgAggregateDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableCountAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableCountAggregateDescriptor.java
index b030d11..98e86d2 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableCountAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableCountAggregateDescriptor.java
@@ -26,7 +26,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "count-serial",
-            1, true);
+            1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SerializableCountAggregateDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableGlobalAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableGlobalAvgAggregateDescriptor.java
index d281750..e4c4931 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableGlobalAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableGlobalAvgAggregateDescriptor.java
@@ -43,7 +43,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "global-avg-serial", 1, true);
+            "global-avg-serial", 1);
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     private final static byte SER_RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableLocalAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableLocalAvgAggregateDescriptor.java
index c04dcf0..f5c9538 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableLocalAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableLocalAvgAggregateDescriptor.java
@@ -47,7 +47,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "local-avg-serial", 1, true);
+            "local-avg-serial", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SerializableLocalAvgAggregateDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableSumAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableSumAggregateDescriptor.java
index cbc5358..e689ab4 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableSumAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableSumAggregateDescriptor.java
@@ -39,8 +39,7 @@
 public class SerializableSumAggregateDescriptor extends AbstractSerializableAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sum-serial", 1,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "sum-serial", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SerializableSumAggregateDescriptor();
@@ -106,8 +105,8 @@
                         inputVal.reset();
                         eval.evaluate(tuple);
                         if (inputVal.getLength() > 0) {
-                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                                    .deserialize(inputVal.getByteArray()[0]);
+                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal
+                                    .getByteArray()[0]);
                             switch (typeTag) {
                                 case INT8: {
                                     metInt8s = true;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AvgAggregateDescriptor.java
index 078e32d..ecdd194 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AvgAggregateDescriptor.java
@@ -47,8 +47,7 @@
 public class AvgAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-avg", 1,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-avg", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new AvgAggregateDescriptor();
@@ -119,8 +118,8 @@
                         eval.evaluate(tuple);
                         if (inputVal.getLength() > 0) {
                             ++count;
-                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                                    .deserialize(inputVal.getByteArray()[0]);
+                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal
+                                    .getByteArray()[0]);
                             switch (typeTag) {
                                 case INT8: {
                                     byte val = AInt8SerializerDeserializer.getByte(inputVal.getByteArray(), 1);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/CountAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/CountAggregateDescriptor.java
index f0f7602..040e2d0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/CountAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/CountAggregateDescriptor.java
@@ -26,8 +26,7 @@
 public class CountAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-count", 1,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-count", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CountAggregateDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/GlobalAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/GlobalAvgAggregateDescriptor.java
index 172cd62..e86b2bc 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/GlobalAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/GlobalAvgAggregateDescriptor.java
@@ -44,7 +44,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-global-avg",
-            1, true);
+            1);
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     private final static byte SER_RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/LocalAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/LocalAvgAggregateDescriptor.java
index f58a084..fa05d4b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/LocalAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/LocalAvgAggregateDescriptor.java
@@ -48,7 +48,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-local-avg",
-            1, true);
+            1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new LocalAvgAggregateDescriptor();
@@ -120,8 +120,8 @@
                         eval.evaluate(tuple);
                         if (inputVal.getLength() > 0) {
                             ++count;
-                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                                    .deserialize(inputVal.getByteArray()[0]);
+                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal
+                                    .getByteArray()[0]);
                             switch (typeTag) {
                                 case INT8: {
                                     byte val = AInt8SerializerDeserializer.getByte(inputVal.getByteArray(), 1);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/MaxAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/MaxAggregateDescriptor.java
index 2fcca4c..e409910 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/MaxAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/MaxAggregateDescriptor.java
@@ -38,8 +38,7 @@
 public class MaxAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-max", 1,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-max", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new MaxAggregateDescriptor();
@@ -105,8 +104,8 @@
                         inputVal.reset();
                         eval.evaluate(tuple);
                         if (inputVal.getLength() > 0) {
-                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                                    .deserialize(inputVal.getByteArray()[0]);
+                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal
+                                    .getByteArray()[0]);
                             switch (typeTag) {
                                 case INT8: {
                                     metInt8s = true;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/MinAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/MinAggregateDescriptor.java
index 8abf8b5..af54c14 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/MinAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/MinAggregateDescriptor.java
@@ -38,8 +38,7 @@
 public class MinAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-min", 1,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-min", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new MinAggregateDescriptor();
@@ -105,8 +104,8 @@
                         inputVal.reset();
                         eval.evaluate(tuple);
                         if (inputVal.getLength() > 0) {
-                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                                    .deserialize(inputVal.getByteArray()[0]);
+                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal
+                                    .getByteArray()[0]);
                             switch (typeTag) {
                                 case INT8: {
                                     metInt8s = true;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/SumAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/SumAggregateDescriptor.java
index 197878b..5e45432 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/SumAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/SumAggregateDescriptor.java
@@ -40,8 +40,7 @@
 public class SumAggregateDescriptor extends AbstractAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sum", 1,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "agg-sum", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SumAggregateDescriptor();
@@ -97,8 +96,8 @@
                         inputVal.reset();
                         eval.evaluate(tuple);
                         if (inputVal.getLength() > 0) {
-                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
-                                    .deserialize(inputVal.getByteArray()[0]);
+                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(inputVal
+                                    .getByteArray()[0]);
                             switch (typeTag) {
                                 case INT8: {
                                     metInt8s = true;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/stream/NonEmptyStreamAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/stream/NonEmptyStreamAggregateDescriptor.java
index a48a99f..9d235e5 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/stream/NonEmptyStreamAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/stream/NonEmptyStreamAggregateDescriptor.java
@@ -24,7 +24,7 @@
     private static final long serialVersionUID = 1L;
 
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "non-empty-stream", 0, true);
+            "non-empty-stream", 0);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new NonEmptyStreamAggregateDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
index 1617dc0..12a1b9a 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ABooleanConstructorDescriptor.java
@@ -26,8 +26,7 @@
 public class ABooleanConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "boolean", 1,
-            false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "boolean", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
index dd4f9ef..2eb9c20 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ACircleConstructorDescriptor.java
@@ -26,7 +26,7 @@
 public class ACircleConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "circle", 1, true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "circle", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
index cfbddf5..25b2f84 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
@@ -25,7 +25,7 @@
 public class ADateConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "date", 1, false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "date", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
index 56c9dcf..c37d646 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
@@ -25,8 +25,7 @@
 public class ADateTimeConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "datetime", 1,
-            false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "datetime", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java
index eea5865..f0aed55 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADoubleConstructorDescriptor.java
@@ -27,8 +27,7 @@
 public class ADoubleConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "double", 1,
-            false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "double", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
index feb2fd7..c2215ff 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
@@ -25,8 +25,7 @@
 public class ADurationConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "duration", 1,
-            false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "duration", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java
index 852b6d4..8737d7b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AFloatConstructorDescriptor.java
@@ -27,7 +27,7 @@
 public class AFloatConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "float", 1, false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "float", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java
index 46e6987..b282476 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt16ConstructorDescriptor.java
@@ -25,7 +25,7 @@
 public class AInt16ConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "int16", 1, false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "int16", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java
index a8befc7..3368f41 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt32ConstructorDescriptor.java
@@ -25,7 +25,7 @@
 public class AInt32ConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "int32", 1, false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "int32", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java
index a3b635d..11242f6 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt64ConstructorDescriptor.java
@@ -25,7 +25,7 @@
 public class AInt64ConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "int64", 1, false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "int64", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java
index 0e6e94d..4bacb74 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AInt8ConstructorDescriptor.java
@@ -25,7 +25,7 @@
 public class AInt8ConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "int8", 1, false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "int8", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java
index c64f745..cb90362 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ALineConstructorDescriptor.java
@@ -26,7 +26,7 @@
 public class ALineConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "line", 1, true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "line", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java
index ff76339..e9e5353 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ANullConstructorDescriptor.java
@@ -25,7 +25,7 @@
 public class ANullConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "null", 1, false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "null", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
@@ -48,7 +48,7 @@
                     private String errorMessage = "This can not be an instance of null";
                     private final byte[] NULL = { 0, 4, 'n', 'u', 'l', 'l' };
                     IBinaryComparator utf8BinaryComparator = AqlBinaryComparatorFactoryProvider.UTF8STRING_POINTABLE_INSTANCE
-                    .createBinaryComparator();
+                            .createBinaryComparator();
                     @SuppressWarnings("unchecked")
                     private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
                             .getSerializerDeserializer(BuiltinType.ANULL);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APoint3DConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APoint3DConstructorDescriptor.java
index 0434a5f..9b6e851 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APoint3DConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APoint3DConstructorDescriptor.java
@@ -25,8 +25,7 @@
 public class APoint3DConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "point3d", 1,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "point3d", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APointConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APointConstructorDescriptor.java
index 840f141..f79a403 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APointConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APointConstructorDescriptor.java
@@ -25,7 +25,7 @@
 public class APointConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "point", 1, true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "point", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APolygonConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APolygonConstructorDescriptor.java
index 705ae78..8ad7fa9 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APolygonConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/APolygonConstructorDescriptor.java
@@ -24,8 +24,7 @@
 public class APolygonConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "polygon", 1,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "polygon", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_POLYGON_TYPE_TAG = ATypeTag.POLYGON.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ARectangleConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ARectangleConstructorDescriptor.java
index 5f5b3b3..e8a39ca 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ARectangleConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ARectangleConstructorDescriptor.java
@@ -26,8 +26,7 @@
 public class ARectangleConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "rectangle", 1,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "rectangle", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
index abe1743..d443a5e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AStringConstructorDescriptor.java
@@ -23,8 +23,7 @@
 public class AStringConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "string", 1,
-            false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "string", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
index c262d9f..8a7ac44 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
@@ -25,7 +25,7 @@
 public class ATimeConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "time", 1, false);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "time", 1);
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
new file mode 100644
index 0000000..c9834ac
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractBinaryStringBoolEval.java
@@ -0,0 +1,109 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ABoolean;
+import edu.uci.ics.asterix.om.base.AString;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import java.io.DataOutput;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public abstract class AbstractBinaryStringBoolEval implements ICopyEvaluator {
+
+    private DataOutput dout;
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
+    private ICopyEvaluator evalLeft;
+    private ICopyEvaluator evalRight;
+    @SuppressWarnings({ "rawtypes" })
+    private ISerializerDeserializer boolSerde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.ABOOLEAN);
+
+    public AbstractBinaryStringBoolEval(DataOutput dout, ICopyEvaluatorFactory evalLeftFactory,
+            ICopyEvaluatorFactory evalRightFactory) throws AlgebricksException {
+        this.dout = dout;
+        this.evalLeft = evalLeftFactory.createEvaluator(array0);
+        this.evalRight = evalRightFactory.createEvaluator(array1);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        array0.reset();
+        evalLeft.evaluate(tuple);
+        array1.reset();
+        evalRight.evaluate(tuple);
+
+        try {
+            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG && array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                try {
+                    boolSerde.serialize(ABoolean.TRUE, dout);
+                } catch (HyracksDataException ex) {
+                    Logger.getLogger(AbstractBinaryStringBoolEval.class.getName()).log(Level.SEVERE, null, ex);
+                }
+                return;
+            } else if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG || array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                boolSerde.serialize(ABoolean.FALSE, dout);
+                return;
+            }
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
+
+        byte[] b1 = array0.getByteArray();
+        byte[] b2 = array1.getByteArray();
+
+        int lLen = array0.getLength();
+        int rLen = array1.getLength();
+
+        int lStart = array0.getStartOffset();
+        int rStart = array1.getStartOffset();
+        ABoolean res = compute(b1, lLen, lStart, b2, rLen, rStart, array0, array1) ? ABoolean.TRUE : ABoolean.FALSE;
+        try {
+            boolSerde.serialize(res, dout);
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
+    }
+
+    protected abstract boolean compute(byte[] lBytes, int lLen, int lStart, byte[] rBytes, int rLen, int rStart,
+            ArrayBackedValueStorage array0, ArrayBackedValueStorage array1) throws AlgebricksException;
+
+    protected String toRegex(AString pattern) {
+        StringBuilder sb = new StringBuilder();
+        String str = pattern.getStringValue();
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            if (c == '\\' && (i < str.length() - 1) && (str.charAt(i + 1) == '_' || str.charAt(i + 1) == '%')) {
+                sb.append(str.charAt(i + 1));
+                ++i;
+            } else if (c == '%') {
+                sb.append(".*");
+            } else if (c == '_') {
+                sb.append(".");
+            } else {
+                if (Arrays.binarySearch(reservedRegexChars, c) >= 0) {
+                    sb.append('\\');
+                }
+                sb.append(c);
+            }
+        }
+        return sb.toString();
+    }
+
+    private final static char[] reservedRegexChars = new char[] { '\\', '(', ')', '[', ']', '{', '}', '.', '^', '$',
+            '*', '|' };
+    static {
+        Arrays.sort(reservedRegexChars);
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
new file mode 100644
index 0000000..96a2876
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractNumericArithmeticEval.java
@@ -0,0 +1,222 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+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.AMutableInt16;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt8;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+@SuppressWarnings("serial")
+public abstract class AbstractNumericArithmeticEval extends AbstractScalarFunctionDynamicDescriptor {
+
+    
+    abstract protected long evaluateInteger(long lhs, long rhs) throws HyracksDataException;
+    abstract protected double evaluateDouble(double lhs, double rhs) throws HyracksDataException;
+    
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+
+                return new ICopyEvaluator() {
+                    private DataOutput out = output.getDataOutput();
+                    // one temp. buffer re-used by both children
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator evalLeft = args[0].createEvaluator(argOut);
+                    private ICopyEvaluator evalRight = args[1].createEvaluator(argOut);
+                    private double[] operandsFloating = new double[args.length];
+                    private long[]   operandsInteger  = new long[args.length];
+                    private int      resultType;
+                    static protected final int typeInt8 = 1;
+                    static protected final int typeInt16 = 2;
+                    static protected final int typeInt32 = 3;
+                    static protected final int typeInt64 = 4;
+                    static protected final int typeFloat = 5;
+                    static protected final int typeDouble = 6;
+                    
+                    
+                    protected AMutableFloat aFloat = new AMutableFloat(0);
+                    protected AMutableDouble aDouble = new AMutableDouble(0);
+                    protected AMutableInt64 aInt64 = new AMutableInt64(0);
+                    protected AMutableInt32 aInt32 = new AMutableInt32(0);
+                    protected AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+                    protected AMutableInt8 aInt8 = new AMutableInt8((byte) 0);                    
+                    private ATypeTag typeTag;
+                    @SuppressWarnings("rawtypes")
+                    private ISerializerDeserializer serde;
+
+                    @SuppressWarnings("unchecked")
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+
+                        try {
+                            resultType = 0;
+                            int currentType = 0;
+                            for (int i = 0; i < args.length; i++) {
+                                argOut.reset();
+                                if (i == 0)
+                                    evalLeft.evaluate(tuple);
+                                else
+                                    evalRight.evaluate(tuple);
+                                typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]);
+                                switch (typeTag) {
+                                    case INT8: {   
+                                        currentType = typeInt8;
+                                        operandsInteger[i] = AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                        operandsFloating[i] = AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case INT16: {
+                                        currentType = typeInt16;
+                                        operandsInteger[i] = AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                        operandsFloating[i] = AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case INT32: {
+                                        currentType = typeInt32;
+                                        operandsInteger[i] = AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                        operandsFloating[i] = AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case INT64: {
+                                        currentType = typeInt64;
+                                        operandsInteger[i] = AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                        operandsFloating[i] = AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case FLOAT: {
+                                        currentType = typeFloat;
+                                        operandsFloating[i] = AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case DOUBLE: {
+                                        currentType = typeDouble;
+                                        operandsFloating[i] = ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case NULL: {
+                                        serde = AqlSerializerDeserializerProvider.INSTANCE
+                                                .getSerializerDeserializer(BuiltinType.ANULL);
+                                        serde.serialize(ANull.NULL, out);
+                                        return;
+                                    }
+                                    default: {
+                                        throw new NotImplementedException(i == 0 ? "Left"
+                                                : "Right"
+                                                        + " Operand of Division can not be "
+                                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
+                                                                .getByteArray()[0]));
+                                    }
+                                }
+                                
+                                if(resultType < currentType) {
+                                    resultType = currentType;
+                                }
+                            }
+                            
+                            long lres = 0;
+                            double dres = 0;
+                            switch(resultType) {
+                                case typeInt8:
+                                    serde = AqlSerializerDeserializerProvider.INSTANCE
+                                    .getSerializerDeserializer(BuiltinType.AINT8);
+                                    lres = evaluateInteger(operandsInteger[0], operandsInteger[1]);
+                                    if(lres > Byte.MAX_VALUE) {
+                                        throw new AlgebricksException("Overflow happened.");
+                                    } 
+                                    if(lres < Byte.MIN_VALUE) {
+                                        throw new AlgebricksException("Underflow happened.");
+                                    }                                     
+                                    aInt8.setValue((byte)lres);
+                                    serde.serialize(aInt8, out);                
+                                    break;                                
+                                case typeInt16:
+                                    serde = AqlSerializerDeserializerProvider.INSTANCE
+                                    .getSerializerDeserializer(BuiltinType.AINT16);
+                                    lres = evaluateInteger(operandsInteger[0], operandsInteger[1]);
+                                    if(lres > Short.MAX_VALUE) {
+                                        throw new AlgebricksException("Overflow happened.");
+                                    } 
+                                    if(lres < Short.MIN_VALUE) {
+                                        throw new AlgebricksException("Underflow happened.");
+                                    }                                    
+                                    aInt16.setValue((short)lres);
+                                    serde.serialize(aInt16, out);                
+                                    break;
+                                case typeInt32:
+                                    serde = AqlSerializerDeserializerProvider.INSTANCE
+                                    .getSerializerDeserializer(BuiltinType.AINT32);
+                                    lres = evaluateInteger(operandsInteger[0], operandsInteger[1]);
+                                    if(lres > Integer.MAX_VALUE) {
+                                        throw new AlgebricksException("Overflow happened.");
+                                    } 
+                                    if(lres < Integer.MIN_VALUE) {
+                                        throw new AlgebricksException("Underflow happened.");
+                                    }                                      
+                                    aInt32.setValue((int)lres);
+                                    serde.serialize(aInt32, out);                 
+                                    break;
+                                case typeInt64:
+                                    serde = AqlSerializerDeserializerProvider.INSTANCE
+                                    .getSerializerDeserializer(BuiltinType.AINT64);
+                                    lres = evaluateInteger(operandsInteger[0], operandsInteger[1]);                                      
+                                    aInt64.setValue(lres);
+                                    serde.serialize(aInt64, out);                   
+                                    break;
+                                case typeFloat:
+                                    serde = AqlSerializerDeserializerProvider.INSTANCE
+                                    .getSerializerDeserializer(BuiltinType.AFLOAT);
+                                    dres = evaluateDouble(operandsFloating[0], operandsFloating[1]);
+                                    if(dres > Float.MAX_VALUE) {
+                                        throw new AlgebricksException("Overflow happened.");
+                                    } 
+                                    if(dres < - Float.MAX_VALUE) {
+                                        throw new AlgebricksException("Underflow happened.");
+                                    }                                      
+                                    aFloat.setValue((float)dres);
+                                    serde.serialize(aFloat, out);                   
+                                    break;                                    
+                                case typeDouble:
+                                    serde = AqlSerializerDeserializerProvider.INSTANCE
+                                    .getSerializerDeserializer(BuiltinType.ADOUBLE);
+                                    aDouble.setValue(evaluateDouble(operandsFloating[0], operandsFloating[1]));
+                                    serde.serialize(aDouble, out);                   
+                                    break;
+                            }                                                   
+                        } catch (HyracksDataException hde) {
+                            throw new AlgebricksException(hde);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
new file mode 100644
index 0000000..a0befd8
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
@@ -0,0 +1,169 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AMutableString;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.AString;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+/**
+ * @author ilovesoup
+ */
+public abstract class AbstractQuadStringStringEval implements ICopyEvaluator {
+
+    private DataOutput dout;
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage array2 = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage array3 = new ArrayBackedValueStorage();
+    private ICopyEvaluator eval0;
+    private ICopyEvaluator eval1;
+    private ICopyEvaluator eval2;
+    private ICopyEvaluator eval3;
+
+    private AMutableString resultBuffer = new AMutableString("");
+    @SuppressWarnings("rawtypes")
+    private ISerializerDeserializer nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.ANULL);
+    @SuppressWarnings("rawtypes")
+    private ISerializerDeserializer strSerde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.ASTRING);
+
+    public AbstractQuadStringStringEval(DataOutput dout, ICopyEvaluatorFactory eval0, ICopyEvaluatorFactory eval1,
+            ICopyEvaluatorFactory eval2, ICopyEvaluatorFactory eval3) throws AlgebricksException {
+        this.dout = dout;
+        this.eval0 = eval0.createEvaluator(array0);
+        this.eval1 = eval1.createEvaluator(array1);
+        this.eval2 = eval2.createEvaluator(array2);
+        this.eval3 = eval3.createEvaluator(array3);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        array0.reset();
+        eval0.evaluate(tuple);
+        array1.reset();
+        eval1.evaluate(tuple);
+        array2.reset();
+        eval2.evaluate(tuple);
+        array3.reset();
+        eval3.evaluate(tuple);
+
+        try {
+            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                nullSerde.serialize(ANull.NULL, dout);
+                return;
+            } else if (array0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+                if (array0.getByteArray()[1] == SER_NULL_TYPE_TAG) {
+                    dout.write(array0.getByteArray(), array0.getStartOffset(), array0.getLength());
+                    return;
+                }
+
+            } else {
+                throw new AlgebricksException("Expects String Type.");
+            }
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        } catch (IOException e) {
+            throw new AlgebricksException(e.getMessage());
+        }
+
+        byte[] b0 = array0.getByteArray();
+        byte[] b1 = array1.getByteArray();
+        byte[] b2 = array2.getByteArray();
+        byte[] b3 = array3.getByteArray();
+
+        int len0 = array0.getLength();
+        int len1 = array1.getLength();
+        int len2 = array2.getLength();
+        int len3 = array3.getLength();
+
+        int s0 = array0.getStartOffset();
+        int s1 = array1.getStartOffset();
+        int s2 = array2.getStartOffset();
+        int s3 = array3.getStartOffset();
+
+        String res = compute(b0, len0, s0, b1, len1, s1, b2, len2, s2, b3, len3, s3, array0, array1);
+        resultBuffer.setValue(res);
+        try {
+            strSerde.serialize(resultBuffer, dout);
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
+    }
+
+    protected abstract String compute(byte[] b0, int l0, int s0, byte[] b1, int l1, int s1, byte[] b2, int l2, int s2,
+            byte[] b3, int l3, int s3, ArrayBackedValueStorage array0, ArrayBackedValueStorage array1)
+            throws AlgebricksException;
+
+    protected String toRegex(AString pattern) {
+        StringBuilder sb = new StringBuilder();
+        String str = pattern.getStringValue();
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            if (c == '\\' && (i < str.length() - 1) && (str.charAt(i + 1) == '_' || str.charAt(i + 1) == '%')) {
+                sb.append(str.charAt(i + 1));
+                ++i;
+            } else if (c == '%') {
+                sb.append(".*");
+            } else if (c == '_') {
+                sb.append(".");
+            } else {
+                if (Arrays.binarySearch(reservedRegexChars, c) >= 0) {
+                    sb.append('\\');
+                }
+                sb.append(c);
+            }
+        }
+        return sb.toString();
+    }
+
+    protected int toFlag(AString pattern) {
+        String str = pattern.getStringValue();
+        int flag = 0;
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            switch (c) {
+                case 's':
+                    flag |= Pattern.DOTALL;
+                    break;
+                case 'm':
+                    flag |= Pattern.MULTILINE;
+                    break;
+                case 'i':
+                    flag |= Pattern.CASE_INSENSITIVE;
+                    break;
+                case 'x':
+                    flag |= Pattern.COMMENTS;
+                    break;
+            }
+        }
+        return flag;
+    }
+
+    private final static char[] reservedRegexChars = new char[] { '\\', '(', ')', '[', ']', '{', '}', '.', '^', '$',
+            '*', '|' };
+
+    static {
+        Arrays.sort(reservedRegexChars);
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
new file mode 100644
index 0000000..e0f8fc9
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringBoolEval.java
@@ -0,0 +1,141 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ABoolean;
+import edu.uci.ics.asterix.om.base.AString;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import java.io.DataOutput;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public abstract class AbstractTripleStringBoolEval implements ICopyEvaluator {
+
+    private DataOutput dout;
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage array2 = new ArrayBackedValueStorage();
+    private ICopyEvaluator eval0;
+    private ICopyEvaluator eval1;
+    private ICopyEvaluator eval2;
+    @SuppressWarnings("rawtypes")
+    private ISerializerDeserializer boolSerde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.ABOOLEAN);
+
+    public AbstractTripleStringBoolEval(DataOutput dout, ICopyEvaluatorFactory eval0, ICopyEvaluatorFactory eval1,
+            ICopyEvaluatorFactory eval2) throws AlgebricksException {
+        this.dout = dout;
+        this.eval0 = eval0.createEvaluator(array0);
+        this.eval1 = eval1.createEvaluator(array1);
+        this.eval2 = eval2.createEvaluator(array2);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        array0.reset();
+        eval0.evaluate(tuple);
+        array1.reset();
+        eval1.evaluate(tuple);
+        array2.reset();
+        eval2.evaluate(tuple);
+
+        try {
+            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG && array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                boolSerde.serialize(ABoolean.TRUE, dout);
+                return;
+            } else if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG || array1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                boolSerde.serialize(ABoolean.FALSE, dout);
+                return;
+            }
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
+
+        byte[] b0 = array0.getByteArray();
+        byte[] b1 = array1.getByteArray();
+        byte[] b2 = array2.getByteArray();
+
+        int len0 = array0.getLength();
+        int len1 = array1.getLength();
+        int len2 = array2.getLength();
+
+        int s0 = array0.getStartOffset();
+        int s1 = array1.getStartOffset();
+        int s2 = array2.getStartOffset();
+
+        ABoolean res = compute(b0, len0, s0, b1, len1, s1, b2, len2, s2, array0, array1) ? ABoolean.TRUE
+                : ABoolean.FALSE;
+        try {
+            boolSerde.serialize(res, dout);
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
+    }
+
+    protected abstract boolean compute(byte[] b0, int l0, int s0, byte[] b1, int l1, int s1, byte[] b2, int l2, int s2,
+            ArrayBackedValueStorage array0, ArrayBackedValueStorage array1) throws AlgebricksException;
+
+    protected String toRegex(AString pattern) {
+        StringBuilder sb = new StringBuilder();
+        String str = pattern.getStringValue();
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            if (c == '\\' && (i < str.length() - 1) && (str.charAt(i + 1) == '_' || str.charAt(i + 1) == '%')) {
+                sb.append(str.charAt(i + 1));
+                ++i;
+            } else if (c == '%') {
+                sb.append(".*");
+            } else if (c == '_') {
+                sb.append(".");
+            } else {
+                if (Arrays.binarySearch(reservedRegexChars, c) >= 0) {
+                    sb.append('\\');
+                }
+                sb.append(c);
+            }
+        }
+        return sb.toString();
+    }
+
+    protected int toFlag(AString pattern) {
+        String str = pattern.getStringValue();
+        int flag = 0;
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            switch (c) {
+                case 's':
+                    flag |= Pattern.DOTALL;
+                    break;
+                case 'm':
+                    flag |= Pattern.MULTILINE;
+                    break;
+                case 'i':
+                    flag |= Pattern.CASE_INSENSITIVE;
+                    break;
+                case 'x':
+                    flag |= Pattern.COMMENTS;
+                    break;
+            }
+        }
+        return flag;
+    }
+
+    private final static char[] reservedRegexChars = new char[] { '\\', '(', ')', '[', ']', '{', '}', '.', '^', '$',
+            '*', '|' };
+
+    static {
+        Arrays.sort(reservedRegexChars);
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
new file mode 100644
index 0000000..e82d30f
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
@@ -0,0 +1,156 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AMutableString;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.AString;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.regex.Pattern;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public abstract class AbstractTripleStringStringEval implements ICopyEvaluator {
+
+    private DataOutput dout;
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
+    private ArrayBackedValueStorage array2 = new ArrayBackedValueStorage();
+    private ICopyEvaluator eval0;
+    private ICopyEvaluator eval1;
+    private ICopyEvaluator eval2;
+
+    private AMutableString resultBuffer = new AMutableString("");
+    @SuppressWarnings("rawtypes")
+    private ISerializerDeserializer nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.ANULL);
+    @SuppressWarnings("rawtypes")
+    private ISerializerDeserializer strSerde = AqlSerializerDeserializerProvider.INSTANCE
+            .getSerializerDeserializer(BuiltinType.ASTRING);
+
+    public AbstractTripleStringStringEval(DataOutput dout, ICopyEvaluatorFactory eval0, ICopyEvaluatorFactory eval1,
+            ICopyEvaluatorFactory eval2) throws AlgebricksException {
+        this.dout = dout;
+        this.eval0 = eval0.createEvaluator(array0);
+        this.eval1 = eval1.createEvaluator(array1);
+        this.eval2 = eval2.createEvaluator(array2);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+        array0.reset();
+        eval0.evaluate(tuple);
+        array1.reset();
+        eval1.evaluate(tuple);
+        array2.reset();
+        eval2.evaluate(tuple);
+
+        try {
+            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                nullSerde.serialize(ANull.NULL, dout);
+                return;
+            } else if (array0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+                if (array0.getByteArray()[1] == SER_NULL_TYPE_TAG) {
+                    dout.write(array0.getByteArray(), array0.getStartOffset(), array0.getLength());
+                    return;
+                }
+
+            } else {
+                throw new AlgebricksException("Expects String Type.");
+            }
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        } catch (IOException e) {
+            throw new AlgebricksException(e.getMessage());
+        }
+
+        byte[] b0 = array0.getByteArray();
+        byte[] b1 = array1.getByteArray();
+        byte[] b2 = array2.getByteArray();
+
+        int len0 = array0.getLength();
+        int len1 = array1.getLength();
+        int len2 = array2.getLength();
+
+        int s0 = array0.getStartOffset();
+        int s1 = array1.getStartOffset();
+        int s2 = array2.getStartOffset();
+
+        String res = compute(b0, len0, s0, b1, len1, s1, b2, len2, s2, array0, array1);
+        resultBuffer.setValue(res);
+        try {
+            strSerde.serialize(resultBuffer, dout);
+        } catch (HyracksDataException e) {
+            throw new AlgebricksException(e);
+        }
+    }
+
+    protected abstract String compute(byte[] b0, int l0, int s0, byte[] b1, int l1, int s1, byte[] b2, int l2, int s2,
+            ArrayBackedValueStorage array0, ArrayBackedValueStorage array1) throws AlgebricksException;
+
+    protected String toRegex(AString pattern) {
+        StringBuilder sb = new StringBuilder();
+        String str = pattern.getStringValue();
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            if (c == '\\' && (i < str.length() - 1) && (str.charAt(i + 1) == '_' || str.charAt(i + 1) == '%')) {
+                sb.append(str.charAt(i + 1));
+                ++i;
+            } else if (c == '%') {
+                sb.append(".*");
+            } else if (c == '_') {
+                sb.append(".");
+            } else {
+                if (Arrays.binarySearch(reservedRegexChars, c) >= 0) {
+                    sb.append('\\');
+                }
+                sb.append(c);
+            }
+        }
+        return sb.toString();
+    }
+
+    protected int toFlag(AString pattern) {
+        String str = pattern.getStringValue();
+        int flag = 0;
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            switch (c) {
+                case 's':
+                    flag |= Pattern.DOTALL;
+                    break;
+                case 'm':
+                    flag |= Pattern.MULTILINE;
+                    break;
+                case 'i':
+                    flag |= Pattern.CASE_INSENSITIVE;
+                    break;
+                case 'x':
+                    flag |= Pattern.COMMENTS;
+                    break;
+            }
+        }
+        return flag;
+    }
+
+    private final static char[] reservedRegexChars = new char[] { '\\', '(', ')', '[', ']', '{', '}', '.', '^', '$',
+            '*', '|' };
+
+    static {
+        Arrays.sort(reservedRegexChars);
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AndDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AndDescriptor.java
index 355d30e..3d05651 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AndDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AndDescriptor.java
@@ -24,7 +24,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS,
-            "and", FunctionIdentifier.VARARGS, true);
+            "and", FunctionIdentifier.VARARGS);
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java
index a71436c..e4ada73 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AnyCollectionMemberDescriptor.java
@@ -29,7 +29,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "any-collection-member", 1, true);
+            "any-collection-member", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new AnyCollectionMemberDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CastRecordDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CastRecordDescriptor.java
index a9f25f4..aad2c27 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CastRecordDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CastRecordDescriptor.java
@@ -23,7 +23,7 @@
 public class CastRecordDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     protected static final FunctionIdentifier FID_CAST = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "cast-record", 1, true);
+            "cast-record", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CastRecordDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
index 980a6c8..d92aff9 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ClosedRecordConstructorDescriptor.java
@@ -12,7 +12,7 @@
 public class ClosedRecordConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     protected static final FunctionIdentifier FID_CLOSED = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "closed-record-constructor", FunctionIdentifier.VARARGS, true);
+            "closed-record-constructor", FunctionIdentifier.VARARGS);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new ClosedRecordConstructorDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
new file mode 100644
index 0000000..7e27463
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodePointToStringDescriptor.java
@@ -0,0 +1,152 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import edu.uci.ics.hyracks.dataflow.common.data.util.StringUtils;
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class CodePointToStringDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "codepoint-to-string", 1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new CodePointToStringDescriptor();
+        }
+    };
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
+    private final static byte[] currentUTF8 = new byte[6];
+    private final byte stringTypeTag = ATypeTag.STRING.serialize();
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+
+            private static final long serialVersionUID = 1L;
+
+            private int codePointToUTF8(int c) {
+                if (c < 0x80) {
+                    currentUTF8[0] = (byte) (c & 0x7F /*mask 7 lsb: 0b1111111 */);
+                    return 1;
+                } else if (c < 0x0800) {
+                    currentUTF8[0] = (byte) (c >> 6 & 0x1F | 0xC0);
+                    currentUTF8[1] = (byte) (c & 0x3F | 0x80);
+                    return 2;
+                } else if (c < 0x010000) {
+                    currentUTF8[0] = (byte) (c >> 12 & 0x0F | 0xE0);
+                    currentUTF8[1] = (byte) (c >> 6 & 0x3F | 0x80);
+                    currentUTF8[2] = (byte) (c & 0x3F | 0x80);
+                    return 3;
+                } else if (c < 0x200000) {
+                    currentUTF8[0] = (byte) (c >> 18 & 0x07 | 0xF0);
+                    currentUTF8[1] = (byte) (c >> 12 & 0x3F | 0x80);
+                    currentUTF8[2] = (byte) (c >> 6 & 0x3F | 0x80);
+                    currentUTF8[3] = (byte) (c & 0x3F | 0x80);
+                    return 4;
+                } else if (c < 0x4000000) {
+                    currentUTF8[0] = (byte) (c >> 24 & 0x03 | 0xF8);
+                    currentUTF8[1] = (byte) (c >> 18 & 0x3F | 0x80);
+                    currentUTF8[2] = (byte) (c >> 12 & 0x3F | 0x80);
+                    currentUTF8[3] = (byte) (c >> 6 & 0x3F | 0x80);
+                    currentUTF8[4] = (byte) (c & 0x3F | 0x80);
+                    return 5;
+                } else if (c < 0x80000000) {
+                    currentUTF8[0] = (byte) (c >> 30 & 0x01 | 0xFC);
+                    currentUTF8[1] = (byte) (c >> 24 & 0x3F | 0x80);
+                    currentUTF8[2] = (byte) (c >> 18 & 0x3F | 0x80);
+                    currentUTF8[3] = (byte) (c >> 12 & 0x3F | 0x80);
+                    currentUTF8[4] = (byte) (c >> 6 & 0x3F | 0x80);
+                    currentUTF8[5] = (byte) (c & 0x3F | 0x80);
+                    return 6;
+                }
+                return 0;
+            }
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ICopyEvaluatorFactory listEvalFactory = args[0];
+                    private ArrayBackedValueStorage outInputList = new ArrayBackedValueStorage();
+                    private ICopyEvaluator evalList = listEvalFactory.createEvaluator(outInputList);
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        try {
+                            outInputList.reset();
+                            evalList.evaluate(tuple);
+                            byte[] serOrderedList = outInputList.getByteArray();
+                            if (serOrderedList[0] == SER_NULL_TYPE_TAG) {
+                                nullSerde.serialize(ANull.NULL, out);
+                                return;
+                            }
+                            if (serOrderedList[0] != SER_ORDEREDLIST_TYPE_TAG) {
+                                throw new AlgebricksException("Expects an Integer List."
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0]));
+                            }
+                            int size = AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList);
+                            try {
+                                // calculate length first
+                                int utf_8_len = 0;
+                                for (int i = 0; i < size; i++) {
+                                    int itemOffset = AOrderedListSerializerDeserializer
+                                            .getItemOffset(serOrderedList, i);
+                                    int codePoint = AInt32SerializerDeserializer.getInt(serOrderedList, itemOffset);
+                                    utf_8_len += codePointToUTF8(codePoint);
+                                }
+                                out.writeByte(stringTypeTag);
+                                StringUtils.writeUTF8Len(utf_8_len, out);
+                                for (int i = 0; i < size; i++) {
+                                    int itemOffset = AOrderedListSerializerDeserializer
+                                            .getItemOffset(serOrderedList, i);
+                                    int codePoint = AInt32SerializerDeserializer.getInt(serOrderedList, itemOffset);
+                                    utf_8_len = codePointToUTF8(codePoint);
+                                    for (int j = 0; j < utf_8_len; j++) {
+                                        out.writeByte(currentUTF8[j]);
+                                    }
+                                }
+                            } catch (AsterixException ex) {
+                                throw new AlgebricksException(ex);
+                            }
+                        } catch (IOException e1) {
+                            throw new AlgebricksException(e1.getMessage());
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodepointIterator.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodepointIterator.java
new file mode 100644
index 0000000..f103e0f
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CodepointIterator.java
@@ -0,0 +1,101 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+/**
+ *
+ * @author Xiaoyu Ma
+ */
+public class CodepointIterator {
+    public void reset(byte [] buf, int startPos) {
+        this.buf = buf;
+        this.curPos = startPos + 2;
+        this.startPos = startPos;
+        len = UTF8StringPointable.getUTFLength(buf, startPos);        
+    }
+    
+    public int size() { return len; }
+
+    private byte[] buf;
+    private int curPos = 0;
+    private int len = 0;
+    private int startPos = 0;
+
+    public int getCodePoint() {
+        return UTF8ToCodePoint(buf, curPos);
+    }
+
+    public static int UTF8ToCodePoint(byte[] b, int s) {
+        if (b[s] >> 7 == 0) {
+            // 1 byte
+            return b[s];
+        } else if ((b[s] & 0xe0) == 0xc0) { /*
+             * 0xe0 = 0b1110000
+             */
+            // 2 bytes
+            return ((int) (b[s] & 0x1f)) << 6
+                    | /*
+                     * 0x3f = 0b00111111
+                     */ ((int) (b[s + 1] & 0x3f));
+        } else if ((b[s] & 0xf0) == 0xe0) {
+            // 3bytes
+            return ((int) (b[s] & 0xf)) << 12
+                    | ((int) (b[s + 1] & 0x3f)) << 6
+                    | ((int) (b[s + 2] & 0x3f));
+        } else if ((b[s] & 0xf8) == 0xf0) {
+            // 4bytes
+            return ((int) (b[s] & 0x7)) << 18
+                    | ((int) (b[s + 1] & 0x3f)) << 12
+                    | ((int) (b[s + 2] & 0x3f)) << 6
+                    | ((int) (b[s + 3] & 0x3f));
+        } else if ((b[s] & 0xfc) == 0xf8) {
+            // 5bytes
+            return ((int) (b[s] & 0x3)) << 24
+                    | ((int) (b[s + 1] & 0x3f)) << 18
+                    | ((int) (b[s + 2] & 0x3f)) << 12
+                    | ((int) (b[s + 3] & 0x3f)) << 6
+                    | ((int) (b[s + 4] & 0x3f));
+        } else if ((b[s] & 0xfe) == 0xfc) {
+            // 6bytes
+            return ((int) (b[s] & 0x1)) << 30
+                    | ((int) (b[s + 1] & 0x3f)) << 24
+                    | ((int) (b[s + 2] & 0x3f)) << 18
+                    | ((int) (b[s + 3] & 0x3f)) << 12
+                    | ((int) (b[s + 4] & 0x3f)) << 6
+                    | ((int) (b[s + 5] & 0x3f));
+        }
+        return 0;
+    }
+
+    public void next() {
+        int step = UTF8StringPointable.charSize(buf, curPos);
+        if(step + curPos < len + 2 + startPos)
+            curPos += step;
+    }
+
+    public boolean hasNext() {
+        int step = UTF8StringPointable.charSize(buf, curPos);
+        if(step + curPos < len + 2 + startPos)
+            return true;   
+        return false;
+    }
+    
+    public static int compare(CodepointIterator ls, CodepointIterator rs) {
+        CodepointIterator shortString = ls.size() < rs.size() ? ls : rs;
+        
+        while (true) {
+            int c1 = ls.getCodePoint();
+            int c2 = rs.getCodePoint();
+            if (c1 != c2) {
+                return c1 - c2;
+            }
+            if(shortString.hasNext()) {
+                ls.next();
+                rs.next();
+            } else {
+                break;
+            }
+        }
+        return ls.size() - rs.size();
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ContainsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ContainsDescriptor.java
index ab4fb3a..cf1abc6 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ContainsDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/ContainsDescriptor.java
@@ -16,8 +16,7 @@
 public class ContainsDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "contains", 2,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "contains", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new ContainsDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CountHashedGramTokensDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CountHashedGramTokensDescriptor.java
index c5d0aa3..1e72adf 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CountHashedGramTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CountHashedGramTokensDescriptor.java
@@ -20,7 +20,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "counthashed-gram-tokens", 3, true);
+            "counthashed-gram-tokens", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CountHashedGramTokensDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CountHashedWordTokensDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CountHashedWordTokensDescriptor.java
index f3a43d6..4462098 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CountHashedWordTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CountHashedWordTokensDescriptor.java
@@ -21,7 +21,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "counthashed-word-tokens", 1, true);
+            "counthashed-word-tokens", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CountHashedWordTokensDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateCircleDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateCircleDescriptor.java
index e8c57c4..dc2c1e1 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateCircleDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateCircleDescriptor.java
@@ -28,7 +28,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "create-circle",
-            2, true);
+            2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreateCircleDescriptor();
@@ -68,7 +68,8 @@
                                     APointSerializerDeserializer.getCoordinateOffset(Coordinate.X)),
                                     ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                             APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y)));
-                            aCircle.setValue(aPoint, ADoubleSerializerDeserializer.getDouble(outInput1.getByteArray(), 1));
+                            aCircle.setValue(aPoint,
+                                    ADoubleSerializerDeserializer.getDouble(outInput1.getByteArray(), 1));
                             circleSerde.serialize(aCircle, out);
                         } catch (IOException e1) {
                             throw new AlgebricksException(e1);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateLineDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateLineDescriptor.java
index a6ca67b..370ed56 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateLineDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateLineDescriptor.java
@@ -27,8 +27,7 @@
 public class CreateLineDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "create-line", 2,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "create-line", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreateLineDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateMBRDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateMBRDescriptor.java
index cd3790c..b1c3564 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateMBRDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateMBRDescriptor.java
@@ -12,8 +12,7 @@
 public class CreateMBRDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "create-mbr", 3,
-            true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "create-mbr", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreateMBRDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePointDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePointDescriptor.java
index 82d1013..58cd6a8 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePointDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePointDescriptor.java
@@ -24,8 +24,7 @@
 public class CreatePointDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "create-point",
-            2, true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "create-point", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreatePointDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePolygonDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePolygonDescriptor.java
index a095111..f967a69 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePolygonDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreatePolygonDescriptor.java
@@ -20,7 +20,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "create-polygon",
-            FunctionIdentifier.VARARGS, true);
+            FunctionIdentifier.VARARGS);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreatePolygonDescriptor();
@@ -62,7 +62,8 @@
                             outInput.reset();
                             argEvals[i].evaluate(tuple);
                             try {
-                                out.write(outInput.getByteArray(), outInput.getStartOffset() + 1, outInput.getLength() - 1);
+                                out.write(outInput.getByteArray(), outInput.getStartOffset() + 1,
+                                        outInput.getLength() - 1);
                             } catch (IOException e) {
                                 throw new AlgebricksException(e);
                             }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
index d7945fa..44d6881 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
@@ -28,7 +28,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "create-rectangle", 2, true);
+            "create-rectangle", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new CreateRectangleDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceCheckDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceCheckDescriptor.java
index 1c1dae3..c261f1f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceCheckDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceCheckDescriptor.java
@@ -28,7 +28,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "edit-distance-check", 3, true);
+            "edit-distance-check", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EditDistanceCheckDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceDescriptor.java
index a7246fc..8a7e356 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceDescriptor.java
@@ -1,6 +1,5 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
-
 import edu.uci.ics.asterix.common.functions.FunctionConstants;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
@@ -16,7 +15,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "edit-distance",
-            2, true);
+            2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EditDistanceDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
index 61a795e..f5bfc4f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceListIsFilterable.java
@@ -34,7 +34,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "edit-distance-list-is-filterable", 2, true);
+            "edit-distance-list-is-filterable", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EditDistanceListIsFilterable();
@@ -59,13 +59,13 @@
     }
 
     private static class EditDistanceListIsFilterableEvaluator implements ICopyEvaluator {
-    	
+
         protected final ArrayBackedValueStorage argBuf = new ArrayBackedValueStorage();
         protected final IDataOutputProvider output;
-        
+
         protected final ICopyEvaluator listEval;
         protected final ICopyEvaluator edThreshEval;
-    	
+
         @SuppressWarnings("unchecked")
         private final ISerializerDeserializer<ABoolean> booleanSerde = AqlSerializerDeserializerProvider.INSTANCE
                 .getSerializerDeserializer(BuiltinType.ABOOLEAN);
@@ -74,42 +74,45 @@
                 throws AlgebricksException {
             this.output = output;
             listEval = args[0].createEvaluator(argBuf);
-        	edThreshEval = args[1].createEvaluator(argBuf);
+            edThreshEval = args[1].createEvaluator(argBuf);
         }
 
-		@Override
-		public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-			ATypeTag typeTag = null;
-			
-			// Check type and compute string length.
-			argBuf.reset();
-			listEval.evaluate(tuple);
-			typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-			int listLen = 0;
-			switch (typeTag) {
-			    case UNORDEREDLIST: {
-			        listLen = AUnorderedListSerializerDeserializer.getNumberOfItems(argBuf.getByteArray(), 0);
-			        break;
-			    }
-			    case ORDEREDLIST: {
-			        listLen = AOrderedListSerializerDeserializer.getNumberOfItems(argBuf.getByteArray(), 0);
-			        break;
-			    }
-			    default: {
-			        throw new AlgebricksException("Expected type 'ORDEREDLIST' or 'UNORDEREDLIST' as first argument. Encountered '" + typeTag.toString() + "'.");
-			    }
-			}
-			
-	        // Check type and extract edit-distance threshold.
-	        argBuf.reset();
-	        edThreshEval.evaluate(tuple);
-			typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-			if (!typeTag.equals(ATypeTag.INT32)) {
-				throw new AlgebricksException("Expected type 'INT32' as second argument. Encountered '" + typeTag.toString() + "'.");
-			}
-			int edThresh = IntegerSerializerDeserializer.getInt(argBuf.getByteArray(), 1);
-			
-			// Compute result.
+        @Override
+        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+            ATypeTag typeTag = null;
+
+            // Check type and compute string length.
+            argBuf.reset();
+            listEval.evaluate(tuple);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            int listLen = 0;
+            switch (typeTag) {
+                case UNORDEREDLIST: {
+                    listLen = AUnorderedListSerializerDeserializer.getNumberOfItems(argBuf.getByteArray(), 0);
+                    break;
+                }
+                case ORDEREDLIST: {
+                    listLen = AOrderedListSerializerDeserializer.getNumberOfItems(argBuf.getByteArray(), 0);
+                    break;
+                }
+                default: {
+                    throw new AlgebricksException(
+                            "Expected type 'ORDEREDLIST' or 'UNORDEREDLIST' as first argument. Encountered '"
+                                    + typeTag.toString() + "'.");
+                }
+            }
+
+            // Check type and extract edit-distance threshold.
+            argBuf.reset();
+            edThreshEval.evaluate(tuple);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            if (!typeTag.equals(ATypeTag.INT32)) {
+                throw new AlgebricksException("Expected type 'INT32' as second argument. Encountered '"
+                        + typeTag.toString() + "'.");
+            }
+            int edThresh = IntegerSerializerDeserializer.getInt(argBuf.getByteArray(), 1);
+
+            // Compute result.
             int lowerBound = listLen - edThresh;
             try {
                 if (lowerBound <= 0) {
@@ -120,6 +123,6 @@
             } catch (IOException e) {
                 throw new AlgebricksException(e);
             }
-		}
+        }
     }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
index 389fc1f..443f792 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EditDistanceStringIsFilterable.java
@@ -34,7 +34,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "edit-distance-string-is-filterable", 4, true);
+            "edit-distance-string-is-filterable", 4);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EditDistanceStringIsFilterable();
@@ -59,15 +59,15 @@
     }
 
     private static class EditDistanceStringIsFilterableEvaluator implements ICopyEvaluator {
-    	
+
         protected final ArrayBackedValueStorage argBuf = new ArrayBackedValueStorage();
         protected final IDataOutputProvider output;
-        
+
         protected final ICopyEvaluator stringEval;
         protected final ICopyEvaluator edThreshEval;
         protected final ICopyEvaluator gramLenEval;
-        protected final ICopyEvaluator usePrePostEval;        
-    	
+        protected final ICopyEvaluator usePrePostEval;
+
         @SuppressWarnings("unchecked")
         private final ISerializerDeserializer<ABoolean> booleanSerde = AqlSerializerDeserializerProvider.INSTANCE
                 .getSerializerDeserializer(BuiltinType.ABOOLEAN);
@@ -76,59 +76,63 @@
                 throws AlgebricksException {
             this.output = output;
             stringEval = args[0].createEvaluator(argBuf);
-        	edThreshEval = args[1].createEvaluator(argBuf);
-        	gramLenEval = args[2].createEvaluator(argBuf);
-        	usePrePostEval = args[3].createEvaluator(argBuf);
+            edThreshEval = args[1].createEvaluator(argBuf);
+            gramLenEval = args[2].createEvaluator(argBuf);
+            usePrePostEval = args[3].createEvaluator(argBuf);
         }
 
-		@Override
-		public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-			ATypeTag typeTag = null;
-			
-			// Check type and compute string length.
-			argBuf.reset();
-			stringEval.evaluate(tuple);
-			typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-			if (!typeTag.equals(ATypeTag.STRING)) {
-				throw new AlgebricksException("Expected type 'STRING' as first argument. Encountered '" + typeTag.toString() + "'.");
-			}
-			int utf8Length = UTF8StringPointable.getUTFLength(argBuf.getByteArray(), 1); 
-			int pos = 3;
-			int strLen = 0;	        
-	        int end = pos + utf8Length;
-	        while (pos < end) {
-	        	strLen++;
-	            pos += UTF8StringPointable.charSize(argBuf.getByteArray(), pos);
-	        }
-			
-	        // Check type and extract edit-distance threshold.
-	        argBuf.reset();
-	        edThreshEval.evaluate(tuple);
-			typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-			if (!typeTag.equals(ATypeTag.INT32)) {
-				throw new AlgebricksException("Expected type 'INT32' as second argument. Encountered '" + typeTag.toString() + "'.");
-			}
-			int edThresh = IntegerSerializerDeserializer.getInt(argBuf.getByteArray(), 1);
-			
-	        // Check type and extract gram length.
-			argBuf.reset();
-			gramLenEval.evaluate(tuple);
-			typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-			if (!typeTag.equals(ATypeTag.INT32)) {
-				throw new AlgebricksException("Expected type 'INT32' as third argument. Encountered '" + typeTag.toString() + "'.");
-			}
-			int gramLen = IntegerSerializerDeserializer.getInt(argBuf.getByteArray(), 1);
-			
-			// Check type and extract usePrePost flag.
-			argBuf.reset();
-			usePrePostEval.evaluate(tuple);
-			typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
-			if (!typeTag.equals(ATypeTag.BOOLEAN)) {
-				throw new AlgebricksException("Expected type 'BOOLEAN' as fourth argument. Encountered '" + typeTag.toString() + "'.");
-			}
-			boolean usePrePost = BooleanSerializerDeserializer.getBoolean(argBuf.getByteArray(), 1);
-			
-			// Compute result.			
+        @Override
+        public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+            ATypeTag typeTag = null;
+
+            // Check type and compute string length.
+            argBuf.reset();
+            stringEval.evaluate(tuple);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            if (!typeTag.equals(ATypeTag.STRING)) {
+                throw new AlgebricksException("Expected type 'STRING' as first argument. Encountered '"
+                        + typeTag.toString() + "'.");
+            }
+            int utf8Length = UTF8StringPointable.getUTFLength(argBuf.getByteArray(), 1);
+            int pos = 3;
+            int strLen = 0;
+            int end = pos + utf8Length;
+            while (pos < end) {
+                strLen++;
+                pos += UTF8StringPointable.charSize(argBuf.getByteArray(), pos);
+            }
+
+            // Check type and extract edit-distance threshold.
+            argBuf.reset();
+            edThreshEval.evaluate(tuple);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            if (!typeTag.equals(ATypeTag.INT32)) {
+                throw new AlgebricksException("Expected type 'INT32' as second argument. Encountered '"
+                        + typeTag.toString() + "'.");
+            }
+            int edThresh = IntegerSerializerDeserializer.getInt(argBuf.getByteArray(), 1);
+
+            // Check type and extract gram length.
+            argBuf.reset();
+            gramLenEval.evaluate(tuple);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            if (!typeTag.equals(ATypeTag.INT32)) {
+                throw new AlgebricksException("Expected type 'INT32' as third argument. Encountered '"
+                        + typeTag.toString() + "'.");
+            }
+            int gramLen = IntegerSerializerDeserializer.getInt(argBuf.getByteArray(), 1);
+
+            // Check type and extract usePrePost flag.
+            argBuf.reset();
+            usePrePostEval.evaluate(tuple);
+            typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argBuf.getByteArray()[0]);
+            if (!typeTag.equals(ATypeTag.BOOLEAN)) {
+                throw new AlgebricksException("Expected type 'BOOLEAN' as fourth argument. Encountered '"
+                        + typeTag.toString() + "'.");
+            }
+            boolean usePrePost = BooleanSerializerDeserializer.getBoolean(argBuf.getByteArray(), 1);
+
+            // Compute result.			
             int numGrams = (usePrePost) ? strLen + gramLen - 1 : strLen - gramLen + 1;
             int lowerBound = numGrams - edThresh * gramLen;
             try {
@@ -140,6 +144,6 @@
             } catch (IOException e) {
                 throw new AlgebricksException(e);
             }
-		}
+        }
     }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java
index 26bfea4..d1f3d25 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EmbedTypeDescriptor.java
@@ -15,14 +15,13 @@
 public class EmbedTypeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "embed-type", 1,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "embed-type", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EmbedTypeDescriptor();
         }
     };
-    
+
     @SuppressWarnings("unused")
     private IAType fieldType;
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EndsWithDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EndsWithDescriptor.java
index 19a3be7..0ef6375 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EndsWithDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/EndsWithDescriptor.java
@@ -16,8 +16,7 @@
 public class EndsWithDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "ends-with", 2,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "ends-with", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new EndsWithDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByIndexDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByIndexDescriptor.java
index a0c1ad2..2bb81ad 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByIndexDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByIndexDescriptor.java
@@ -13,13 +13,13 @@
 
     private static final long serialVersionUID = 1L;
     private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "field-access-by-index", 2, true);
+            "field-access-by-index", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new FieldAccessByIndexDescriptor();
         }
     };
-    
+
     private ARecordType recType;
 
     public void reset(ARecordType recType) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
index 2ac483b..b6e376b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FieldAccessByNameDescriptor.java
@@ -28,7 +28,7 @@
 
     private static final long serialVersionUID = 1L;
     private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "field-access-by-name", 2, true);
+            "field-access-by-name", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new FieldAccessByNameDescriptor();
@@ -55,7 +55,8 @@
         private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
         private final static byte SER_RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
 
-        public FieldAccessByNameEvalFactory(ICopyEvaluatorFactory recordEvalFactory, ICopyEvaluatorFactory fldNameEvalFactory) {
+        public FieldAccessByNameEvalFactory(ICopyEvaluatorFactory recordEvalFactory,
+                ICopyEvaluatorFactory fldNameEvalFactory) {
             this.recordEvalFactory = recordEvalFactory;
             this.fldNameEvalFactory = fldNameEvalFactory;
         }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java
index 623783e..9ad2f2b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/FuzzyEqDescriptor.java
@@ -12,8 +12,7 @@
 public class FuzzyEqDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "fuzzy-eq", 2,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "fuzzy-eq", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new FuzzyEqDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GetItemDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GetItemDescriptor.java
index f8470b0..e098ef9 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GetItemDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GetItemDescriptor.java
@@ -28,8 +28,7 @@
 public class GetItemDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-item", 2,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "get-item", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new GetItemDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GramTokensDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GramTokensDescriptor.java
index 94c6375..b01c29c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GramTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/GramTokensDescriptor.java
@@ -19,8 +19,7 @@
 public class GramTokensDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "gram-tokens",
-            3, true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "gram-tokens", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new GramTokensDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java
index 8b375ab..097df8c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/HashedGramTokensDescriptor.java
@@ -20,7 +20,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "hashed-gram-tokens", 3, true);
+            "hashed-gram-tokens", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new HashedGramTokensDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java
index 40d15ee..4e44523 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/HashedWordTokensDescriptor.java
@@ -21,13 +21,13 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "hashed-word-tokens", 1, true);
+            "hashed-word-tokens", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new HashedWordTokensDescriptor();
         }
     };
-    
+
     @Override
     public FunctionIdentifier getIdentifier() {
         return FID;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java
index abd3ae5..b2ac3ca 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/InjectFailureDescriptor.java
@@ -21,7 +21,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "inject-failure", 2, true);
+            "inject-failure", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new InjectFailureDescriptor();
@@ -55,7 +55,8 @@
                             // evaluator the failure condition
                             argOut.reset();
                             evals[1].evaluate(tuple);
-                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]);
+                            ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
+                                    .deserialize(argOut.getByteArray()[0]);
                             if (typeTag == ATypeTag.BOOLEAN) {
                                 boolean argResult = ABooleanSerializerDeserializer.getBoolean(argOut.getByteArray(), 1);
                                 if (argResult)
@@ -65,7 +66,8 @@
                             // evaluate the real evaluator
                             argOut.reset();
                             evals[0].evaluate(tuple);
-                            output.getDataOutput().write(argOut.getByteArray(), argOut.getStartOffset(), argOut.getLength());
+                            output.getDataOutput().write(argOut.getByteArray(), argOut.getStartOffset(),
+                                    argOut.getLength());
                         } catch (IOException e) {
                             throw new AlgebricksException(e);
                         }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/IsNullDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/IsNullDescriptor.java
index 5e3b7ab..813fc41 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/IsNullDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/IsNullDescriptor.java
@@ -23,7 +23,7 @@
     private static final long serialVersionUID = 1L;
 
     public final static FunctionIdentifier FID = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS,
-            "is-null", 1, true);
+            "is-null", 1);
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LenDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LenDescriptor.java
index 0e15a18..e09035e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LenDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LenDescriptor.java
@@ -28,7 +28,7 @@
 public class LenDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "len", 1, true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "len", 1);
     private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
     private final static byte SER_UNORDEREDLIST_TYPE_TAG = ATypeTag.UNORDEREDLIST.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LikeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LikeDescriptor.java
index 1b43441..a3bd5bd 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LikeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/LikeDescriptor.java
@@ -39,7 +39,7 @@
 public class LikeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "like", 2, true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "like", 2);
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
@@ -100,8 +100,8 @@
                                 first = false;
                                 newPattern = true;
                             } else {
-                                int c = strComp.compare(array0.getByteArray(), array0.getStartOffset(), array0.getLength(),
-                                        lastPattern.getByteArray(), 0, lastPattern.size());
+                                int c = strComp.compare(array0.getByteArray(), array0.getStartOffset(),
+                                        array0.getLength(), lastPattern.getByteArray(), 0, lastPattern.size());
                                 if (c != 0) {
                                     newPattern = true;
                                 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NotDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NotDescriptor.java
index abb4e25..a3f78e4 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NotDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NotDescriptor.java
@@ -26,7 +26,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS,
-            "not", 1, true);
+            "not", 1);
 
     private final static byte SER_BOOLEAN_TYPE_TAG = ATypeTag.BOOLEAN.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java
new file mode 100644
index 0000000..662e777
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAbsDescriptor.java
@@ -0,0 +1,145 @@
+/*
+ * Numeric function Absolute value
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+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.AMutableInt16;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt8;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class NumericAbsDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "numeric-abs", 1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new NumericAbsDescriptor();
+        }
+    };
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private byte serNullTypeTag = ATypeTag.NULL.serialize();
+                    private byte serInt8TypeTag = ATypeTag.INT8.serialize();
+                    private byte serInt16TypeTag = ATypeTag.INT16.serialize();
+                    private byte serInt32TypeTag = ATypeTag.INT32.serialize();
+                    private byte serInt64TypeTag = ATypeTag.INT64.serialize();
+                    private byte serFloatTypeTag = ATypeTag.FLOAT.serialize();
+                    private byte serDoubleTypeTag = ATypeTag.DOUBLE.serialize();
+
+                    private AMutableDouble aDouble = new AMutableDouble(0);
+                    private AMutableFloat aFloat = new AMutableFloat(0);
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
+                    private AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
+                    @SuppressWarnings("rawtypes")
+                    private ISerializerDeserializer serde;
+
+                    @SuppressWarnings("unchecked")
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        eval.evaluate(tuple);
+                        try {
+                            if (argOut.getByteArray()[0] == serNullTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ANULL);
+                                serde.serialize(ANull.NULL, out);
+                            } else if (argOut.getByteArray()[0] == serInt8TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT8);
+                                byte val = (byte) AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                aInt8.setValue((val <= 0) ? (byte) (0 - val) : val);
+                                serde.serialize(aInt8, out);
+                            } else if (argOut.getByteArray()[0] == serInt16TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT16);
+                                short val = (short) AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                aInt16.setValue((val <= 0) ? (short) (0 - val) : val);
+                                serde.serialize(aInt16, out);
+                            } else if (argOut.getByteArray()[0] == serInt32TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT32);
+                                int val = (int) AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                aInt32.setValue((val <= 0) ? (0 - val) : val);
+                                serde.serialize(aInt32, out);
+                            } else if (argOut.getByteArray()[0] == serInt64TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT64);
+                                long val = (long) AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                aInt64.setValue((val <= 0L) ? (0L - val) : val);
+                                serde.serialize(aInt64, out);
+                            } else if (argOut.getByteArray()[0] == serFloatTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
+                                float val = (float) AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                                aFloat.setValue((val <= 0.0f) ? 0.0f - val : val);
+                                serde.serialize(aFloat, out);
+                            } else if (argOut.getByteArray()[0] == serDoubleTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
+                                double val = (double) ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                                aDouble.setValue((val <= 0.0D) ? 0.0D - val : val);
+                                serde.serialize(aDouble, out);
+                            } else {
+                                throw new NotImplementedException("Numeric Abs is not implemented for "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                            }
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAddDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAddDescriptor.java
index baa20cd..c2791b9 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAddDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericAddDescriptor.java
@@ -1,44 +1,16 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
-
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
-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.AMutableInt16;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt64;
-import edu.uci.ics.asterix.om.base.AMutableInt8;
-import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
-public class NumericAddDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+public class NumericAddDescriptor extends AbstractNumericArithmeticEval {
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS,
-            "numeric-add", 2, true);
+            "numeric-add", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new NumericAddDescriptor();
@@ -51,130 +23,18 @@
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-
-                return new ICopyEvaluator() {
-                    private DataOutput out = output.getDataOutput();
-                    // one temp. buffer re-used by both children
-                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalLeft = args[0].createEvaluator(argOut);
-                    private ICopyEvaluator evalRight = args[1].createEvaluator(argOut);
-                    private double[] operands = new double[args.length];
-                    private boolean metInt8 = false, metInt16 = false, metInt32 = false, metInt64 = false,
-                            metFloat = false, metDouble = false;
-                    private ATypeTag typeTag;
-                    private AMutableDouble aDouble = new AMutableDouble(0);
-                    private AMutableFloat aFloat = new AMutableFloat(0);
-                    private AMutableInt64 aInt64 = new AMutableInt64(0);
-                    private AMutableInt32 aInt32 = new AMutableInt32(0);
-                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
-                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
-                    @SuppressWarnings("rawtypes")
-                    private ISerializerDeserializer serde;
-
-                    @SuppressWarnings("unchecked")
-                    @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
-                        try {
-                            for (int i = 0; i < args.length; i++) {
-                                argOut.reset();
-                                if (i == 0)
-                                    evalLeft.evaluate(tuple);
-                                else
-                                    evalRight.evaluate(tuple);
-                                typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]);
-                                switch (typeTag) {
-                                    case INT8: {
-                                        metInt8 = true;
-                                        operands[i] = AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT16: {
-                                        metInt16 = true;
-                                        operands[i] = AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT32: {
-                                        metInt32 = true;
-                                        operands[i] = AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT64: {
-                                        metInt64 = true;
-                                        operands[i] = AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case FLOAT: {
-                                        metFloat = true;
-                                        operands[i] = AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case DOUBLE: {
-                                        metDouble = true;
-                                        operands[i] = ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case NULL: {
-                                        serde = AqlSerializerDeserializerProvider.INSTANCE
-                                                .getSerializerDeserializer(BuiltinType.ANULL);
-                                        serde.serialize(ANull.NULL, out);
-                                        return;
-                                    }
-                                    default: {
-                                        throw new NotImplementedException(i == 0 ? "Left"
-                                                : "Right"
-                                                        + " Operand of Addition can not be "
-                                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                                .getByteArray()[0]));
-                                    }
-                                }
-                            }
-
-                            if (metDouble) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
-                                aDouble.setValue(operands[0] + operands[1]);
-                                serde.serialize(aDouble, out);
-                            } else if (metFloat) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
-                                aFloat.setValue((float) (operands[0] + operands[1]));
-                                serde.serialize(aFloat, out);
-                            } else if (metInt64) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT64);
-                                aInt64.setValue((long) (operands[0] + operands[1]));
-                                serde.serialize(aInt64, out);
-                            } else if (metInt32) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT32);
-                                aInt32.setValue((int) (operands[0] + operands[1]));
-                                serde.serialize(aInt32, out);
-                            } else if (metInt16) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT16);
-                                aInt16.setValue((short) (operands[0] + operands[1]));
-                                serde.serialize(aInt16, out);
-                            } else if (metInt8) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT8);
-                                aInt8.setValue((byte) (operands[0] + operands[1]));
-                                serde.serialize(aInt8, out);
-                            }
-
-                        } catch (HyracksDataException hde) {
-                            throw new AlgebricksException(hde);
-                        }
-                    }
-                };
-            }
-        };
+    protected long evaluateInteger(long x, long y) throws HyracksDataException {
+        long z = x + y;
+        if (x > 0) {
+            if (y > 0 && z < 0)
+                throw new ArithmeticException("Overflow adding " + x + " + " + y);
+        } else if (y < 0 && z > 0)
+            throw new ArithmeticException("Overflow adding " + x + " + " + y);
+        return z;
     }
 
+    @Override
+    protected double evaluateDouble(double lhs, double rhs) throws HyracksDataException {
+        return lhs + rhs;
+    }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericCeilingDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericCeilingDescriptor.java
new file mode 100644
index 0000000..2029426
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericCeilingDescriptor.java
@@ -0,0 +1,147 @@
+/*
+ * Numeric function ceiling
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+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.AMutableInt16;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt8;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class NumericCeilingDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "numeric-ceiling", 1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new NumericCeilingDescriptor();
+        }
+    };
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private byte serNullTypeTag = ATypeTag.NULL.serialize();
+                    private byte serInt8TypeTag = ATypeTag.INT8.serialize();
+                    private byte serInt16TypeTag = ATypeTag.INT16.serialize();
+                    private byte serInt32TypeTag = ATypeTag.INT32.serialize();
+                    private byte serInt64TypeTag = ATypeTag.INT64.serialize();
+                    private byte serFloatTypeTag = ATypeTag.FLOAT.serialize();
+                    private byte serDoubleTypeTag = ATypeTag.DOUBLE.serialize();
+
+                    private AMutableDouble aDouble = new AMutableDouble(0);
+                    private AMutableFloat aFloat = new AMutableFloat(0);
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
+                    private AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
+                    @SuppressWarnings("rawtypes")
+                    private ISerializerDeserializer serde;
+
+                    @SuppressWarnings("unchecked")
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        eval.evaluate(tuple);
+                        try {
+                            if (argOut.getByteArray()[0] == serNullTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ANULL);
+                                serde.serialize(ANull.NULL, out);
+                            } else if (argOut.getByteArray()[0] == serInt8TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT8);
+                                byte val = (byte) AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                aInt8.setValue(val);
+                                serde.serialize(aInt8, out);
+                            } else if (argOut.getByteArray()[0] == serInt16TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT16);
+                                short val = (short) AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                aInt16.setValue(val);
+                                serde.serialize(aInt16, out);
+                            } else if (argOut.getByteArray()[0] == serInt32TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT32);
+                                int val = (int) AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                aInt32.setValue(val);
+                                serde.serialize(aInt32, out);
+                            } else if (argOut.getByteArray()[0] == serInt64TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT64);
+                                long val = (long) AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                aInt64.setValue(val);
+                                serde.serialize(aInt64, out);
+                            } else if (argOut.getByteArray()[0] == serFloatTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
+                                float val = (float) AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                                aFloat.setValue((float) Math.ceil(val));
+                                serde.serialize(aFloat, out);
+                            } else if (argOut.getByteArray()[0] == serDoubleTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
+                                double val = (double) ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                                aDouble.setValue(Math.ceil(val));
+                                serde.serialize(aDouble, out);
+                            } else {
+                                throw new NotImplementedException("Numeric Ceiling is not implemented for "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                            }
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java
index b226ad7..87a4257 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericDivideDescriptor.java
@@ -1,44 +1,16 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
-
 import edu.uci.ics.asterix.common.functions.FunctionConstants;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
-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.AMutableInt16;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt64;
-import edu.uci.ics.asterix.om.base.AMutableInt8;
-import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
-public class NumericDivideDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+public class NumericDivideDescriptor extends AbstractNumericArithmeticEval {
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "numeric-divide",
-            2, true);
+            2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new NumericDivideDescriptor();
@@ -51,130 +23,14 @@
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-
-                return new ICopyEvaluator() {
-                    private DataOutput out = output.getDataOutput();
-                    // one temp. buffer re-used by both children
-                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalLeft = args[0].createEvaluator(argOut);
-                    private ICopyEvaluator evalRight = args[1].createEvaluator(argOut);
-                    private double[] operands = new double[args.length];
-                    private boolean metInt8 = false, metInt16 = false, metInt32 = false, metInt64 = false,
-                            metFloat = false, metDouble = false;
-                    private ATypeTag typeTag;
-                    private AMutableDouble aDouble = new AMutableDouble(0);
-                    private AMutableFloat aFloat = new AMutableFloat(0);
-                    private AMutableInt64 aInt64 = new AMutableInt64(0);
-                    private AMutableInt32 aInt32 = new AMutableInt32(0);
-                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
-                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
-                    @SuppressWarnings("rawtypes")
-                    private ISerializerDeserializer serde;
-
-                    @SuppressWarnings("unchecked")
-                    @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
-                        try {
-                            for (int i = 0; i < args.length; i++) {
-                                argOut.reset();
-                                if (i == 0)
-                                    evalLeft.evaluate(tuple);
-                                else
-                                    evalRight.evaluate(tuple);
-                                typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]);
-                                switch (typeTag) {
-                                    case INT8: {
-                                        metInt8 = true;
-                                        operands[i] = AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT16: {
-                                        metInt16 = true;
-                                        operands[i] = AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT32: {
-                                        metInt32 = true;
-                                        operands[i] = AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT64: {
-                                        metInt64 = true;
-                                        operands[i] = AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case FLOAT: {
-                                        metFloat = true;
-                                        operands[i] = AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case DOUBLE: {
-                                        metDouble = true;
-                                        operands[i] = ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case NULL: {
-                                        serde = AqlSerializerDeserializerProvider.INSTANCE
-                                                .getSerializerDeserializer(BuiltinType.ANULL);
-                                        serde.serialize(ANull.NULL, out);
-                                        return;
-                                    }
-                                    default: {
-                                        throw new NotImplementedException(i == 0 ? "Left"
-                                                : "Right"
-                                                        + " Operand of Division can not be "
-                                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                                .getByteArray()[0]));
-                                    }
-                                }
-                            }
-
-                            if (metDouble) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
-                                aDouble.setValue(operands[0] / operands[1]);
-                                serde.serialize(aDouble, out);
-                            } else if (metFloat) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
-                                aFloat.setValue((float) (operands[0] / operands[1]));
-                                serde.serialize(aFloat, out);
-                            } else if (metInt64) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT64);
-                                aInt64.setValue((long) (operands[0] / operands[1]));
-                                serde.serialize(aInt64, out);
-                            } else if (metInt32) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT32);
-                                aInt32.setValue((int) (operands[0] / operands[1]));
-                                serde.serialize(aInt32, out);
-                            } else if (metInt16) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT16);
-                                aInt16.setValue((short) (operands[0] / operands[1]));
-                                serde.serialize(aInt16, out);
-                            } else if (metInt8) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT8);
-                                aInt8.setValue((byte) (operands[0] / operands[1]));
-                                serde.serialize(aInt8, out);
-                            }
-
-                        } catch (HyracksDataException hde) {
-                            throw new AlgebricksException(hde);
-                        }
-                    }
-                };
-            }
-        };
+    protected long evaluateInteger(long lhs, long rhs) throws HyracksDataException {
+        if (rhs == 0)
+            throw new HyracksDataException("Divide by Zero.");
+        return lhs / rhs;
     }
 
+    @Override
+    protected double evaluateDouble(double lhs, double rhs) {
+        return lhs / rhs;
+    }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java
new file mode 100644
index 0000000..d30ebb5
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericFloorDescriptor.java
@@ -0,0 +1,146 @@
+/*
+ * Numeric function Floor
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+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.AMutableInt16;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt8;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class NumericFloorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "numeric-floor",
+            1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new NumericFloorDescriptor();
+        }
+    };
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private byte serNullTypeTag = ATypeTag.NULL.serialize();
+                    private byte serInt8TypeTag = ATypeTag.INT8.serialize();
+                    private byte serInt16TypeTag = ATypeTag.INT16.serialize();
+                    private byte serInt32TypeTag = ATypeTag.INT32.serialize();
+                    private byte serInt64TypeTag = ATypeTag.INT64.serialize();
+                    private byte serFloatTypeTag = ATypeTag.FLOAT.serialize();
+                    private byte serDoubleTypeTag = ATypeTag.DOUBLE.serialize();
+
+                    private AMutableDouble aDouble = new AMutableDouble(0);
+                    private AMutableFloat aFloat = new AMutableFloat(0);
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
+                    private AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
+                    @SuppressWarnings("rawtypes")
+                    private ISerializerDeserializer serde;
+
+                    @SuppressWarnings("unchecked")
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        eval.evaluate(tuple);
+                        try {
+                            if (argOut.getByteArray()[0] == serNullTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ANULL);
+                                serde.serialize(ANull.NULL, out);
+                            } else if (argOut.getByteArray()[0] == serInt8TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT8);
+                                byte val = (byte) AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                aInt8.setValue(val);
+                                serde.serialize(aInt8, out);
+                            } else if (argOut.getByteArray()[0] == serInt16TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT16);
+                                short val = (short) AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                aInt16.setValue(val);
+                                serde.serialize(aInt16, out);
+                            } else if (argOut.getByteArray()[0] == serInt32TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT32);
+                                int val = (int) AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                aInt32.setValue(val);
+                                serde.serialize(aInt32, out);
+                            } else if (argOut.getByteArray()[0] == serInt64TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT64);
+                                long val = (long) AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                aInt64.setValue(val);
+                                serde.serialize(aInt64, out);
+                            } else if (argOut.getByteArray()[0] == serFloatTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
+                                float val = (float) AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                                aFloat.setValue((float) Math.floor(val));
+                                serde.serialize(aFloat, out);
+                            } else if (argOut.getByteArray()[0] == serDoubleTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
+                                double val = (double) ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                                aDouble.setValue(Math.floor(val));
+                                serde.serialize(aDouble, out);
+                            } else {
+                                throw new NotImplementedException("Numeric Floor is not implemented for "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                            }
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
new file mode 100644
index 0000000..c92d75f
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericModuloDescriptor.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+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.AMutableInt16;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt8;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+/**
+ * @author kisskys
+ */
+public class NumericModuloDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "numeric-mod", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new NumericModuloDescriptor();
+        }
+    };
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+
+                return new ICopyEvaluator() {
+                    private DataOutput out = output.getDataOutput();
+                    // one temp. buffer re-used by both children
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator evalLeft = args[0].createEvaluator(argOut);
+                    private ICopyEvaluator evalRight = args[1].createEvaluator(argOut);
+                    private double[] operands = new double[args.length];
+                    private boolean metInt8 = false, metInt16 = false, metInt32 = false, metInt64 = false,
+                            metFloat = false, metDouble = false;
+                    private ATypeTag typeTag;
+                    private AMutableDouble aDouble = new AMutableDouble(0);
+                    private AMutableFloat aFloat = new AMutableFloat(0);
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
+                    private AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
+                    @SuppressWarnings("rawtypes")
+                    private ISerializerDeserializer serde;
+
+                    @SuppressWarnings("unchecked")
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+
+                        try {
+                            for (int i = 0; i < args.length; i++) {
+                                argOut.reset();
+                                if (i == 0)
+                                    evalLeft.evaluate(tuple);
+                                else
+                                    evalRight.evaluate(tuple);
+                                typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]);
+                                switch (typeTag) {
+                                    case INT8: {
+                                        metInt8 = true;
+                                        operands[i] = AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case INT16: {
+                                        metInt16 = true;
+                                        operands[i] = AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case INT32: {
+                                        metInt32 = true;
+                                        operands[i] = AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case INT64: {
+                                        metInt64 = true;
+                                        operands[i] = AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case FLOAT: {
+                                        metFloat = true;
+                                        operands[i] = AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case DOUBLE: {
+                                        metDouble = true;
+                                        operands[i] = ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                                        break;
+                                    }
+                                    case NULL: {
+                                        serde = AqlSerializerDeserializerProvider.INSTANCE
+                                                .getSerializerDeserializer(BuiltinType.ANULL);
+                                        serde.serialize(ANull.NULL, out);
+                                        return;
+                                    }
+                                    default: {
+                                        throw new NotImplementedException(i == 0 ? "Left" : "Right"
+                                                + " Operand of Modulo can not be "
+                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
+                                                        .getByteArray()[0]));
+                                    }
+                                }
+                            }
+
+                            if (metDouble) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
+                                aDouble.setValue(operands[0] % operands[1]);
+                                serde.serialize(aDouble, out);
+                            } else if (metFloat) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
+                                aFloat.setValue((float) (operands[0] % operands[1]));
+                                serde.serialize(aFloat, out);
+                            } else if (metInt64) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT64);
+                                aInt64.setValue((long) (operands[0] % operands[1]));
+                                serde.serialize(aInt64, out);
+                            } else if (metInt32) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT32);
+                                aInt32.setValue((int) (operands[0] % operands[1]));
+                                serde.serialize(aInt32, out);
+                            } else if (metInt16) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT16);
+                                aInt16.setValue((short) (operands[0] % operands[1]));
+                                serde.serialize(aInt16, out);
+                            } else if (metInt8) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT8);
+                                aInt8.setValue((byte) (operands[0] % operands[1]));
+                                serde.serialize(aInt8, out);
+                            }
+
+                        } catch (HyracksDataException hde) {
+                            throw new AlgebricksException(hde);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java
index aa5eaaa..606f2ec 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericMultiplyDescriptor.java
@@ -1,44 +1,16 @@
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
-import java.io.DataOutput;
-
 import edu.uci.ics.asterix.common.functions.FunctionConstants;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
-import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
-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.AMutableInt16;
-import edu.uci.ics.asterix.om.base.AMutableInt32;
-import edu.uci.ics.asterix.om.base.AMutableInt64;
-import edu.uci.ics.asterix.om.base.AMutableInt8;
-import edu.uci.ics.asterix.om.base.ANull;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
-import edu.uci.ics.asterix.om.types.ATypeTag;
-import edu.uci.ics.asterix.om.types.BuiltinType;
-import edu.uci.ics.asterix.om.types.EnumDeserializer;
-import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
 import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
 import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
-import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
 
-public class NumericMultiplyDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+public class NumericMultiplyDescriptor extends AbstractNumericArithmeticEval {
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-multiply", 2, true);
+            "numeric-multiply", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new NumericMultiplyDescriptor();
@@ -51,129 +23,26 @@
     }
 
     @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
-        return new ICopyEvaluatorFactory() {
-            private static final long serialVersionUID = 1L;
+    protected long evaluateInteger(long lhs, long rhs) throws HyracksDataException {
+        int signLhs = lhs > 0 ? 1 : (lhs < 0 ? -1 : 0);
+        int signRhs = rhs > 0 ? 1 : (rhs < 0 ? -1 : 0);
+        long maximum = signLhs == signRhs ? Long.MAX_VALUE : Long.MIN_VALUE;
 
-            @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+        if (lhs != 0 && (rhs > 0 && rhs > maximum / lhs || rhs < 0 && rhs < maximum / lhs))
+            throw new HyracksDataException("Overflow Happened.");
 
-                return new ICopyEvaluator() {
-                    private DataOutput out = output.getDataOutput();
-                    // one temp. buffer re-used by both children
-                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
-                    private ICopyEvaluator evalLeft = args[0].createEvaluator(argOut);
-                    private ICopyEvaluator evalRight = args[1].createEvaluator(argOut);
-                    private double[] operands = new double[args.length];
-                    private boolean metInt8 = false, metInt16 = false, metInt32 = false, metInt64 = false,
-                            metFloat = false, metDouble = false;
-                    private ATypeTag typeTag;
-                    private AMutableDouble aDouble = new AMutableDouble(0);
-                    private AMutableFloat aFloat = new AMutableFloat(0);
-                    private AMutableInt64 aInt64 = new AMutableInt64(0);
-                    private AMutableInt32 aInt32 = new AMutableInt32(0);
-                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
-                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
-                    @SuppressWarnings("rawtypes")
-                    private ISerializerDeserializer serde;
-
-                    @SuppressWarnings("unchecked")
-                    @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
-                        try {
-                            for (int i = 0; i < args.length; i++) {
-                                argOut.reset();
-                                if (i == 0)
-                                    evalLeft.evaluate(tuple);
-                                else
-                                    evalRight.evaluate(tuple);
-                                typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]);
-                                switch (typeTag) {
-                                    case INT8: {
-                                        metInt8 = true;
-                                        operands[i] = AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT16: {
-                                        metInt16 = true;
-                                        operands[i] = AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT32: {
-                                        metInt32 = true;
-                                        operands[i] = AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case INT64: {
-                                        metInt64 = true;
-                                        operands[i] = AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case FLOAT: {
-                                        metFloat = true;
-                                        operands[i] = AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case DOUBLE: {
-                                        metDouble = true;
-                                        operands[i] = ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
-                                        break;
-                                    }
-                                    case NULL: {
-                                        serde = AqlSerializerDeserializerProvider.INSTANCE
-                                                .getSerializerDeserializer(BuiltinType.ANULL);
-                                        serde.serialize(ANull.NULL, out);
-                                        return;
-                                    }
-                                    default: {
-                                        throw new NotImplementedException(i == 0 ? "Left"
-                                                : "Right"
-                                                        + " Operand of Multiplication can not be "
-                                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                                .getByteArray()[0]));
-                                    }
-                                }
-                            }
-                            if (metDouble) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
-                                aDouble.setValue(operands[0] * operands[1]);
-                                serde.serialize(aDouble, out);
-                            } else if (metFloat) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
-                                aFloat.setValue((float) (operands[0] * operands[1]));
-                                serde.serialize(aFloat, out);
-                            } else if (metInt64) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT64);
-                                aInt64.setValue((long) (operands[0] * operands[1]));
-                                serde.serialize(aInt64, out);
-                            } else if (metInt32) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT32);
-                                aInt32.setValue((int) (operands[0] * operands[1]));
-                                serde.serialize(aInt32, out);
-                            } else if (metInt16) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT16);
-                                aInt16.setValue((short) (operands[0] * operands[1]));
-                                serde.serialize(aInt16, out);
-                            } else if (metInt8) {
-                                serde = AqlSerializerDeserializerProvider.INSTANCE
-                                        .getSerializerDeserializer(BuiltinType.AINT8);
-                                aInt8.setValue((byte) (operands[0] * operands[1]));
-                                serde.serialize(aInt8, out);
-                            }
-
-                        } catch (HyracksDataException hde) {
-                            throw new AlgebricksException(hde);
-                        }
-                    }
-                };
-            }
-        };
+        return lhs * rhs;
     }
 
+    @Override
+    protected double evaluateDouble(double lhs, double rhs) throws HyracksDataException {
+        int signLhs = lhs > 0 ? 1 : (lhs < 0 ? -1 : 0);
+        int signRhs = rhs > 0 ? 1 : (rhs < 0 ? -1 : 0);
+        double maximum = signLhs == signRhs ? Double.MAX_VALUE : -Double.MAX_VALUE;
+
+        if (lhs != 0 && (rhs > 0 && rhs > maximum / lhs || rhs < 0 && rhs < maximum / lhs))
+            throw new HyracksDataException("Overflow Happened.");
+
+        return lhs * rhs;
+    }
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
new file mode 100644
index 0000000..d43cdd0
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundDescriptor.java
@@ -0,0 +1,148 @@
+/*
+ * Numeric function Round
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+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.AMutableInt16;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt64;
+import edu.uci.ics.asterix.om.base.AMutableInt8;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class NumericRoundDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "numeric-round",
+            1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new NumericRoundDescriptor();
+        }
+    };
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private byte serNullTypeTag = ATypeTag.NULL.serialize();
+                    private byte serInt8TypeTag = ATypeTag.INT8.serialize();
+                    private byte serInt16TypeTag = ATypeTag.INT16.serialize();
+                    private byte serInt32TypeTag = ATypeTag.INT32.serialize();
+                    private byte serInt64TypeTag = ATypeTag.INT64.serialize();
+                    private byte serFloatTypeTag = ATypeTag.FLOAT.serialize();
+                    private byte serDoubleTypeTag = ATypeTag.DOUBLE.serialize();
+
+                    private AMutableDouble aDouble = new AMutableDouble(0);
+                    private AMutableFloat aFloat = new AMutableFloat(0);
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
+                    private AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
+                    @SuppressWarnings("rawtypes")
+                    private ISerializerDeserializer serde;
+
+                    @SuppressWarnings("unchecked")
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        eval.evaluate(tuple);
+                        try {
+                            if (argOut.getByteArray()[0] == serNullTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ANULL);
+                                serde.serialize(ANull.NULL, out);
+                            } else if (argOut.getByteArray()[0] == serInt8TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT8);
+                                byte val = (byte) AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                aInt8.setValue(val);
+                                serde.serialize(aInt8, out);
+                            } else if (argOut.getByteArray()[0] == serInt16TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT16);
+                                short val = (short) AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                aInt16.setValue(val);
+                                serde.serialize(aInt16, out);
+                            } else if (argOut.getByteArray()[0] == serInt32TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT32);
+                                int val = (int) AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                aInt32.setValue(val);
+                                serde.serialize(aInt32, out);
+                            } else if (argOut.getByteArray()[0] == serInt64TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT64);
+                                long val = (long) AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                aInt64.setValue(val);
+                                serde.serialize(aInt64, out);
+                            } else if (argOut.getByteArray()[0] == serFloatTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
+                                float val = (float) AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                                val = Math.round(val);
+                                aFloat.setValue(val);
+                                serde.serialize(aFloat, out);
+                            } else if (argOut.getByteArray()[0] == serDoubleTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
+                                double val = (double) ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                                val = Math.round(val);
+                                aDouble.setValue(val);
+                                serde.serialize(aDouble, out);
+                            } else {
+                                throw new NotImplementedException("Numeric Round is not implemented for "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                            }
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundHalfToEven2Descriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundHalfToEven2Descriptor.java
new file mode 100644
index 0000000..f43567c
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundHalfToEven2Descriptor.java
@@ -0,0 +1,174 @@
+/*
+ * Numeric function Round half to even
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.*;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.*;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import java.io.DataOutput;
+import java.math.BigDecimal;
+
+public class NumericRoundHalfToEven2Descriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "numeric-round-half-to-even2", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new NumericRoundHalfToEven2Descriptor();
+        }
+    };
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private ICopyEvaluator precision = args[1].createEvaluator(argOut);
+
+                    private byte serNullTypeTag = ATypeTag.NULL.serialize();
+                    private byte serInt8TypeTag = ATypeTag.INT8.serialize();
+                    private byte serInt16TypeTag = ATypeTag.INT16.serialize();
+                    private byte serInt32TypeTag = ATypeTag.INT32.serialize();
+                    private byte serInt64TypeTag = ATypeTag.INT64.serialize();
+                    private byte serFloatTypeTag = ATypeTag.FLOAT.serialize();
+                    private byte serDoubleTypeTag = ATypeTag.DOUBLE.serialize();
+
+                    private AMutableDouble aDouble = new AMutableDouble(0);
+                    private AMutableFloat aFloat = new AMutableFloat(0);
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
+                    private AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
+                    @SuppressWarnings("rawtypes")
+                    private ISerializerDeserializer serde;
+
+                    private int getPrecision(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        precision.evaluate(tuple);
+
+                        if (argOut.getByteArray()[0] == serInt8TypeTag) {
+                            return (int) AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                        } else if (argOut.getByteArray()[0] == serInt16TypeTag) {
+                            return (int) AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                        } else if (argOut.getByteArray()[0] == serInt32TypeTag) {
+                            return (int) AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                        } else if (argOut.getByteArray()[0] == serInt64TypeTag) {
+                            return (int) AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                        } else if (argOut.getByteArray()[0] == serFloatTypeTag) {
+                            return (int) AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                        } else if (argOut.getByteArray()[0] == serDoubleTypeTag) {
+                            return (int) ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                        }
+
+                        return 0;
+                    }
+
+                    @SuppressWarnings("unchecked")
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        eval.evaluate(tuple);
+
+                        try {
+                            if (argOut.getByteArray()[0] == serNullTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ANULL);
+                                serde.serialize(ANull.NULL, out);
+                            } else if (argOut.getByteArray()[0] == serInt8TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT8);
+                                byte val = (byte) AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                aInt8.setValue(val);
+                                serde.serialize(aInt8, out);
+                            } else if (argOut.getByteArray()[0] == serInt16TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT16);
+                                short val = (short) AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                aInt16.setValue(val);
+                                serde.serialize(aInt16, out);
+                            } else if (argOut.getByteArray()[0] == serInt32TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT32);
+                                int val = (int) AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                aInt32.setValue(val);
+                                serde.serialize(aInt32, out);
+                            } else if (argOut.getByteArray()[0] == serInt64TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT64);
+                                long val = (long) AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                aInt64.setValue(val);
+                                serde.serialize(aInt64, out);
+                            } else if (argOut.getByteArray()[0] == serFloatTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
+                                float val = (float) AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                                if (Float.isNaN(val) || Float.isInfinite(val) || val == -0.0F || val == 0.0F) {
+                                    aFloat.setValue(val);
+                                    serde.serialize(aFloat, out);
+                                } else {
+                                    BigDecimal r = new BigDecimal(Float.toString(val));
+                                    aFloat.setValue(r.setScale(getPrecision(tuple), BigDecimal.ROUND_HALF_EVEN)
+                                            .floatValue());
+                                    serde.serialize(aFloat, out);
+                                }
+                            } else if (argOut.getByteArray()[0] == serDoubleTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
+                                double val = (double) ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                                if (Double.isNaN(val) || Double.isInfinite(val) || val == -0.0D || val == 0.0D) {
+                                    aDouble.setValue(val);
+                                    serde.serialize(aDouble, out);
+                                } else {
+                                    BigDecimal r = new BigDecimal(Double.toString(val));
+                                    aDouble.setValue(r.setScale(getPrecision(tuple), BigDecimal.ROUND_HALF_EVEN)
+                                            .doubleValue());
+                                    serde.serialize(aDouble, out);
+                                }
+                            } else {
+                                throw new NotImplementedException("Numeric Round Half to Even is not implemented for "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                            }
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundHalfToEvenDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundHalfToEvenDescriptor.java
new file mode 100644
index 0000000..9499bb3
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericRoundHalfToEvenDescriptor.java
@@ -0,0 +1,135 @@
+/*
+ * Numeric function Round half to even
+ * Author : Xiaoyu Ma@UC Irvine
+ * 01/30/2012
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.*;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.*;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.NotImplementedException;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import java.io.DataOutput;
+
+public class NumericRoundHalfToEvenDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "numeric-round-half-to-even", 1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new NumericRoundHalfToEvenDescriptor();
+        }
+    };
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+                    private byte serNullTypeTag = ATypeTag.NULL.serialize();
+                    private byte serInt8TypeTag = ATypeTag.INT8.serialize();
+                    private byte serInt16TypeTag = ATypeTag.INT16.serialize();
+                    private byte serInt32TypeTag = ATypeTag.INT32.serialize();
+                    private byte serInt64TypeTag = ATypeTag.INT64.serialize();
+                    private byte serFloatTypeTag = ATypeTag.FLOAT.serialize();
+                    private byte serDoubleTypeTag = ATypeTag.DOUBLE.serialize();
+
+                    private AMutableDouble aDouble = new AMutableDouble(0);
+                    private AMutableFloat aFloat = new AMutableFloat(0);
+                    private AMutableInt64 aInt64 = new AMutableInt64(0);
+                    private AMutableInt32 aInt32 = new AMutableInt32(0);
+                    private AMutableInt16 aInt16 = new AMutableInt16((short) 0);
+                    private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);
+                    @SuppressWarnings("rawtypes")
+                    private ISerializerDeserializer serde;
+
+                    @SuppressWarnings("unchecked")
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        eval.evaluate(tuple);
+                        try {
+                            if (argOut.getByteArray()[0] == serNullTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ANULL);
+                                serde.serialize(ANull.NULL, out);
+                                return;
+                            } else if (argOut.getByteArray()[0] == serInt8TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT8);
+                                byte val = (byte) AInt8SerializerDeserializer.getByte(argOut.getByteArray(), 1);
+                                aInt8.setValue(val);
+                                serde.serialize(aInt8, out);
+                            } else if (argOut.getByteArray()[0] == serInt16TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT16);
+                                short val = (short) AInt16SerializerDeserializer.getShort(argOut.getByteArray(), 1);
+                                aInt16.setValue(val);
+                                serde.serialize(aInt16, out);
+                            } else if (argOut.getByteArray()[0] == serInt32TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT32);
+                                int val = (int) AInt32SerializerDeserializer.getInt(argOut.getByteArray(), 1);
+                                aInt32.setValue(val);
+                                serde.serialize(aInt32, out);
+                            } else if (argOut.getByteArray()[0] == serInt64TypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AINT64);
+                                long val = (long) AInt64SerializerDeserializer.getLong(argOut.getByteArray(), 1);
+                                aInt64.setValue(val);
+                                serde.serialize(aInt64, out);
+                            } else if (argOut.getByteArray()[0] == serFloatTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.AFLOAT);
+                                float val = (float) AFloatSerializerDeserializer.getFloat(argOut.getByteArray(), 1);
+                                aFloat.setValue((float) Math.rint(val));
+                                serde.serialize(aFloat, out);
+                            } else if (argOut.getByteArray()[0] == serDoubleTypeTag) {
+                                serde = AqlSerializerDeserializerProvider.INSTANCE
+                                        .getSerializerDeserializer(BuiltinType.ADOUBLE);
+                                double val = (double) ADoubleSerializerDeserializer.getDouble(argOut.getByteArray(), 1);
+                                aDouble.setValue(Math.rint(val));
+                                serde.serialize(aDouble, out);
+                            } else {
+                                throw new NotImplementedException("Numeric Round Half to Even is not implemented for "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                            }
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java
index 0b53f18..9abbf47 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericSubtractDescriptor.java
@@ -38,7 +38,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-subtract", 2, true);
+            "numeric-subtract", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new NumericSubtractDescriptor();
@@ -127,11 +127,10 @@
                                         return;
                                     }
                                     default: {
-                                        throw new NotImplementedException(i == 0 ? "Left"
-                                                : "Right"
-                                                        + " Operand of Substraction can not be "
-                                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
-                                                                .getByteArray()[0]));
+                                        throw new NotImplementedException(i == 0 ? "Left" : "Right"
+                                                + " Operand of Substraction can not be "
+                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut
+                                                        .getByteArray()[0]));
                                     }
                                 }
                             }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java
index 7998618..9e3b188 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/NumericUnaryMinusDescriptor.java
@@ -38,7 +38,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "numeric-unary-minus", 1, true);
+            "numeric-unary-minus", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new NumericUnaryMinusDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
index f3681f2..37d6ce0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
@@ -21,7 +21,7 @@
 public class OpenRecordConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     protected static final FunctionIdentifier FID_OPEN = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "open-record-constructor", FunctionIdentifier.VARARGS, true);
+            "open-record-constructor", FunctionIdentifier.VARARGS);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new OpenRecordConstructorDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OrDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OrDescriptor.java
index 8349c97..a54ec54 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OrDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OrDescriptor.java
@@ -24,7 +24,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(AlgebricksBuiltinFunctions.ALGEBRICKS_NS, "or",
-            FunctionIdentifier.VARARGS, true);
+            FunctionIdentifier.VARARGS);
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
index b9e341d..520b386 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OrderedListConstructorDescriptor.java
@@ -22,7 +22,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "ordered-list-constructor", FunctionIdentifier.VARARGS, true);
+            "ordered-list-constructor", FunctionIdentifier.VARARGS);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new OrderedListConstructorDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
index 57b7acd..25cbf74 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenDescriptor.java
@@ -27,8 +27,7 @@
 public class PrefixLenDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "prefix-len", 3,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "prefix-len", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new PrefixLenDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
index 2612583..927ade5 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/PrefixLenJaccardDescriptor.java
@@ -27,7 +27,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "prefix-len-jaccard", 2, true);
+            "prefix-len-jaccard", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new PrefixLenJaccardDescriptor();
@@ -69,8 +69,8 @@
                         // similarity threshold
                         inputVal.reset();
                         evalThreshold.evaluate(tuple);
-                        float similarityThreshold = (float) AFloatSerializerDeserializer.getFloat(inputVal.getByteArray(),
-                                1);
+                        float similarityThreshold = (float) AFloatSerializerDeserializer.getFloat(
+                                inputVal.getByteArray(), 1);
 
                         if (similarityThreshold != similarityThresholdCache || similarityFilters == null) {
                             similarityFilters = new SimilarityFiltersJaccard(similarityThreshold);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RegExpDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RegExpDescriptor.java
index 1815085..01b00a0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RegExpDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/RegExpDescriptor.java
@@ -38,8 +38,7 @@
 public class RegExpDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "reg-exp", 2,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "reg-exp", 2);
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
@@ -100,8 +99,8 @@
                                 first = false;
                                 newPattern = true;
                             } else {
-                                int c = strComp.compare(array0.getByteArray(), array0.getStartOffset(), array0.getLength(),
-                                        lastPattern.getByteArray(), 0, lastPattern.size());
+                                int c = strComp.compare(array0.getByteArray(), array0.getStartOffset(),
+                                        array0.getLength(), lastPattern.getByteArray(), 0, lastPattern.size());
                                 if (c != 0) {
                                     newPattern = true;
                                 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
index d3218ff..ec21b96 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityDescriptor.java
@@ -35,8 +35,7 @@
 public class SimilarityDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "similarity", 7,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "similarity", 7);
 
     private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
     private final static byte SER_UNORDEREDLIST_TYPE_TAG = ATypeTag.UNORDEREDLIST.serialize();
@@ -122,8 +121,8 @@
 
                             int lengthTokens1;
                             if (serList[0] == SER_ORDEREDLIST_TYPE_TAG) {
-                                lengthTokens1 = AOrderedListSerializerDeserializer
-                                        .getNumberOfItems(inputVal.getByteArray());
+                                lengthTokens1 = AOrderedListSerializerDeserializer.getNumberOfItems(inputVal
+                                        .getByteArray());
                                 // read tokens
                                 for (i = 0; i < lengthTokens1; i++) {
                                     int itemOffset;
@@ -166,8 +165,8 @@
 
                             int lengthTokens2;
                             if (serList[0] == SER_ORDEREDLIST_TYPE_TAG) {
-                                lengthTokens2 = AOrderedListSerializerDeserializer
-                                        .getNumberOfItems(inputVal.getByteArray());
+                                lengthTokens2 = AOrderedListSerializerDeserializer.getNumberOfItems(inputVal
+                                        .getByteArray());
                                 // read tokens
                                 for (i = 0; i < lengthTokens2; i++) {
                                     int itemOffset;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java
index bb9d75e..4881e2a 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardCheckDescriptor.java
@@ -15,7 +15,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "similarity-jaccard-check", 3, true);
+            "similarity-jaccard-check", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SimilarityJaccardCheckDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java
index 7328cfa..95d994f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardDescriptor.java
@@ -15,7 +15,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "similarity-jaccard", 2, true);
+            "similarity-jaccard", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SimilarityJaccardDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java
index 4008419..24f012e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixCheckDescriptor.java
@@ -28,7 +28,7 @@
     private static final long serialVersionUID = 1L;
 
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "similarity-jaccard-prefix-check", 6, true);
+            "similarity-jaccard-prefix-check", 6);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SimilarityJaccardPrefixCheckDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
index 4d9c528..54d4280 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardPrefixDescriptor.java
@@ -15,7 +15,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "similarity-jaccard-prefix", 6, true);
+            "similarity-jaccard-prefix", 6);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SimilarityJaccardPrefixDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java
index 9b941c6..23b7a5d 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardSortedCheckDescriptor.java
@@ -16,13 +16,13 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "similarity-jaccard-sorted-check", 3, true);
+            "similarity-jaccard-sorted-check", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SimilarityJaccardSortedCheckDescriptor();
         }
     };
-    
+
     @Override
     public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java
index 3c550ab..db944d4 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SimilarityJaccardSortedDescriptor.java
@@ -16,13 +16,13 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "similarity-jaccard-sorted", 2, true);
+            "similarity-jaccard-sorted", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SimilarityJaccardSortedDescriptor();
         }
     };
-    
+
     @Override
     public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
         return new ICopyEvaluatorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
index 644e89d..f35adee 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialAreaDescriptor.java
@@ -28,8 +28,7 @@
 public class SpatialAreaDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "spatial-area",
-            1, true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "spatial-area", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SpatialAreaDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
index 0fe63f5..c2a4d66 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialCellDescriptor.java
@@ -30,8 +30,7 @@
 public class SpatialCellDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "spatial-cell",
-            4, true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "spatial-cell", 4);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SpatialCellDescriptor();
@@ -75,7 +74,8 @@
                         eval3.evaluate(tuple);
 
                         try {
-                            ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput0.getByteArray()[0]);
+                            ATypeTag tag = EnumDeserializer.ATYPETAGDESERIALIZER
+                                    .deserialize(outInput0.getByteArray()[0]);
                             if (tag == ATypeTag.POINT) {
                                 double xLoc = ADoubleSerializerDeserializer.getDouble(outInput0.getByteArray(),
                                         APointSerializerDeserializer.getCoordinateOffset(Coordinate.X));
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
index 97e70b2..22132cc 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialDistanceDescriptor.java
@@ -26,7 +26,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "spatial-distance", 2, true);
+            "spatial-distance", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SpatialDistanceDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
index be31eed..b519a23 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SpatialIntersectDescriptor.java
@@ -37,7 +37,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "spatial-intersect", 2, true);
+            "spatial-intersect", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SpatialIntersectDescriptor();
@@ -751,8 +751,10 @@
 
                         try {
                             boolean res = false;
-                            ATypeTag tag0 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput0.getByteArray()[0]);
-                            ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(outInput1.getByteArray()[0]);
+                            ATypeTag tag0 = EnumDeserializer.ATYPETAGDESERIALIZER
+                                    .deserialize(outInput0.getByteArray()[0]);
+                            ATypeTag tag1 = EnumDeserializer.ATYPETAGDESERIALIZER
+                                    .deserialize(outInput1.getByteArray()[0]);
 
                             switch (tag0) {
                                 case POINT:
@@ -805,12 +807,12 @@
                                             double startY1 = ADoubleSerializerDeserializer.getDouble(outInput0
                                                     .getByteArray(), ALineSerializerDeserializer
                                                     .getStartPointCoordinateOffset(Coordinate.Y));
-                                            double endX1 = ADoubleSerializerDeserializer.getDouble(
-                                                    outInput0.getByteArray(), ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.X));
-                                            double endY1 = ADoubleSerializerDeserializer.getDouble(
-                                                    outInput0.getByteArray(), ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.Y));
+                                            double endX1 = ADoubleSerializerDeserializer.getDouble(outInput0
+                                                    .getByteArray(), ALineSerializerDeserializer
+                                                    .getEndPointCoordinateOffset(Coordinate.X));
+                                            double endY1 = ADoubleSerializerDeserializer.getDouble(outInput0
+                                                    .getByteArray(), ALineSerializerDeserializer
+                                                    .getEndPointCoordinateOffset(Coordinate.Y));
 
                                             double startX2 = ADoubleSerializerDeserializer.getDouble(outInput1
                                                     .getByteArray(), ALineSerializerDeserializer
@@ -818,23 +820,26 @@
                                             double startY2 = ADoubleSerializerDeserializer.getDouble(outInput1
                                                     .getByteArray(), ALineSerializerDeserializer
                                                     .getStartPointCoordinateOffset(Coordinate.Y));
-                                            double endX2 = ADoubleSerializerDeserializer.getDouble(
-                                                    outInput1.getByteArray(), ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.X));
-                                            double endY2 = ADoubleSerializerDeserializer.getDouble(
-                                                    outInput1.getByteArray(), ALineSerializerDeserializer
-                                                            .getEndPointCoordinateOffset(Coordinate.Y));
+                                            double endX2 = ADoubleSerializerDeserializer.getDouble(outInput1
+                                                    .getByteArray(), ALineSerializerDeserializer
+                                                    .getEndPointCoordinateOffset(Coordinate.X));
+                                            double endY2 = ADoubleSerializerDeserializer.getDouble(outInput1
+                                                    .getByteArray(), ALineSerializerDeserializer
+                                                    .getEndPointCoordinateOffset(Coordinate.Y));
                                             res = lineLineIntersection(startX1, startY1, endX1, endY1, startX2,
                                                     startY2, endX2, endY2);
                                             break;
                                         case POLYGON:
-                                            res = linePolygonIntersection(outInput0.getByteArray(), outInput1.getByteArray());
+                                            res = linePolygonIntersection(outInput0.getByteArray(),
+                                                    outInput1.getByteArray());
                                             break;
                                         case CIRCLE:
-                                            res = lineCircleIntersection(outInput0.getByteArray(), outInput1.getByteArray());
+                                            res = lineCircleIntersection(outInput0.getByteArray(),
+                                                    outInput1.getByteArray());
                                             break;
                                         case RECTANGLE:
-                                            res = lineRectangleIntersection(outInput0.getByteArray(), outInput1.getByteArray());
+                                            res = lineRectangleIntersection(outInput0.getByteArray(),
+                                                    outInput1.getByteArray());
                                             break;
                                         case NULL:
                                             res = false;
@@ -852,7 +857,8 @@
                                             res = pointInPolygon(outInput1.getByteArray(), outInput0.getByteArray());
                                             break;
                                         case LINE:
-                                            res = linePolygonIntersection(outInput1.getByteArray(), outInput0.getByteArray());
+                                            res = linePolygonIntersection(outInput1.getByteArray(),
+                                                    outInput0.getByteArray());
                                             break;
                                         case POLYGON:
                                             int numOfPoints0 = AInt16SerializerDeserializer.getShort(
@@ -880,9 +886,9 @@
                                             trianglesX1.reset();
                                             trianglesY1.reset();
                                             while (true) {
-                                                middleVertex1 = triangulatePolygon(outInput1.getByteArray(), numOfPoints1,
-                                                        pointsOffsets1, trianglesX1, trianglesY1, numOfTriangles1,
-                                                        nonSimplePolygonDetection1, middleVertex1);
+                                                middleVertex1 = triangulatePolygon(outInput1.getByteArray(),
+                                                        numOfPoints1, pointsOffsets1, trianglesX1, trianglesY1,
+                                                        numOfTriangles1, nonSimplePolygonDetection1, middleVertex1);
 
                                                 if (middleVertex1 == -1) {
                                                     break;
@@ -896,9 +902,9 @@
                                             trianglesX0.reset();
                                             trianglesY0.reset();
                                             while (true) {
-                                                middleVertex0 = triangulatePolygon(outInput0.getByteArray(), numOfPoints0,
-                                                        pointsOffsets0, trianglesX0, trianglesY0, numOfTriangles0,
-                                                        nonSimplePolygonDetection0, middleVertex0);
+                                                middleVertex0 = triangulatePolygon(outInput0.getByteArray(),
+                                                        numOfPoints0, pointsOffsets0, trianglesX0, trianglesY0,
+                                                        numOfTriangles0, nonSimplePolygonDetection0, middleVertex0);
 
                                                 if (middleVertex0 == -1) {
                                                     break;
@@ -929,7 +935,8 @@
                                             }
                                             break;
                                         case CIRCLE:
-                                            res = polygonCircleIntersection(outInput0.getByteArray(), outInput1.getByteArray());
+                                            res = polygonCircleIntersection(outInput0.getByteArray(),
+                                                    outInput1.getByteArray());
                                             break;
                                         case RECTANGLE:
                                             res = rectanglePolygonIntersection(outInput1.getByteArray(),
@@ -951,13 +958,16 @@
                                             res = pointInCircle(outInput1.getByteArray(), outInput0.getByteArray());
                                             break;
                                         case LINE:
-                                            res = lineCircleIntersection(outInput1.getByteArray(), outInput0.getByteArray());
+                                            res = lineCircleIntersection(outInput1.getByteArray(),
+                                                    outInput0.getByteArray());
                                             break;
                                         case POLYGON:
-                                            res = polygonCircleIntersection(outInput1.getByteArray(), outInput0.getByteArray());
+                                            res = polygonCircleIntersection(outInput1.getByteArray(),
+                                                    outInput0.getByteArray());
                                             break;
                                         case CIRCLE:
-                                            res = circleCircleIntersection(outInput0.getByteArray(), outInput1.getByteArray());
+                                            res = circleCircleIntersection(outInput0.getByteArray(),
+                                                    outInput1.getByteArray());
                                             break;
                                         case RECTANGLE:
                                             res = rectangleCircleIntersection(outInput1.getByteArray(),
@@ -979,7 +989,8 @@
                                             res = pointInRectangle(outInput1.getByteArray(), outInput0.getByteArray());
                                             break;
                                         case LINE:
-                                            res = lineRectangleIntersection(outInput1.getByteArray(), outInput0.getByteArray());
+                                            res = lineRectangleIntersection(outInput1.getByteArray(),
+                                                    outInput0.getByteArray());
                                             break;
                                         case POLYGON:
                                             res = rectanglePolygonIntersection(outInput0.getByteArray(),
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StartsWithDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StartsWithDescriptor.java
index 2405ad9..cd8079d 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StartsWithDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StartsWithDescriptor.java
@@ -16,8 +16,7 @@
 public class StartsWithDescriptor extends AbstractScalarFunctionDynamicDescriptor {
     private static final long serialVersionUID = 1L;
 
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "starts-with",
-            2, true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "starts-with", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new StartsWithDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringConcatDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
new file mode 100644
index 0000000..73d2ac9
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringConcatDescriptor.java
@@ -0,0 +1,111 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import edu.uci.ics.hyracks.dataflow.common.data.util.StringUtils;
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringConcatDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "string-concat",
+            1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringConcatDescriptor();
+        }
+    };
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
+    private final byte stringTypeTag = ATypeTag.STRING.serialize();
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ICopyEvaluatorFactory listEvalFactory = args[0];
+                    private ArrayBackedValueStorage outInputList = new ArrayBackedValueStorage();
+                    private ICopyEvaluator evalList = listEvalFactory.createEvaluator(outInputList);
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        try {
+                            outInputList.reset();
+                            evalList.evaluate(tuple);
+                            byte[] serOrderedList = outInputList.getByteArray();
+                            if (serOrderedList[0] == SER_NULL_TYPE_TAG) {
+                                nullSerde.serialize(ANull.NULL, out);
+                                return;
+                            }
+                            if (serOrderedList[0] != SER_ORDEREDLIST_TYPE_TAG) {
+                                throw new AlgebricksException("Expects String List."
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0]));
+                            }
+                            int size = AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList);
+                            try {
+                                // calculate length first
+                                int utf_8_len = 0;
+                                for (int i = 0; i < size; i++) {
+                                    int itemOffset = AOrderedListSerializerDeserializer
+                                            .getItemOffset(serOrderedList, i);
+                                    utf_8_len += UTF8StringPointable.getUTFLength(serOrderedList, itemOffset);
+                                }
+                                out.writeByte(stringTypeTag);
+                                StringUtils.writeUTF8Len(utf_8_len, out);
+                                for (int i = 0; i < size; i++) {
+                                    int itemOffset = AOrderedListSerializerDeserializer
+                                            .getItemOffset(serOrderedList, i);
+                                    utf_8_len = UTF8StringPointable.getUTFLength(serOrderedList, itemOffset);
+                                    for (int j = 0; j < utf_8_len; j++) {
+                                        out.writeByte(serOrderedList[2 + itemOffset + j]);
+                                    }
+                                }
+                            } catch (AsterixException ex) {
+                                throw new AlgebricksException(ex);
+                            }
+                        } catch (IOException e1) {
+                            throw new AlgebricksException(e1.getMessage());
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEndWithDescrtiptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEndWithDescrtiptor.java
new file mode 100644
index 0000000..7d5bdab
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEndWithDescrtiptor.java
@@ -0,0 +1,77 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import java.io.DataOutput;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringEndWithDescrtiptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "end-with", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringEndWithDescrtiptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+
+                DataOutput dout = output.getDataOutput();
+
+                return new AbstractBinaryStringBoolEval(dout, args[0], args[1]) {
+
+                    @Override
+                    protected boolean compute(byte[] lBytes, int lLen, int lStart, byte[] rBytes, int rLen, int rStart,
+                            ArrayBackedValueStorage array0, ArrayBackedValueStorage array1) {
+                        int len1 = UTF8StringPointable.getUTFLength(lBytes, 1);
+                        int len2 = UTF8StringPointable.getUTFLength(rBytes, 1);
+                        if (len2 > len1)
+                            return false;
+
+                        int pos = 3;
+                        int delta = len1 - len2;
+                        while (pos < len2 + 3) {
+                            char c1 = UTF8StringPointable.charAt(lBytes, pos + delta);
+                            char c2 = UTF8StringPointable.charAt(rBytes, pos);
+                            if (c1 != c2)
+                                return false;
+
+                            pos += UTF8StringPointable.charSize(lBytes, pos);
+                        }
+
+                        return true;
+                    }
+
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEqualDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
new file mode 100644
index 0000000..5417e22
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringEqualDescriptor.java
@@ -0,0 +1,73 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import java.io.DataOutput;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringEqualDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "string-equal",
+            2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringEqualDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+
+                DataOutput dout = output.getDataOutput();
+
+                return new AbstractBinaryStringBoolEval(dout, args[0], args[1]) {
+
+                    @Override
+                    protected boolean compute(byte[] lBytes, int lLen, int lStart, byte[] rBytes, int rLen, int rStart,
+                            ArrayBackedValueStorage array0, ArrayBackedValueStorage array1) {
+                        int len = UTF8StringPointable.getUTFLength(lBytes, 1);
+
+                        if (len != UTF8StringPointable.getUTFLength(rBytes, 1))
+                            return false;
+
+                        int pos = 3;
+                        while (pos < len + 3) {
+                            char c1 = UTF8StringPointable.charAt(lBytes, pos);
+                            char c2 = UTF8StringPointable.charAt(rBytes, pos);
+                            if (c1 != c2)
+                                return false;
+
+                            pos += UTF8StringPointable.charSize(lBytes, pos);
+                        }
+
+                        return true;
+                    }
+
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringJoinDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
new file mode 100644
index 0000000..83784bb
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringJoinDescriptor.java
@@ -0,0 +1,137 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import edu.uci.ics.hyracks.dataflow.common.data.util.StringUtils;
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringJoinDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "string-join", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringJoinDescriptor();
+        }
+    };
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
+    private final byte stringTypeTag = ATypeTag.STRING.serialize();
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ICopyEvaluatorFactory listEvalFactory = args[0];
+                    private ICopyEvaluatorFactory sepEvalFactory = args[1];
+                    private ArrayBackedValueStorage outInputList = new ArrayBackedValueStorage();
+                    private ArrayBackedValueStorage outInputSep = new ArrayBackedValueStorage();
+                    private ICopyEvaluator evalList = listEvalFactory.createEvaluator(outInputList);
+                    private ICopyEvaluator evalSep = sepEvalFactory.createEvaluator(outInputSep);
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        try {
+                            outInputList.reset();
+                            evalList.evaluate(tuple);
+                            byte[] serOrderedList = outInputList.getByteArray();
+
+                            outInputSep.reset();
+                            evalSep.evaluate(tuple);
+                            byte[] serSep = outInputSep.getByteArray();
+                            if (serOrderedList[0] == SER_NULL_TYPE_TAG) {
+                                nullSerde.serialize(ANull.NULL, out);
+                                return;
+                            }
+                            if (serOrderedList[0] != SER_ORDEREDLIST_TYPE_TAG) {
+                                throw new AlgebricksException("Expects String List."
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0]));
+                            }
+
+                            if (serSep[0] == SER_NULL_TYPE_TAG) {
+                            }
+                            if (serSep[0] != SER_STRING_TYPE_TAG) {
+                                throw new AlgebricksException("Expects String as Seperator."
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[0]));
+                            }
+
+                            int size = AOrderedListSerializerDeserializer.getNumberOfItems(serOrderedList);
+                            try {
+                                // calculate length first
+                                int utf_8_len = 0;
+                                int sep_len = UTF8StringPointable.getUTFLength(serSep, 1);
+
+                                for (int i = 0; i < size; i++) {
+                                    int itemOffset = AOrderedListSerializerDeserializer
+                                            .getItemOffset(serOrderedList, i);
+                                    int currentSize = UTF8StringPointable.getUTFLength(serOrderedList, itemOffset);
+                                    if (i != size - 1 && currentSize != 0) {
+                                        utf_8_len += sep_len;
+                                    }
+                                    utf_8_len += currentSize;
+                                }
+                                out.writeByte(stringTypeTag);
+                                StringUtils.writeUTF8Len(utf_8_len, out);
+                                for (int i = 0; i < size; i++) {
+                                    int itemOffset = AOrderedListSerializerDeserializer
+                                            .getItemOffset(serOrderedList, i);
+                                    utf_8_len = UTF8StringPointable.getUTFLength(serOrderedList, itemOffset);
+                                    for (int j = 0; j < utf_8_len; j++) {
+                                        out.writeByte(serOrderedList[2 + itemOffset + j]);
+                                    }
+                                    if (i == size - 1 || utf_8_len == 0)
+                                        continue;
+                                    for (int j = 0; j < sep_len; j++) {
+                                        out.writeByte(serSep[3 + j]);
+                                    }
+                                }
+                            } catch (AsterixException ex) {
+                                throw new AlgebricksException(ex);
+                            }
+                        } catch (IOException e1) {
+                            throw new AlgebricksException(e1.getMessage());
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLengthDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
new file mode 100644
index 0000000..1952da2
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLengthDescriptor.java
@@ -0,0 +1,88 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import java.io.DataOutput;
+import java.io.IOException;
+
+public class StringLengthDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "string-length",
+            1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringLengthDescriptor();
+        }
+    };
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+                    private AMutableInt32 result = new AMutableInt32(0);
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(outInput);
+                    private String errorMessage = "This can not be an instance of string";
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<AInt32> intSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT32);
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+
+                        try {
+                            outInput.reset();
+                            eval.evaluate(tuple);
+                            byte[] serString = outInput.getByteArray();
+                            if (serString[0] == SER_STRING_TYPE_TAG) {
+                                int len = UTF8StringPointable.getUTFLength(outInput.getByteArray(), 1);
+                                result.setValue(len);
+                                intSerde.serialize(result, out);
+                            } else if (serString[0] == SER_NULL_TYPE_TAG)
+                                nullSerde.serialize(ANull.NULL, out);
+                            else {
+                                throw new AlgebricksException(errorMessage);
+                            }
+                        } catch (IOException e1) {
+                            throw new AlgebricksException(errorMessage);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
\ No newline at end of file
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
new file mode 100644
index 0000000..f576cf4
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringLowerCaseDescriptor.java
@@ -0,0 +1,98 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import edu.uci.ics.hyracks.dataflow.common.data.util.StringUtils;
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringLowerCaseDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "lowercase", 1);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringLowerCaseDescriptor();
+        }
+    };
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage outInput = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(outInput);
+                    private String errorMessage = "This is not an instance of string";
+                    private final byte stt = ATypeTag.STRING.serialize();
+
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+
+                        try {
+                            outInput.reset();
+                            eval.evaluate(tuple);
+                            byte[] serString = outInput.getByteArray();
+
+                            if (serString[0] == SER_STRING_TYPE_TAG) {
+                                byte[] bytes = outInput.getByteArray();
+                                int len = UTF8StringPointable.getUTFLength(bytes, 1);
+
+                                out.writeByte(stt);
+                                StringUtils.writeUTF8Len(len, out);
+
+                                int pos = 3;
+                                while (pos < len + 3) {
+                                    char c1 = UTF8StringPointable.charAt(bytes, pos);
+                                    c1 = Character.toLowerCase(c1);
+                                    pos += UTF8StringPointable.charSize(bytes, pos);
+                                    StringUtils.writeCharAsModifiedUTF8(c1, out);
+                                }
+                            } else if (serString[0] == SER_NULL_TYPE_TAG)
+                                nullSerde.serialize(ANull.NULL, out);
+                            else
+                                throw new AlgebricksException(errorMessage);
+                        } catch (IOException e1) {
+                            throw new AlgebricksException(errorMessage);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
new file mode 100644
index 0000000..e9e016f
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesDescriptor.java
@@ -0,0 +1,112 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.utils.UTF8CharSequence;
+import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AString;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.comm.io.ByteArrayAccessibleOutputStream;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringMatchesDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "matches", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringMatchesDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+
+                DataOutput dout = output.getDataOutput();
+
+                return new AbstractBinaryStringBoolEval(dout, args[0], args[1]) {
+
+                    private Pattern pattern = null;
+                    private Matcher matcher = null;
+                    private ByteArrayAccessibleOutputStream lastPattern = new ByteArrayAccessibleOutputStream();
+                    private IBinaryComparator strComp = AqlBinaryComparatorFactoryProvider.INSTANCE
+                            .getBinaryComparatorFactory(BuiltinType.ASTRING, true).createBinaryComparator();
+                    private UTF8CharSequence carSeq = new UTF8CharSequence();
+
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ASTRING);
+
+                    @Override
+                    protected boolean compute(byte[] lBytes, int lLen, int lStart, byte[] rBytes, int rLen, int rStart,
+                            ArrayBackedValueStorage array0, ArrayBackedValueStorage array1) throws AlgebricksException {
+                        try {
+                            boolean newPattern = false;
+                            if (pattern == null) {
+                                newPattern = true;
+                            } else {
+                                int c = strComp.compare(rBytes, rStart, rLen, lastPattern.getByteArray(), 0,
+                                        lastPattern.size());
+                                if (c != 0) {
+                                    newPattern = true;
+                                }
+                            }
+                            if (newPattern) {
+                                lastPattern.reset();
+                                lastPattern.write(rBytes, rStart, rLen);
+                                // ! object creation !
+                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
+                                        lastPattern.getByteArray()));
+                                AString strPattern = (AString) stringSerde.deserialize(di);
+                                // pattern = Pattern.compile(toRegex(strPattern));
+                                pattern = Pattern.compile(strPattern.getStringValue());
+                            }
+
+                            carSeq.reset(array0, 1);
+                            if (newPattern) {
+                                matcher = pattern.matcher(carSeq);
+                            } else {
+                                matcher.reset(carSeq);
+                            }
+                            return matcher.find();
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
new file mode 100644
index 0000000..912a014
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringMatchesWithFlagDescriptor.java
@@ -0,0 +1,139 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.utils.UTF8CharSequence;
+import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AString;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.comm.io.ByteArrayAccessibleOutputStream;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringMatchesWithFlagDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "matches2", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringMatchesWithFlagDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        return new ICopyEvaluatorFactory() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+
+                DataOutput dout = output.getDataOutput();
+
+                return new AbstractTripleStringBoolEval(dout, args[0], args[1], args[2]) {
+
+                    private Pattern pattern = null;
+                    private Matcher matcher = null;
+                    private String strPattern = "";
+                    private int flags = 0;
+                    private ByteArrayAccessibleOutputStream lastPattern = new ByteArrayAccessibleOutputStream();
+                    private ByteArrayAccessibleOutputStream lastFlags = new ByteArrayAccessibleOutputStream();
+                    private IBinaryComparator strComp = AqlBinaryComparatorFactoryProvider.INSTANCE
+                            .getBinaryComparatorFactory(BuiltinType.ASTRING, true).createBinaryComparator();
+                    private UTF8CharSequence carSeq = new UTF8CharSequence();
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ASTRING);
+
+                    @Override
+                    protected boolean compute(byte[] b0, int l0, int s0, byte[] b1, int l1, int s1, byte[] b2, int l2,
+                            int s2, ArrayBackedValueStorage array0, ArrayBackedValueStorage array1)
+                            throws AlgebricksException {
+                        try {
+                            boolean newPattern = false;
+                            boolean newFlags = false;
+
+                            AString astrPattern;
+                            AString astrFlags;
+
+                            if (pattern == null) {
+                                newPattern = true;
+                                newFlags = true;
+                            } else {
+                                int c = strComp.compare(b1, s1, l1, lastPattern.getByteArray(), 0, lastPattern.size());
+                                if (c != 0) {
+                                    newPattern = true;
+                                }
+
+                                c = strComp.compare(b2, s2, l2, lastFlags.getByteArray(), 0, lastFlags.size());
+                                if (c != 0) {
+                                    newFlags = true;
+                                }
+                            }
+                            if (newPattern) {
+                                lastPattern.reset();
+                                lastPattern.write(b1, s1, l1);
+                                // ! object creation !
+                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
+                                        lastPattern.getByteArray()));
+                                astrPattern = (AString) stringSerde.deserialize(di);
+                                // strPattern = toRegex(astrPattern);
+                                strPattern = astrPattern.getStringValue();
+                            }
+                            if (newFlags) {
+                                lastFlags.reset();
+                                lastFlags.write(b2, s2, l2);
+                                // ! object creation !
+                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
+                                        lastFlags.getByteArray()));
+                                astrFlags = (AString) stringSerde.deserialize(di);
+                                flags = toFlag(astrFlags);
+                            }
+
+                            pattern = Pattern.compile(strPattern, flags);
+                            carSeq.reset(array0, 1);
+                            if (newPattern) {
+                                matcher = pattern.matcher(carSeq);
+                            } else {
+                                matcher.reset(carSeq);
+                            }
+                            return matcher.find();
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
new file mode 100644
index 0000000..15c612e
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
@@ -0,0 +1,140 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.utils.UTF8CharSequence;
+import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AString;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.comm.io.ByteArrayAccessibleOutputStream;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringReplaceDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "replace", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringReplaceDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        return new ICopyEvaluatorFactory() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+
+                DataOutput dout = output.getDataOutput();
+
+                return new AbstractTripleStringStringEval(dout, args[0], args[1], args[2]) {
+
+                    private Pattern pattern = null;
+                    private Matcher matcher = null;
+                    private String replace;
+                    private String strPattern = "";
+                    private StringBuffer resultBuf = new StringBuffer();
+                    private ByteArrayAccessibleOutputStream lastPattern = new ByteArrayAccessibleOutputStream();
+                    private ByteArrayAccessibleOutputStream lastReplace = new ByteArrayAccessibleOutputStream();
+                    private IBinaryComparator strComp = AqlBinaryComparatorFactoryProvider.INSTANCE
+                            .getBinaryComparatorFactory(BuiltinType.ASTRING, true).createBinaryComparator();
+                    private UTF8CharSequence carSeq = new UTF8CharSequence();
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ASTRING);
+
+                    @Override
+                    protected String compute(byte[] b0, int l0, int s0, byte[] b1, int l1, int s1, byte[] b2, int l2,
+                            int s2, ArrayBackedValueStorage array0, ArrayBackedValueStorage array1)
+                            throws AlgebricksException {
+                        try {
+                            boolean newPattern = false;
+                            boolean newReplace = false;
+
+                            AString astrPattern;
+                            AString astrReplace;
+
+                            if (pattern == null) {
+                                newPattern = true;
+                                newReplace = true;
+                            } else {
+                                int c = strComp.compare(b1, s1, l1, lastPattern.getByteArray(), 0, lastPattern.size());
+                                if (c != 0) {
+                                    newPattern = true;
+                                }
+
+                                c = strComp.compare(b2, s2, l2, lastReplace.getByteArray(), 0, lastReplace.size());
+                                if (c != 0) {
+                                    newReplace = true;
+                                }
+                            }
+                            if (newPattern) {
+                                lastPattern.reset();
+                                lastPattern.write(b1, s1, l1);
+                                // ! object creation !
+                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
+                                        lastPattern.getByteArray()));
+                                astrPattern = (AString) stringSerde.deserialize(di);
+                                // strPattern = toRegex(astrPattern);
+                                strPattern = astrPattern.getStringValue();
+                            }
+                            if (newReplace) {
+                                lastReplace.reset();
+                                lastReplace.write(b2, s2, l2);
+                                // ! object creation !
+                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
+                                        lastReplace.getByteArray()));
+                                astrReplace = (AString) stringSerde.deserialize(di);
+                                replace = astrReplace.getStringValue();
+                            }
+                            if (newPattern)
+                                pattern = Pattern.compile(strPattern);
+                            carSeq.reset(array0, 1);
+                            if (newPattern) {
+                                matcher = pattern.matcher(carSeq);
+                            } else {
+                                matcher.reset(carSeq);
+                            }
+                            while (matcher.find()) {
+                                matcher.appendReplacement(resultBuf, replace);
+                            }
+                            matcher.appendTail(resultBuf);
+                            return resultBuf.toString();
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
new file mode 100644
index 0000000..aedad20
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceWithFlagsDescriptor.java
@@ -0,0 +1,163 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.utils.UTF8CharSequence;
+import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AString;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.dataflow.common.comm.io.ByteArrayAccessibleOutputStream;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringReplaceWithFlagsDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "replace2", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringReplaceWithFlagsDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        return new ICopyEvaluatorFactory() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+
+                DataOutput dout = output.getDataOutput();
+
+                return new AbstractQuadStringStringEval(dout, args[0], args[1], args[2], args[3]) {
+
+                    private Pattern pattern = null;
+                    private Matcher matcher = null;
+                    private String strPattern = "";
+                    private String replace = "";
+                    private int flags = 0;
+                    private StringBuffer resultBuf = new StringBuffer();
+                    private ByteArrayAccessibleOutputStream lastPattern = new ByteArrayAccessibleOutputStream();
+                    private ByteArrayAccessibleOutputStream lastFlags = new ByteArrayAccessibleOutputStream();
+                    private ByteArrayAccessibleOutputStream lastReplace = new ByteArrayAccessibleOutputStream();
+                    private IBinaryComparator strComp = AqlBinaryComparatorFactoryProvider.INSTANCE
+                            .getBinaryComparatorFactory(BuiltinType.ASTRING, true).createBinaryComparator();
+                    private UTF8CharSequence carSeq = new UTF8CharSequence();
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<AString> stringSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ASTRING);
+
+                    @Override
+                    protected String compute(byte[] b0, int l0, int s0, byte[] b1, int l1, int s1, byte[] b2, int l2,
+                            int s2, byte[] b3, int l3, int s3, ArrayBackedValueStorage array0,
+                            ArrayBackedValueStorage array1) throws AlgebricksException {
+                        try {
+                            boolean newPattern = false;
+                            boolean newFlags = false;
+                            boolean newReplace = false;
+
+                            AString astrPattern;
+                            AString astrFlags;
+
+                            if (pattern == null) {
+                                newPattern = true;
+                                newFlags = true;
+                            } else {
+                                int c = strComp.compare(b1, s1, l1, lastPattern.getByteArray(), 0, lastPattern.size());
+                                if (c != 0) {
+                                    newPattern = true;
+                                }
+
+                                c = strComp.compare(b3, s3, l3, lastFlags.getByteArray(), 0, lastFlags.size());
+                                if (c != 0) {
+                                    newFlags = true;
+                                }
+                            }
+
+                            if (replace == null) {
+                                newReplace = true;
+                            } else {
+                                int c = strComp.compare(b2, s2, l2, lastReplace.getByteArray(), 0, lastReplace.size());
+                                if (c != 0) {
+                                    newReplace = true;
+                                }
+                            }
+
+                            if (newPattern) {
+                                lastPattern.reset();
+                                lastPattern.write(b1, s1, l1);
+                                // ! object creation !
+                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
+                                        lastPattern.getByteArray()));
+                                astrPattern = (AString) stringSerde.deserialize(di);
+                                // strPattern = toRegex(astrPattern);
+                                strPattern = astrPattern.getStringValue();
+                            }
+                            if (newReplace) {
+                                lastReplace.reset();
+                                lastReplace.write(b2, s2, l2);
+                                // ! object creation !
+                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
+                                        lastReplace.getByteArray()));
+                                replace = ((AString) stringSerde.deserialize(di)).getStringValue();
+                            }
+                            if (newFlags) {
+                                lastFlags.reset();
+                                lastFlags.write(b3, s3, l3);
+                                // ! object creation !
+                                DataInputStream di = new DataInputStream(new ByteArrayInputStream(
+                                        lastFlags.getByteArray()));
+                                astrFlags = (AString) stringSerde.deserialize(di);
+                                flags = toFlag(astrFlags);
+                            }
+
+                            if (newPattern || newFlags)
+                                pattern = Pattern.compile(strPattern, flags);
+                            resultBuf.setLength(0);
+                            carSeq.reset(array0, 1);
+                            if (newPattern) {
+                                matcher = pattern.matcher(carSeq);
+                            } else {
+                                matcher.reset(carSeq);
+                            }
+                            while (matcher.find()) {
+                                matcher.appendReplacement(resultBuf, replace);
+                            }
+                            matcher.appendTail(resultBuf);
+                            return resultBuf.toString();
+                        } catch (HyracksDataException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java
new file mode 100644
index 0000000..9ecdee9
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringStartWithDescrtiptor.java
@@ -0,0 +1,72 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringStartWithDescrtiptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "start-with", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringStartWithDescrtiptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(IDataOutputProvider output) throws AlgebricksException {
+
+                DataOutput dout = output.getDataOutput();
+
+                return new AbstractBinaryStringBoolEval(dout, args[0], args[1]) {
+
+                    @Override
+                    protected boolean compute(byte[] lBytes, int lLen, int lStart, byte[] rBytes, int rLen, int rStart,
+                            ArrayBackedValueStorage array0, ArrayBackedValueStorage array1) {
+                        int patternLength = UTF8StringPointable.getUTFLength(rBytes, 1);
+                        if (patternLength > UTF8StringPointable.getUTFLength(lBytes, 1))
+                            return false;
+
+                        int pos = 3;
+                        while (pos < patternLength + 3) {
+                            char c1 = UTF8StringPointable.charAt(lBytes, pos);
+                            char c2 = UTF8StringPointable.charAt(rBytes, pos);
+                            if (c1 != c2)
+                                return false;
+
+                            pos += UTF8StringPointable.charSize(lBytes, pos);
+                        }
+
+                        return true;
+                    }
+
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
new file mode 100644
index 0000000..3c60e28
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringToCodePointDescriptor.java
@@ -0,0 +1,147 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.builders.IAOrderedListBuilder;
+import edu.uci.ics.asterix.builders.OrderedListBuilder;
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AInt32;
+import edu.uci.ics.asterix.om.base.AMutableInt32;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.AOrderedListType;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+/**
+ * @author Xiaoyu Ma
+ */
+public class StringToCodePointDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "string-to-codepoint", 1);
+    public static final IFunctionDescriptorFactory FACTORY1 = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringToCodePointDescriptor();
+        }
+    };
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new StringToCodePointDescriptor();
+        }
+    };
+    private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+                    protected final DataOutput out = output.getDataOutput();;
+                    protected final ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    protected final ICopyEvaluator stringEval = args[0].createEvaluator(argOut);
+                    protected final AOrderedListType intListType = new AOrderedListType(BuiltinType.AINT32, null);
+
+                    private IAOrderedListBuilder listBuilder = new OrderedListBuilder();
+                    private ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
+
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+                    @SuppressWarnings("unchecked")
+                    private final ISerializerDeserializer<AInt32> int32Serde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINT32);
+                    private final AMutableInt32 aInt32 = new AMutableInt32(0);
+
+                    int UTF8ToCodePoint(byte[] b, int s) {
+                        if (b[s] >> 7 == 0) {
+                            // 1 byte
+                            return b[s];
+                        } else if ((b[s] & 0xe0) == 0xc0) { /*0xe0 = 0b1110000*/
+                            // 2 bytes
+                            return ((int) (b[s] & 0x1f)) << 6 | /*0x3f = 0b00111111*/
+                            ((int) (b[s + 1] & 0x3f));
+                        } else if ((b[s] & 0xf0) == 0xe0) {
+                            // 3bytes
+                            return ((int) (b[s] & 0xf)) << 12 | ((int) (b[s + 1] & 0x3f)) << 6
+                                    | ((int) (b[s + 2] & 0x3f));
+                        } else if ((b[s] & 0xf8) == 0xf0) {
+                            // 4bytes
+                            return ((int) (b[s] & 0x7)) << 18 | ((int) (b[s + 1] & 0x3f)) << 12
+                                    | ((int) (b[s + 2] & 0x3f)) << 6 | ((int) (b[s + 3] & 0x3f));
+                        } else if ((b[s] & 0xfc) == 0xf8) {
+                            // 5bytes
+                            return ((int) (b[s] & 0x3)) << 24 | ((int) (b[s + 1] & 0x3f)) << 18
+                                    | ((int) (b[s + 2] & 0x3f)) << 12 | ((int) (b[s + 3] & 0x3f)) << 6
+                                    | ((int) (b[s + 4] & 0x3f));
+                        } else if ((b[s] & 0xfe) == 0xfc) {
+                            // 6bytes
+                            return ((int) (b[s] & 0x1)) << 30 | ((int) (b[s + 1] & 0x3f)) << 24
+                                    | ((int) (b[s + 2] & 0x3f)) << 18 | ((int) (b[s + 3] & 0x3f)) << 12
+                                    | ((int) (b[s + 4] & 0x3f)) << 6 | ((int) (b[s + 5] & 0x3f));
+                        }
+                        return 0;
+                    }
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        try {
+                            argOut.reset();
+                            stringEval.evaluate(tuple);
+                            byte[] serString = argOut.getByteArray();
+
+                            if (serString[0] == SER_STRING_TYPE_TAG) {
+                                byte[] bytes = argOut.getByteArray();
+                                int len = UTF8StringPointable.getUTFLength(bytes, 1);
+
+                                int pos = 3;
+                                listBuilder.reset(intListType);
+                                while (pos < len + 3) {
+                                    int codePoint = UTF8ToCodePoint(bytes, pos);
+                                    pos += UTF8StringPointable.charSize(bytes, pos);
+
+                                    inputVal.reset();
+                                    aInt32.setValue(codePoint);
+                                    int32Serde.serialize(aInt32, inputVal.getDataOutput());
+                                    listBuilder.addItem(inputVal);
+
+                                }
+                                listBuilder.write(out, true);
+                            } else if (serString[0] == SER_NULL_TYPE_TAG)
+                                nullSerde.serialize(ANull.NULL, out);
+                            else
+                                throw new AlgebricksException("Expects String Type.");
+                        } catch (IOException e1) {
+                            throw new AlgebricksException(e1.getMessage());
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java
new file mode 100644
index 0000000..ebbfe80
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/Substring2Descriptor.java
@@ -0,0 +1,91 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import edu.uci.ics.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
+
+public class Substring2Descriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "substring2", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new Substring2Descriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator evalString = args[0].createEvaluator(argOut);
+                    private ICopyEvaluator evalStart = args[1].createEvaluator(argOut);
+                    private final byte stt = ATypeTag.STRING.serialize();
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        evalStart.evaluate(tuple);
+                        int start = IntegerSerializerDeserializer.getInt(argOut.getByteArray(), 1) - 1;
+                        argOut.reset();
+                        evalString.evaluate(tuple);
+
+                        byte[] bytes = argOut.getByteArray();
+                        int utflen = UTF8StringPointable.getUTFLength(bytes, 1);
+                        int sStart = 3;
+                        int c = 0;
+                        int idxPos1 = 0;
+                        // skip to start
+                        while (idxPos1 < start && c < utflen) {
+                            c += UTF8StringPointable.charSize(bytes, sStart + c);
+                            ++idxPos1;
+                        }
+                        int startSubstr = c;
+
+                        while (c < utflen) {
+                            c += UTF8StringPointable.charSize(bytes, sStart + c);
+                        }
+
+                        int substrByteLen = c - startSubstr;
+                        try {
+                            out.writeByte(stt);
+                            out.writeByte((byte) ((substrByteLen >>> 8) & 0xFF));
+                            out.writeByte((byte) ((substrByteLen >>> 0) & 0xFF));
+                            out.write(bytes, sStart + startSubstr, substrByteLen);
+
+                        } catch (IOException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
new file mode 100644
index 0000000..567526d
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringAfterDescriptor.java
@@ -0,0 +1,101 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+import java.io.DataOutput;
+import java.io.IOException;
+
+public class SubstringAfterDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "substring-after", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new SubstringAfterDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
+                    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
+                    private ICopyEvaluator evalString = args[0].createEvaluator(array0);
+                    private ICopyEvaluator evalPattern = args[1].createEvaluator(array1);
+                    private final byte stt = ATypeTag.STRING.serialize();
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        array0.reset();
+                        evalString.evaluate(tuple);
+                        byte[] src = array0.getByteArray();
+
+                        array1.reset();
+                        evalPattern.evaluate(tuple);
+                        byte[] pattern = array1.getByteArray();
+
+                        int srcLen = UTF8StringPointable.getUTFLength(src, 1);
+                        int patternLen = UTF8StringPointable.getUTFLength(pattern, 1);
+                        int posSrc = 3;
+                        int posPattern = 3;
+
+                        int offset = 0;
+                        // boolean found = false;
+                        while (posSrc - 3 < srcLen - patternLen) {
+                            offset = 0;
+                            while (posPattern + offset - 3 < patternLen && posSrc + offset - 3 < srcLen) {
+                                char c1 = UTF8StringPointable.charAt(src, posSrc + offset);
+                                char c2 = UTF8StringPointable.charAt(pattern, posPattern + offset);
+                                if (c1 != c2)
+                                    break;
+                                offset++;
+                            }
+                            if (offset == patternLen) {
+                                // found = true;
+                                break;
+                            }
+                            posSrc += UTF8StringPointable.charSize(src, posSrc);
+                        }
+
+                        posSrc += patternLen;
+                        int substrByteLen = srcLen - posSrc + 3;
+                        try {
+                            out.writeByte(stt);
+                            out.writeByte((byte) ((substrByteLen >>> 8) & 0xFF));
+                            out.writeByte((byte) ((substrByteLen >>> 0) & 0xFF));
+                            out.write(src, posSrc, substrByteLen);
+
+                        } catch (IOException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
new file mode 100644
index 0000000..fb496a1
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringBeforeDescriptor.java
@@ -0,0 +1,101 @@
+package edu.uci.ics.asterix.runtime.evaluators.functions;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IDataOutputProvider;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class SubstringBeforeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+            "substring-before", 2);
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new SubstringBeforeDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage array0 = new ArrayBackedValueStorage();
+                    private ArrayBackedValueStorage array1 = new ArrayBackedValueStorage();
+                    private ICopyEvaluator evalString = args[0].createEvaluator(array0);
+                    private ICopyEvaluator evalPattern = args[1].createEvaluator(array1);
+                    private final byte stt = ATypeTag.STRING.serialize();
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        array0.reset();
+                        evalString.evaluate(tuple);
+                        byte[] src = array0.getByteArray();
+
+                        array1.reset();
+                        evalPattern.evaluate(tuple);
+                        byte[] pattern = array1.getByteArray();
+
+                        int srcLen = UTF8StringPointable.getUTFLength(src, 1);
+                        int patternLen = UTF8StringPointable.getUTFLength(pattern, 1);
+                        int posSrc = 3;
+                        int posPattern = 3;
+
+                        int offset = 0;
+                        while (posSrc - 3 < srcLen - patternLen) {
+                            // offset = 0;                        
+                            while (posPattern + offset - 3 < patternLen && posSrc + offset - 3 < srcLen) {
+                                char c1 = UTF8StringPointable.charAt(src, posSrc + offset);
+                                char c2 = UTF8StringPointable.charAt(pattern, posPattern + offset);
+                                if (c1 != c2)
+                                    break;
+                                offset++;
+                            }
+                            if (offset == patternLen) {
+                                // found = true;
+                                break;
+                            }
+                            posSrc += UTF8StringPointable.charSize(src, posSrc);
+                        }
+                        int startSubstr = 3;
+
+                        int substrByteLen = posSrc - startSubstr;
+                        try {
+                            out.writeByte(stt);
+                            out.writeByte((byte) ((substrByteLen >>> 8) & 0xFF));
+                            out.writeByte((byte) ((substrByteLen >>> 0) & 0xFF));
+                            out.write(src, startSubstr, substrByteLen);
+
+                        } catch (IOException e) {
+                            throw new AlgebricksException(e);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
index c6d0627..5d3007f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SubstringDescriptor.java
@@ -21,8 +21,7 @@
 public class SubstringDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "substring", 3,
-            true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "substring", 3);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SubstringDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
index 29fbb7f..4a33010 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/SwitchCaseDescriptor.java
@@ -19,7 +19,7 @@
 
     private static final long serialVersionUID = 1L;
     public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "switch-case",
-            FunctionIdentifier.VARARGS, true);
+            FunctionIdentifier.VARARGS);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SwitchCaseDescriptor();
@@ -79,7 +79,8 @@
                             // the default case
                             argOut.reset();
                             evals[n - 1].evaluate(tuple);
-                            output.getDataOutput().write(argOut.getByteArray(), argOut.getStartOffset(), argOut.getLength());
+                            output.getDataOutput().write(argOut.getByteArray(), argOut.getStartOffset(),
+                                    argOut.getLength());
                         } catch (HyracksDataException hde) {
                             throw new AlgebricksException(hde);
                         } catch (IOException ioe) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
index ea0765e..39149ac 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/UnorderedListConstructorDescriptor.java
@@ -22,7 +22,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "unordered-list-constructor", FunctionIdentifier.VARARGS, true);
+            "unordered-list-constructor", FunctionIdentifier.VARARGS);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new UnorderedListConstructorDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/WordTokensDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/WordTokensDescriptor.java
index 122bd99..8f8c5f3 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/WordTokensDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/WordTokensDescriptor.java
@@ -20,8 +20,7 @@
 public class WordTokensDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "word-tokens",
-            1, true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "word-tokens", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new WordTokensDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/YearDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/YearDescriptor.java
index b95fbfa..e6da3ac 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/YearDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/YearDescriptor.java
@@ -27,7 +27,7 @@
 public class YearDescriptor extends AbstractScalarFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "year", 1, true);
+    public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "year", 1);
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
index 240587f..e9f1ac5 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
@@ -109,6 +109,7 @@
 import edu.uci.ics.asterix.runtime.evaluators.functions.NotDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.NumericAddDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.NumericDivideDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.NumericModuloDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.NumericMultiplyDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.NumericSubtractDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.NumericUnaryMinusDescriptor;
@@ -133,6 +134,28 @@
 import edu.uci.ics.asterix.runtime.evaluators.functions.UnorderedListConstructorDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.WordTokensDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.YearDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.NumericAbsDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.NumericCeilingDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.NumericFloorDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.NumericRoundDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.NumericRoundHalfToEvenDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.NumericRoundHalfToEven2Descriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringEqualDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringStartWithDescrtiptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringEndWithDescrtiptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringMatchesDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringLowerCaseDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringMatchesWithFlagDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringReplaceDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringReplaceWithFlagsDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringLengthDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.Substring2Descriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.SubstringBeforeDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.SubstringAfterDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringToCodePointDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.CodePointToStringDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringConcatDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.StringJoinDescriptor;
 import edu.uci.ics.asterix.runtime.operators.file.AdmSchemafullRecordParserFactory;
 import edu.uci.ics.asterix.runtime.operators.file.NtDelimitedDataTupleParserFactory;
 import edu.uci.ics.asterix.runtime.runningaggregates.std.TidRunningAggregateDescriptor;
@@ -238,12 +261,38 @@
         temp.add(NumericDivideDescriptor.FACTORY);
         temp.add(NumericMultiplyDescriptor.FACTORY);
         temp.add(NumericSubtractDescriptor.FACTORY);
+        temp.add(NumericModuloDescriptor.FACTORY);
         temp.add(IsNullDescriptor.FACTORY);
         temp.add(NotDescriptor.FACTORY);
         temp.add(LenDescriptor.FACTORY);
         temp.add(NonEmptyStreamAggregateDescriptor.FACTORY);
         temp.add(RangeDescriptor.FACTORY);
 
+// Xiaoyu Ma add for numeric unary functions
+        temp.add(NumericAbsDescriptor.FACTORY);
+        temp.add(NumericCeilingDescriptor.FACTORY);
+        temp.add(NumericFloorDescriptor.FACTORY);
+        temp.add(NumericRoundDescriptor.FACTORY);
+        temp.add(NumericRoundHalfToEvenDescriptor.FACTORY);
+        temp.add(NumericRoundHalfToEven2Descriptor.FACTORY);
+        // String functions
+        temp.add(StringEqualDescriptor.FACTORY);
+        temp.add(StringStartWithDescrtiptor.FACTORY);    
+        temp.add(StringEndWithDescrtiptor.FACTORY);       
+        temp.add(StringMatchesDescriptor.FACTORY);    
+        temp.add(StringLowerCaseDescriptor.FACTORY);   
+        temp.add(StringMatchesWithFlagDescriptor.FACTORY);
+        temp.add(StringReplaceDescriptor.FACTORY);      
+        temp.add(StringReplaceWithFlagsDescriptor.FACTORY);    
+        temp.add(StringLengthDescriptor.FACTORY);        
+        temp.add(Substring2Descriptor.FACTORY);    
+        temp.add(SubstringBeforeDescriptor.FACTORY); 
+        temp.add(SubstringAfterDescriptor.FACTORY); 
+        temp.add(StringToCodePointDescriptor.FACTORY);         
+        temp.add(CodePointToStringDescriptor.FACTORY); 
+        temp.add(StringConcatDescriptor.FACTORY);         
+        temp.add(StringJoinDescriptor.FACTORY);      
+
         // aggregates
         temp.add(ListifyAggregateDescriptor.FACTORY);
         temp.add(CountAggregateDescriptor.FACTORY);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/runningaggregates/std/TidRunningAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/runningaggregates/std/TidRunningAggregateDescriptor.java
index 69e823b..f4bc68d 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/runningaggregates/std/TidRunningAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/runningaggregates/std/TidRunningAggregateDescriptor.java
@@ -23,13 +23,13 @@
 public class TidRunningAggregateDescriptor extends AbstractRunningAggregateFunctionDynamicDescriptor {
 
     private static final long serialVersionUID = 1L;
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tid", 0, true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "tid", 0);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new TidRunningAggregateDescriptor();
         }
     };
-    
+
     @Override
     public ICopyRunningAggregateFunctionFactory createRunningAggregateFunctionFactory(ICopyEvaluatorFactory[] args)
             throws AlgebricksException {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/RangeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/RangeDescriptor.java
index fb7f8f0..03d2677 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/RangeDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/RangeDescriptor.java
@@ -26,13 +26,13 @@
 
     private static final long serialVersionUID = 1L;
 
-    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "range", 2, true);
+    private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "range", 2);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new RangeDescriptor();
         }
     };
-    
+
     @Override
     public FunctionIdentifier getIdentifier() {
         return FID;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/ScanCollectionDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/ScanCollectionDescriptor.java
index bfd23eb..cfac382 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/ScanCollectionDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/ScanCollectionDescriptor.java
@@ -31,7 +31,7 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "scan-collection", 1, true);
+            "scan-collection", 1);
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new ScanCollectionDescriptor();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/SubsetCollectionDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/SubsetCollectionDescriptor.java
index cd69f5b..8aee5cf 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/SubsetCollectionDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/unnestingfunctions/std/SubsetCollectionDescriptor.java
@@ -32,12 +32,12 @@
 
     private static final long serialVersionUID = 1L;
     private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
-            "subset-collection", 3, true);
+            "subset-collection", 3);
 
     private final static byte SER_ORDEREDLIST_TYPE_TAG = ATypeTag.ORDEREDLIST.serialize();
     private final static byte SER_UNORDEREDLIST_TYPE_TAG = ATypeTag.UNORDEREDLIST.serialize();
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-    
+
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
             return new SubsetCollectionDescriptor();
@@ -51,7 +51,8 @@
             private static final long serialVersionUID = 1L;
 
             @Override
-            public ICopyUnnestingFunction createUnnestingFunction(IDataOutputProvider provider) throws AlgebricksException {
+            public ICopyUnnestingFunction createUnnestingFunction(IDataOutputProvider provider)
+                    throws AlgebricksException {
 
                 final DataOutput out = provider.getDataOutput();