clean up hivesterix

git-svn-id: https://hyracks.googlecode.com/svn/branches/fullstack_job_rewriter@3008 123451ca-8445-de46-9d55-352943316053
diff --git a/hivesterix/pom.xml b/hivesterix/pom.xml
index cf9c4b5..55f837e 100644
--- a/hivesterix/pom.xml
+++ b/hivesterix/pom.xml
@@ -4,7 +4,7 @@
 	<groupId>edu.uci.ics.hivesterix</groupId>

 	<artifactId>hivesterix</artifactId>

 	<version>0.2.3-SNAPSHOT</version>

- 	<name>hivesterix</name>

+	<name>hivesterix</name>

 	<dependencies>

 		<dependency>

 			<groupId>javax.servlet</groupId>

@@ -313,6 +313,25 @@
 				</configuration>

 			</plugin>

 			<plugin>

+				<artifactId>maven-jar-plugin</artifactId>

+				<executions>

+					<execution>

+						<id>patch</id>

+						<goals>

+							<goal>jar</goal>

+						</goals>

+						<phase>package</phase>

+						<configuration>

+							<classifier>patch</classifier>

+							<finalName>a-hive</finalName>

+							<includes>

+								<include>**/org/apache/**</include>

+							</includes>

+						</configuration>

+					</execution>

+				</executions>

+			</plugin>

+			<plugin>

 				<groupId>org.codehaus.mojo</groupId>

 				<artifactId>appassembler-maven-plugin</artifactId>

 				<version>1.3</version>

@@ -358,8 +377,8 @@
 				<version>2.13</version>

 				<configuration>

 					<forkMode>pertest</forkMode>

-					<argLine>-enableassertions -Xmx2047m -Dfile.encoding=UTF-8 

-                        -Djava.util.logging.config.file=src/test/resources/logging.properties</argLine>

+					<argLine>-enableassertions -Xmx2047m -Dfile.encoding=UTF-8

+						-Djava.util.logging.config.file=src/test/resources/logging.properties</argLine>

 					<includes>

 						<include>**/test/optimizer/*TestSuite.java</include>

 						<include>**/test/optimizer/*Test.java</include>

diff --git a/hivesterix/src/main/assembly/binary-assembly.xml b/hivesterix/src/main/assembly/binary-assembly.xml
index 0500499..906f199 100755
--- a/hivesterix/src/main/assembly/binary-assembly.xml
+++ b/hivesterix/src/main/assembly/binary-assembly.xml
@@ -1,19 +1,26 @@
 <assembly>
-  <id>binary-assembly</id>
-  <formats>
-    <format>zip</format>
-    <format>dir</format>
-  </formats>
-  <includeBaseDirectory>false</includeBaseDirectory>
-  <fileSets>
-    <fileSet>
-      <directory>target/appassembler/bin</directory>
-      <outputDirectory>bin</outputDirectory>
-      <fileMode>0755</fileMode>
-    </fileSet>
-    <fileSet>
-      <directory>target/appassembler/lib</directory>
-      <outputDirectory>lib</outputDirectory>
-    </fileSet>
-  </fileSets>
+	<id>binary-assembly</id>
+	<formats>
+		<format>zip</format>
+		<format>dir</format>
+	</formats>
+	<includeBaseDirectory>false</includeBaseDirectory>
+	<fileSets>
+		<fileSet>
+			<directory>target/appassembler/bin</directory>
+			<outputDirectory>bin</outputDirectory>
+			<fileMode>0755</fileMode>
+		</fileSet>
+		<fileSet>
+			<directory>target/appassembler/lib</directory>
+			<outputDirectory>lib</outputDirectory>
+		</fileSet>
+		<fileSet>
+			<directory>target</directory>
+			<outputDirectory>lib</outputDirectory>
+			<includes>
+				<include>**/*.jar</include>
+			</includes>
+		</fileSet>
+	</fileSets>
 </assembly>
diff --git a/hivesterix/src/main/java/edu/uci/ics/hivesterix/logical/plan/HiveAlgebricksTranslator.java b/hivesterix/src/main/java/edu/uci/ics/hivesterix/logical/plan/HiveAlgebricksTranslator.java
index 1fb973e..2765e44 100644
--- a/hivesterix/src/main/java/edu/uci/ics/hivesterix/logical/plan/HiveAlgebricksTranslator.java
+++ b/hivesterix/src/main/java/edu/uci/ics/hivesterix/logical/plan/HiveAlgebricksTranslator.java
@@ -80,729 +80,770 @@
 @SuppressWarnings("rawtypes")

 public class HiveAlgebricksTranslator implements Translator {

 

-    private int currentVariable = 0;

+	private int currentVariable = 0;

 

-    private List<Mutable<ILogicalOperator>> logicalOp = new ArrayList<Mutable<ILogicalOperator>>();

+	private List<Mutable<ILogicalOperator>> logicalOp = new ArrayList<Mutable<ILogicalOperator>>();

 

-    private boolean continueTraverse = true;

+	private boolean continueTraverse = true;

 

-    private IMetadataProvider<PartitionDesc, Object> metaData;

+	private IMetadataProvider<PartitionDesc, Object> metaData;

 

-    /**

-     * map variable name to the logical variable

-     */

-    private HashMap<String, LogicalVariable> nameToLogicalVariableMap = new HashMap<String, LogicalVariable>();

+	/**

+	 * map variable name to the logical variable

+	 */

+	private HashMap<String, LogicalVariable> nameToLogicalVariableMap = new HashMap<String, LogicalVariable>();

 

-    /**

-     * map field name to LogicalVariable

-     */

-    private HashMap<String, LogicalVariable> fieldToLogicalVariableMap = new HashMap<String, LogicalVariable>();

+	/**

+	 * map field name to LogicalVariable

+	 */

+	private HashMap<String, LogicalVariable> fieldToLogicalVariableMap = new HashMap<String, LogicalVariable>();

 

-    /**

-     * map logical variable to name

-     */

-    private HashMap<LogicalVariable, String> logicalVariableToFieldMap = new HashMap<LogicalVariable, String>();

+	/**

+	 * map logical variable to name

+	 */

+	private HashMap<LogicalVariable, String> logicalVariableToFieldMap = new HashMap<LogicalVariable, String>();

 

-    /**

-     * asterix root operators

-     */

-    private List<Mutable<ILogicalOperator>> rootOperators = new ArrayList<Mutable<ILogicalOperator>>();

+	/**

+	 * asterix root operators

+	 */

+	private List<Mutable<ILogicalOperator>> rootOperators = new ArrayList<Mutable<ILogicalOperator>>();

 

-    /**

-     * a list of visitors

-     */

-    private List<Visitor> visitors = new ArrayList<Visitor>();

+	/**

+	 * a list of visitors

+	 */

+	private List<Visitor> visitors = new ArrayList<Visitor>();

 

-    /**

-     * output writer to print things out

-     */

-    private static PrintWriter outputWriter = new PrintWriter(new OutputStreamWriter(System.out));

+	/**

+	 * output writer to print things out

+	 */

+	private static PrintWriter outputWriter = new PrintWriter(

+			new OutputStreamWriter(System.out));

 

-    /**

-     * map a logical variable to type info

-     */

-    private HashMap<LogicalVariable, TypeInfo> variableToType = new HashMap<LogicalVariable, TypeInfo>();

+	/**

+	 * map a logical variable to type info

+	 */

+	private HashMap<LogicalVariable, TypeInfo> variableToType = new HashMap<LogicalVariable, TypeInfo>();

 

-    @Override

-    public LogicalVariable getVariable(String fieldName, TypeInfo type) {

-        LogicalVariable var = fieldToLogicalVariableMap.get(fieldName);

-        if (var == null) {

-            currentVariable++;

-            var = new LogicalVariable(currentVariable);

-            fieldToLogicalVariableMap.put(fieldName, var);

-            nameToLogicalVariableMap.put(var.toString(), var);

-            variableToType.put(var, type);

-            logicalVariableToFieldMap.put(var, fieldName);

-        }

-        return var;

-    }

+	@Override

+	public LogicalVariable getVariable(String fieldName, TypeInfo type) {

+		LogicalVariable var = fieldToLogicalVariableMap.get(fieldName);

+		if (var == null) {

+			currentVariable++;

+			var = new LogicalVariable(currentVariable);

+			fieldToLogicalVariableMap.put(fieldName, var);

+			nameToLogicalVariableMap.put(var.toString(), var);

+			variableToType.put(var, type);

+			logicalVariableToFieldMap.put(var, fieldName);

+		}

+		return var;

+	}

 

-    @Override

-    public LogicalVariable getNewVariable(String fieldName, TypeInfo type) {

-        currentVariable++;

-        LogicalVariable var = new LogicalVariable(currentVariable);

-        fieldToLogicalVariableMap.put(fieldName, var);

-        nameToLogicalVariableMap.put(var.toString(), var);

-        variableToType.put(var, type);

-        logicalVariableToFieldMap.put(var, fieldName);

-        return var;

-    }

+	@Override

+	public LogicalVariable getNewVariable(String fieldName, TypeInfo type) {

+		currentVariable++;

+		LogicalVariable var = new LogicalVariable(currentVariable);

+		fieldToLogicalVariableMap.put(fieldName, var);

+		nameToLogicalVariableMap.put(var.toString(), var);

+		variableToType.put(var, type);

+		logicalVariableToFieldMap.put(var, fieldName);

+		return var;

+	}

 

-    @Override

-    public void replaceVariable(LogicalVariable oldVar, LogicalVariable newVar) {

-        String name = this.logicalVariableToFieldMap.get(oldVar);

-        if (name != null) {

-            fieldToLogicalVariableMap.put(name, newVar);

-            nameToLogicalVariableMap.put(newVar.toString(), newVar);

-            nameToLogicalVariableMap.put(oldVar.toString(), newVar);

-            logicalVariableToFieldMap.put(newVar, name);

-        }

-    }

+	@Override

+	public void replaceVariable(LogicalVariable oldVar, LogicalVariable newVar) {

+		String name = this.logicalVariableToFieldMap.get(oldVar);

+		if (name != null) {

+			fieldToLogicalVariableMap.put(name, newVar);

+			nameToLogicalVariableMap.put(newVar.toString(), newVar);

+			nameToLogicalVariableMap.put(oldVar.toString(), newVar);

+			logicalVariableToFieldMap.put(newVar, name);

+		}

+	}

 

-    @Override

-    public IMetadataProvider<PartitionDesc, Object> getMetadataProvider() {

-        return metaData;

-    }

+	@Override

+	public IMetadataProvider<PartitionDesc, Object> getMetadataProvider() {

+		return metaData;

+	}

 

-    /**

-     * only get an variable, without rewriting it

-     * 

-     * @param fieldName

-     * @return

-     */

-    private LogicalVariable getVariableOnly(String fieldName) {

-        return fieldToLogicalVariableMap.get(fieldName);

-    }

+	/**

+	 * only get an variable, without rewriting it

+	 * 

+	 * @param fieldName

+	 * @return

+	 */

+	private LogicalVariable getVariableOnly(String fieldName) {

+		return fieldToLogicalVariableMap.get(fieldName);

+	}

 

-    private void updateVariable(String fieldName, LogicalVariable variable) {

-        LogicalVariable var = fieldToLogicalVariableMap.get(fieldName);

-        if (var == null) {

-            fieldToLogicalVariableMap.put(fieldName, variable);

-            nameToLogicalVariableMap.put(fieldName, variable);

-        } else if (!var.equals(variable)) {

-            // System.out.println("!!!replace variables!!!");

-            fieldToLogicalVariableMap.put(fieldName, variable);

-            nameToLogicalVariableMap.put(fieldName, variable);

-        }

-    }

+	private void updateVariable(String fieldName, LogicalVariable variable) {

+		LogicalVariable var = fieldToLogicalVariableMap.get(fieldName);

+		if (var == null) {

+			fieldToLogicalVariableMap.put(fieldName, variable);

+			nameToLogicalVariableMap.put(fieldName, variable);

+		} else if (!var.equals(variable)) {

+			fieldToLogicalVariableMap.put(fieldName, variable);

+			nameToLogicalVariableMap.put(fieldName, variable);

+		}

+	}

 

-    /**

-     * get a list of logical variables from the schema

-     * 

-     * @param schema

-     * @return

-     */

-    @Override

-    public List<LogicalVariable> getVariablesFromSchema(Schema schema) {

-        List<LogicalVariable> variables = new ArrayList<LogicalVariable>();

-        List<String> names = schema.getNames();

+	/**

+	 * get a list of logical variables from the schema

+	 * 

+	 * @param schema

+	 * @return

+	 */

+	@Override

+	public List<LogicalVariable> getVariablesFromSchema(Schema schema) {

+		List<LogicalVariable> variables = new ArrayList<LogicalVariable>();

+		List<String> names = schema.getNames();

 

-        for (String name : names)

-            variables.add(nameToLogicalVariableMap.get(name));

-        return variables;

-    }

+		for (String name : names)

+			variables.add(nameToLogicalVariableMap.get(name));

+		return variables;

+	}

 

-    /**

-     * get variable to typeinfo map

-     * 

-     * @return

-     */

-    public HashMap<LogicalVariable, TypeInfo> getVariableContext() {

-        return this.variableToType;

-    }

+	/**

+	 * get variable to typeinfo map

+	 * 

+	 * @return

+	 */

+	public HashMap<LogicalVariable, TypeInfo> getVariableContext() {

+		return this.variableToType;

+	}

 

-    /**

-     * get the number of variables

-     * s

-     * 

-     * @return

-     */

-    public int getVariableCounter() {

-        return currentVariable + 1;

-    }

+	/**

+	 * get the number of variables s

+	 * 

+	 * @return

+	 */

+	public int getVariableCounter() {

+		return currentVariable + 1;

+	}

 

-    /**

-     * translate from hive operator tree to asterix operator tree

-     * 

-     * @param hive

-     *            roots

-     * @return Algebricks roots

-     */

-    public void translate(List<Operator> hiveRoot, ILogicalOperator parentOperator,

-            HashMap<String, PartitionDesc> aliasToPathMap) throws AlgebricksException {

-        /**

-         * register visitors

-         */

-        visitors.add(new FilterVisitor());

-        visitors.add(new GroupByVisitor());

-        visitors.add(new JoinVisitor());

-        visitors.add(new LateralViewJoinVisitor());

-        visitors.add(new UnionVisitor());

-        visitors.add(new LimitVisitor());

-        visitors.add(new MapJoinVisitor());

-        visitors.add(new ProjectVisitor());

-        visitors.add(new SortVisitor());

-        visitors.add(new ExtractVisitor());

-        visitors.add(new TableScanWriteVisitor(aliasToPathMap));

+	/**

+	 * translate from hive operator tree to asterix operator tree

+	 * 

+	 * @param hive

+	 *            roots

+	 * @return Algebricks roots

+	 */

+	public void translate(List<Operator> hiveRoot,

+			ILogicalOperator parentOperator,

+			HashMap<String, PartitionDesc> aliasToPathMap)

+			throws AlgebricksException {

+		/**

+		 * register visitors

+		 */

+		visitors.add(new FilterVisitor());

+		visitors.add(new GroupByVisitor());

+		visitors.add(new JoinVisitor());

+		visitors.add(new LateralViewJoinVisitor());

+		visitors.add(new UnionVisitor());

+		visitors.add(new LimitVisitor());

+		visitors.add(new MapJoinVisitor());

+		visitors.add(new ProjectVisitor());

+		visitors.add(new SortVisitor());

+		visitors.add(new ExtractVisitor());

+		visitors.add(new TableScanWriteVisitor(aliasToPathMap));

 

-        List<Mutable<ILogicalOperator>> refList = translate(hiveRoot, new MutableObject<ILogicalOperator>(

-                parentOperator));

-        insertReplicateOperator(refList);

-        if (refList != null)

-            rootOperators.addAll(refList);

-    }

+		List<Mutable<ILogicalOperator>> refList = translate(hiveRoot,

+				new MutableObject<ILogicalOperator>(parentOperator));

+		insertReplicateOperator(refList);

+		if (refList != null)

+			rootOperators.addAll(refList);

+	}

 

-    /**

-     * translate operator DAG

-     * 

-     * @param hiveRoot

-     * @param AlgebricksParentOperator

-     * @return

-     */

-    private List<Mutable<ILogicalOperator>> translate(List<Operator> hiveRoot,

-            Mutable<ILogicalOperator> AlgebricksParentOperator) throws AlgebricksException {

+	/**

+	 * translate operator DAG

+	 * 

+	 * @param hiveRoot

+	 * @param AlgebricksParentOperator

+	 * @return

+	 */

+	private List<Mutable<ILogicalOperator>> translate(List<Operator> hiveRoot,

+			Mutable<ILogicalOperator> AlgebricksParentOperator)

+			throws AlgebricksException {

 

-        for (Operator hiveOperator : hiveRoot) {

-            continueTraverse = true;

-            Mutable<ILogicalOperator> currentOperatorRef = null;

-            if (hiveOperator.getType() == OperatorType.FILTER) {

-                FilterOperator fop = (FilterOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.REDUCESINK) {

-                ReduceSinkOperator fop = (ReduceSinkOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.JOIN) {

-                JoinOperator fop = (JoinOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null) {

-                        continueTraverse = true;

-                        break;

-                    } else

-                        continueTraverse = false;

-                }

-                if (currentOperatorRef == null)

-                    return null;

-            } else if (hiveOperator.getType() == OperatorType.LATERALVIEWJOIN) {

-                LateralViewJoinOperator fop = (LateralViewJoinOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-                if (currentOperatorRef == null)

-                    return null;

-            } else if (hiveOperator.getType() == OperatorType.MAPJOIN) {

-                MapJoinOperator fop = (MapJoinOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null) {

-                        continueTraverse = true;

-                        break;

-                    } else

-                        continueTraverse = false;

-                }

-                if (currentOperatorRef == null)

-                    return null;

-            } else if (hiveOperator.getType() == OperatorType.SELECT) {

-                SelectOperator fop = (SelectOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.EXTRACT) {

-                ExtractOperator fop = (ExtractOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.GROUPBY) {

-                GroupByOperator fop = (GroupByOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.TABLESCAN) {

-                TableScanOperator fop = (TableScanOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.FILESINK) {

-                FileSinkOperator fop = (FileSinkOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(fop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.LIMIT) {

-                LimitOperator lop = (LimitOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(lop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.UDTF) {

-                UDTFOperator lop = (UDTFOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(lop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null)

-                        break;

-                }

-            } else if (hiveOperator.getType() == OperatorType.UNION) {

-                UnionOperator lop = (UnionOperator) hiveOperator;

-                for (Visitor visitor : visitors) {

-                    currentOperatorRef = visitor.visit(lop, AlgebricksParentOperator, this);

-                    if (currentOperatorRef != null) {

-                        continueTraverse = true;

-                        break;

-                    } else

-                        continueTraverse = false;

-                }

-            } else

-                ;

-            if (hiveOperator.getChildOperators() != null && hiveOperator.getChildOperators().size() > 0

-                    && continueTraverse) {

-                @SuppressWarnings("unchecked")

-                List<Operator> children = hiveOperator.getChildOperators();

-                if (currentOperatorRef == null)

-                    currentOperatorRef = AlgebricksParentOperator;

-                translate(children, currentOperatorRef);

-            }

-            if (hiveOperator.getChildOperators() == null || hiveOperator.getChildOperators().size() == 0)

-                logicalOp.add(currentOperatorRef);

-        }

-        return logicalOp;

-    }

+		for (Operator hiveOperator : hiveRoot) {

+			continueTraverse = true;

+			Mutable<ILogicalOperator> currentOperatorRef = null;

+			if (hiveOperator.getType() == OperatorType.FILTER) {

+				FilterOperator fop = (FilterOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.REDUCESINK) {

+				ReduceSinkOperator fop = (ReduceSinkOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.JOIN) {

+				JoinOperator fop = (JoinOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null) {

+						continueTraverse = true;

+						break;

+					} else

+						continueTraverse = false;

+				}

+				if (currentOperatorRef == null)

+					return null;

+			} else if (hiveOperator.getType() == OperatorType.LATERALVIEWJOIN) {

+				LateralViewJoinOperator fop = (LateralViewJoinOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+				if (currentOperatorRef == null)

+					return null;

+			} else if (hiveOperator.getType() == OperatorType.MAPJOIN) {

+				MapJoinOperator fop = (MapJoinOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null) {

+						continueTraverse = true;

+						break;

+					} else

+						continueTraverse = false;

+				}

+				if (currentOperatorRef == null)

+					return null;

+			} else if (hiveOperator.getType() == OperatorType.SELECT) {

+				SelectOperator fop = (SelectOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.EXTRACT) {

+				ExtractOperator fop = (ExtractOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.GROUPBY) {

+				GroupByOperator fop = (GroupByOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.TABLESCAN) {

+				TableScanOperator fop = (TableScanOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.FILESINK) {

+				FileSinkOperator fop = (FileSinkOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(fop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.LIMIT) {

+				LimitOperator lop = (LimitOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(lop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.UDTF) {

+				UDTFOperator lop = (UDTFOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(lop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null)

+						break;

+				}

+			} else if (hiveOperator.getType() == OperatorType.UNION) {

+				UnionOperator lop = (UnionOperator) hiveOperator;

+				for (Visitor visitor : visitors) {

+					currentOperatorRef = visitor.visit(lop,

+							AlgebricksParentOperator, this);

+					if (currentOperatorRef != null) {

+						continueTraverse = true;

+						break;

+					} else

+						continueTraverse = false;

+				}

+			} else

+				;

+			if (hiveOperator.getChildOperators() != null

+					&& hiveOperator.getChildOperators().size() > 0

+					&& continueTraverse) {

+				@SuppressWarnings("unchecked")

+				List<Operator> children = hiveOperator.getChildOperators();

+				if (currentOperatorRef == null)

+					currentOperatorRef = AlgebricksParentOperator;

+				translate(children, currentOperatorRef);

+			}

+			if (hiveOperator.getChildOperators() == null

+					|| hiveOperator.getChildOperators().size() == 0)

+				logicalOp.add(currentOperatorRef);

+		}

+		return logicalOp;

+	}

 

-    /**

-     * used in select, group by to get no-column-expression columns

-     * 

-     * @param cols

-     * @return

-     */

-    public ILogicalOperator getAssignOperator(Mutable<ILogicalOperator> parent, List<ExprNodeDesc> cols,

-            ArrayList<LogicalVariable> variables) {

+	/**

+	 * used in select, group by to get no-column-expression columns

+	 * 

+	 * @param cols

+	 * @return

+	 */

+	public ILogicalOperator getAssignOperator(Mutable<ILogicalOperator> parent,

+			List<ExprNodeDesc> cols, ArrayList<LogicalVariable> variables) {

 

-        ArrayList<Mutable<ILogicalExpression>> expressions = new ArrayList<Mutable<ILogicalExpression>>();

+		ArrayList<Mutable<ILogicalExpression>> expressions = new ArrayList<Mutable<ILogicalExpression>>();

 

-        /**

-         * variables to be appended in the assign operator

-         */

-        ArrayList<LogicalVariable> appendedVariables = new ArrayList<LogicalVariable>();

+		/**

+		 * variables to be appended in the assign operator

+		 */

+		ArrayList<LogicalVariable> appendedVariables = new ArrayList<LogicalVariable>();

 

-        // one variable can only be assigned once

-        for (ExprNodeDesc hiveExpr : cols) {

-            rewriteExpression(hiveExpr);

+		// one variable can only be assigned once

+		for (ExprNodeDesc hiveExpr : cols) {

+			rewriteExpression(hiveExpr);

 

-            if (hiveExpr instanceof ExprNodeColumnDesc) {

-                ExprNodeColumnDesc desc2 = (ExprNodeColumnDesc) hiveExpr;

-                String fieldName = desc2.getTabAlias() + "." + desc2.getColumn();

+			if (hiveExpr instanceof ExprNodeColumnDesc) {

+				ExprNodeColumnDesc desc2 = (ExprNodeColumnDesc) hiveExpr;

+				String fieldName = desc2.getTabAlias() + "."

+						+ desc2.getColumn();

 

-                // System.out.println("project expr: " + fieldName);

+				// System.out.println("project expr: " + fieldName);

 

-                if (fieldName.indexOf("$$") < 0) {

-                    LogicalVariable var = getVariable(fieldName, hiveExpr.getTypeInfo());

-                    desc2.setColumn(var.toString());

-                    desc2.setTabAlias("");

-                    variables.add(var);

-                } else {

-                    LogicalVariable var = nameToLogicalVariableMap.get(desc2.getColumn());

-                    String name = this.logicalVariableToFieldMap.get(var);

-                    var = this.getVariableOnly(name);

-                    variables.add(var);

-                }

-            } else {

-                Mutable<ILogicalExpression> asterixExpr = translateScalarFucntion(hiveExpr);

-                expressions.add(asterixExpr);

-                LogicalVariable var = getVariable(hiveExpr.getExprString() + asterixExpr.hashCode(),

-                        hiveExpr.getTypeInfo());

-                variables.add(var);

-                appendedVariables.add(var);

-            }

-        }

+				if (fieldName.indexOf("$$") < 0) {

+					LogicalVariable var = getVariable(fieldName,

+							hiveExpr.getTypeInfo());

+					desc2.setColumn(var.toString());

+					desc2.setTabAlias("");

+					variables.add(var);

+				} else {

+					LogicalVariable var = nameToLogicalVariableMap.get(desc2

+							.getColumn());

+					String name = this.logicalVariableToFieldMap.get(var);

+					var = this.getVariableOnly(name);

+					variables.add(var);

+				}

+			} else {

+				Mutable<ILogicalExpression> asterixExpr = translateScalarFucntion(hiveExpr);

+				expressions.add(asterixExpr);

+				LogicalVariable var = getVariable(hiveExpr.getExprString()

+						+ asterixExpr.hashCode(), hiveExpr.getTypeInfo());

+				variables.add(var);

+				appendedVariables.add(var);

+			}

+		}

 

-        /**

-         * create an assign operator to deal with appending

-         */

-        ILogicalOperator assignOp = null;

-        if (appendedVariables.size() > 0) {

-            assignOp = new AssignOperator(appendedVariables, expressions);

-            assignOp.getInputs().add(parent);

-        }

-        return assignOp;

-    }

+		/**

+		 * create an assign operator to deal with appending

+		 */

+		ILogicalOperator assignOp = null;

+		if (appendedVariables.size() > 0) {

+			assignOp = new AssignOperator(appendedVariables, expressions);

+			assignOp.getInputs().add(parent);

+		}

+		return assignOp;

+	}

 

-    private ILogicalPlan plan;

+	private ILogicalPlan plan;

 

-    public ILogicalPlan genLogicalPlan() {

-        plan = new ALogicalPlanImpl(rootOperators);

-        return plan;

-    }

+	public ILogicalPlan genLogicalPlan() {

+		plan = new ALogicalPlanImpl(rootOperators);

+		return plan;

+	}

 

-    public void printOperators() throws AlgebricksException {

-        LogicalOperatorPrettyPrintVisitor pvisitor = new LogicalOperatorPrettyPrintVisitor();

-        StringBuilder buffer = new StringBuilder();

-        PlanPrettyPrinter.printPlan(plan, buffer, pvisitor, 0);

-        outputWriter.println(buffer);

-        outputWriter.println("rewritten variables: ");

-        outputWriter.flush();

-        printVariables();

+	public void printOperators() throws AlgebricksException {

+		LogicalOperatorPrettyPrintVisitor pvisitor = new LogicalOperatorPrettyPrintVisitor();

+		StringBuilder buffer = new StringBuilder();

+		PlanPrettyPrinter.printPlan(plan, buffer, pvisitor, 0);

+		outputWriter.println(buffer);

+		outputWriter.println("rewritten variables: ");

+		outputWriter.flush();

+		printVariables();

 

-    }

+	}

 

-    public static void setOutputPrinter(PrintWriter writer) {

-        outputWriter = writer;

-    }

+	public static void setOutputPrinter(PrintWriter writer) {

+		outputWriter = writer;

+	}

 

-    private void printVariables() {

-        Set<Entry<String, LogicalVariable>> entries = fieldToLogicalVariableMap.entrySet();

+	private void printVariables() {

+		Set<Entry<String, LogicalVariable>> entries = fieldToLogicalVariableMap

+				.entrySet();

 

-        for (Entry<String, LogicalVariable> entry : entries) {

-            outputWriter.println(entry.getKey() + " -> " + entry.getValue());

-        }

-        outputWriter.flush();

-    }

+		for (Entry<String, LogicalVariable> entry : entries) {

+			outputWriter.println(entry.getKey() + " -> " + entry.getValue());

+		}

+		outputWriter.flush();

+	}

 

-    /**

-     * generate the object inspector for the output of an operator

-     * 

-     * @param operator

-     *            The Hive operator

-     * @return an ObjectInspector object

-     */

-    public Schema generateInputSchema(Operator operator) {

-        List<String> variableNames = new ArrayList<String>();

-        List<TypeInfo> typeList = new ArrayList<TypeInfo>();

-        List<ColumnInfo> columns = operator.getSchema().getSignature();

+	/**

+	 * generate the object inspector for the output of an operator

+	 * 

+	 * @param operator

+	 *            The Hive operator

+	 * @return an ObjectInspector object

+	 */

+	public Schema generateInputSchema(Operator operator) {

+		List<String> variableNames = new ArrayList<String>();

+		List<TypeInfo> typeList = new ArrayList<TypeInfo>();

+		List<ColumnInfo> columns = operator.getSchema().getSignature();

 

-        for (ColumnInfo col : columns) {

-            // typeList.add();

-            TypeInfo type = col.getType();

-            typeList.add(type);

+		for (ColumnInfo col : columns) {

+			// typeList.add();

+			TypeInfo type = col.getType();

+			typeList.add(type);

 

-            String fieldName = col.getInternalName();

-            variableNames.add(fieldName);

-        }

+			String fieldName = col.getInternalName();

+			variableNames.add(fieldName);

+		}

 

-        return new Schema(variableNames, typeList);

-    }

+		return new Schema(variableNames, typeList);

+	}

 

-    /**

-     * rewrite the names of output columns for feature expression evaluators to

-     * use

-     * 

-     * @param operator

-     */

-    public void rewriteOperatorOutputSchema(Operator operator) {

-        List<ColumnInfo> columns = operator.getSchema().getSignature();

+	/**

+	 * rewrite the names of output columns for feature expression evaluators to

+	 * use

+	 * 

+	 * @param operator

+	 */

+	public void rewriteOperatorOutputSchema(Operator operator) {

+		List<ColumnInfo> columns = operator.getSchema().getSignature();

 

-        for (ColumnInfo column : columns) {

-            String columnName = column.getTabAlias() + "." + column.getInternalName();

-            if (columnName.indexOf("$$") < 0) {

-                LogicalVariable var = getVariable(columnName, column.getType());

-                column.setInternalName(var.toString());

-            }

-        }

-    }

+		for (ColumnInfo column : columns) {

+			String columnName = column.getTabAlias() + "."

+					+ column.getInternalName();

+			if (columnName.indexOf("$$") < 0) {

+				LogicalVariable var = getVariable(columnName, column.getType());

+				column.setInternalName(var.toString());

+			}

+		}

+	}

 

-    @Override

-    public void rewriteOperatorOutputSchema(List<LogicalVariable> variables, Operator operator) {

+	@Override

+	public void rewriteOperatorOutputSchema(List<LogicalVariable> variables,

+			Operator operator) {

 

-        printOperatorSchema(operator);

-        List<ColumnInfo> columns = operator.getSchema().getSignature();

-        if (variables.size() != columns.size()) {

-            throw new IllegalStateException("output cardinality error " + operator.getName() + " variable size: "

-                    + variables.size() + " expected " + columns.size());

-        }

+		//printOperatorSchema(operator);

+		List<ColumnInfo> columns = operator.getSchema().getSignature();

+		if (variables.size() != columns.size()) {

+			throw new IllegalStateException("output cardinality error "

+					+ operator.getName() + " variable size: "

+					+ variables.size() + " expected " + columns.size());

+		}

 

-        for (int i = 0; i < variables.size(); i++) {

-            LogicalVariable var = variables.get(i);

-            ColumnInfo column = columns.get(i);

-            String fieldName = column.getTabAlias() + "." + column.getInternalName();

-            if (fieldName.indexOf("$$") < 0) {

-                updateVariable(fieldName, var);

-                column.setInternalName(var.toString());

-            }

-        }

-        printOperatorSchema(operator);

-    }

+		for (int i = 0; i < variables.size(); i++) {

+			LogicalVariable var = variables.get(i);

+			ColumnInfo column = columns.get(i);

+			String fieldName = column.getTabAlias() + "."

+					+ column.getInternalName();

+			if (fieldName.indexOf("$$") < 0) {

+				updateVariable(fieldName, var);

+				column.setInternalName(var.toString());

+			}

+		}

+		//printOperatorSchema(operator);

+	}

 

-    /**

-     * rewrite an expression and substitute variables

-     * 

-     * @param expr

-     *            hive expression

-     */

-    public void rewriteExpression(ExprNodeDesc expr) {

-        if (expr instanceof ExprNodeColumnDesc) {

-            ExprNodeColumnDesc desc = (ExprNodeColumnDesc) expr;

-            String fieldName = desc.getTabAlias() + "." + desc.getColumn();

-            if (fieldName.indexOf("$$") < 0) {

-                LogicalVariable var = getVariableOnly(fieldName);

-                if (var == null) {

-                    fieldName = "." + desc.getColumn();

-                    var = getVariableOnly(fieldName);

-                    if (var == null) {

-                        fieldName = "null." + desc.getColumn();

-                        var = getVariableOnly(fieldName);

-                        if (var == null) {

-                            throw new IllegalStateException(fieldName + " is wrong!!! ");

-                        }

-                    }

-                }

-                String name = this.logicalVariableToFieldMap.get(var);

-                var = getVariableOnly(name);

-                desc.setColumn(var.toString());

-            }

-        } else {

-            if (expr.getChildren() != null && expr.getChildren().size() > 0) {

-                List<ExprNodeDesc> children = expr.getChildren();

-                for (ExprNodeDesc desc : children)

-                    rewriteExpression(desc);

-            }

-        }

-    }

+	/**

+	 * rewrite an expression and substitute variables

+	 * 

+	 * @param expr

+	 *            hive expression

+	 */

+	public void rewriteExpression(ExprNodeDesc expr) {

+		if (expr instanceof ExprNodeColumnDesc) {

+			ExprNodeColumnDesc desc = (ExprNodeColumnDesc) expr;

+			String fieldName = desc.getTabAlias() + "." + desc.getColumn();

+			if (fieldName.indexOf("$$") < 0) {

+				LogicalVariable var = getVariableOnly(fieldName);

+				if (var == null) {

+					fieldName = "." + desc.getColumn();

+					var = getVariableOnly(fieldName);

+					if (var == null) {

+						fieldName = "null." + desc.getColumn();

+						var = getVariableOnly(fieldName);

+						if (var == null) {

+							throw new IllegalStateException(fieldName

+									+ " is wrong!!! ");

+						}

+					}

+				}

+				String name = this.logicalVariableToFieldMap.get(var);

+				var = getVariableOnly(name);

+				desc.setColumn(var.toString());

+			}

+		} else {

+			if (expr.getChildren() != null && expr.getChildren().size() > 0) {

+				List<ExprNodeDesc> children = expr.getChildren();

+				for (ExprNodeDesc desc : children)

+					rewriteExpression(desc);

+			}

+		}

+	}

 

-    /**

-     * rewrite an expression and substitute variables

-     * 

-     * @param expr

-     *            hive expression

-     */

-    public void rewriteExpressionPartial(ExprNodeDesc expr) {

-        if (expr instanceof ExprNodeColumnDesc) {

-            ExprNodeColumnDesc desc = (ExprNodeColumnDesc) expr;

-            String fieldName = desc.getTabAlias() + "." + desc.getColumn();

-            if (fieldName.indexOf("$$") < 0) {

-                LogicalVariable var = getVariableOnly(fieldName);

-                desc.setColumn(var.toString());

-            }

-        } else {

-            if (expr.getChildren() != null && expr.getChildren().size() > 0) {

-                List<ExprNodeDesc> children = expr.getChildren();

-                for (ExprNodeDesc desc : children)

-                    rewriteExpressionPartial(desc);

-            }

-        }

-    }

+	/**

+	 * rewrite an expression and substitute variables

+	 * 

+	 * @param expr

+	 *            hive expression

+	 */

+	public void rewriteExpressionPartial(ExprNodeDesc expr) {

+		if (expr instanceof ExprNodeColumnDesc) {

+			ExprNodeColumnDesc desc = (ExprNodeColumnDesc) expr;

+			String fieldName = desc.getTabAlias() + "." + desc.getColumn();

+			if (fieldName.indexOf("$$") < 0) {

+				LogicalVariable var = getVariableOnly(fieldName);

+				desc.setColumn(var.toString());

+			}

+		} else {

+			if (expr.getChildren() != null && expr.getChildren().size() > 0) {

+				List<ExprNodeDesc> children = expr.getChildren();

+				for (ExprNodeDesc desc : children)

+					rewriteExpressionPartial(desc);

+			}

+		}

+	}

 

-    private void printOperatorSchema(Operator operator) {

-        System.out.println(operator.getName());

-        List<ColumnInfo> columns = operator.getSchema().getSignature();

-        for (ColumnInfo column : columns) {

-            System.out.print(column.getTabAlias() + "." + column.getInternalName() + "  ");

-        }

-        System.out.println();

-    }

+	// private void printOperatorSchema(Operator operator) {

+	// // System.out.println(operator.getName());

+	// // List<ColumnInfo> columns = operator.getSchema().getSignature();

+	// // for (ColumnInfo column : columns) {

+	// // System.out.print(column.getTabAlias() + "." +

+	// // column.getInternalName() + "  ");

+	// // }

+	// // System.out.println();

+	// }

 

-    /**

-     * translate scalar function expression

-     * 

-     * @param hiveExpr

-     * @return

-     */

-    public Mutable<ILogicalExpression> translateScalarFucntion(ExprNodeDesc hiveExpr) {

-        ILogicalExpression AlgebricksExpr;

+	/**

+	 * translate scalar function expression

+	 * 

+	 * @param hiveExpr

+	 * @return

+	 */

+	public Mutable<ILogicalExpression> translateScalarFucntion(

+			ExprNodeDesc hiveExpr) {

+		ILogicalExpression AlgebricksExpr;

 

-        if (hiveExpr instanceof ExprNodeGenericFuncDesc) {

-            List<Mutable<ILogicalExpression>> arguments = new ArrayList<Mutable<ILogicalExpression>>();

-            List<ExprNodeDesc> children = hiveExpr.getChildren();

+		if (hiveExpr instanceof ExprNodeGenericFuncDesc) {

+			List<Mutable<ILogicalExpression>> arguments = new ArrayList<Mutable<ILogicalExpression>>();

+			List<ExprNodeDesc> children = hiveExpr.getChildren();

 

-            for (ExprNodeDesc child : children)

-                arguments.add(translateScalarFucntion(child));

+			for (ExprNodeDesc child : children)

+				arguments.add(translateScalarFucntion(child));

 

-            ExprNodeGenericFuncDesc funcExpr = (ExprNodeGenericFuncDesc) hiveExpr;

-            GenericUDF genericUdf = funcExpr.getGenericUDF();

-            UDF udf = null;

-            if (genericUdf instanceof GenericUDFBridge) {

-                GenericUDFBridge bridge = (GenericUDFBridge) genericUdf;

-                try {

-                    udf = bridge.getUdfClass().newInstance();

-                } catch (Exception e) {

-                    e.printStackTrace();

-                }

-            }

+			ExprNodeGenericFuncDesc funcExpr = (ExprNodeGenericFuncDesc) hiveExpr;

+			GenericUDF genericUdf = funcExpr.getGenericUDF();

+			UDF udf = null;

+			if (genericUdf instanceof GenericUDFBridge) {

+				GenericUDFBridge bridge = (GenericUDFBridge) genericUdf;

+				try {

+					udf = bridge.getUdfClass().newInstance();

+				} catch (Exception e) {

+					e.printStackTrace();

+				}

+			}

 

-            /**

-             * set up the hive function

-             */

-            Object hiveFunction = genericUdf;

-            if (udf != null)

-                hiveFunction = udf;

+			/**

+			 * set up the hive function

+			 */

+			Object hiveFunction = genericUdf;

+			if (udf != null)

+				hiveFunction = udf;

 

-            FunctionIdentifier funcId = HiveAlgebricksBuiltInFunctionMap.INSTANCE.getAlgebricksFunctionId(hiveFunction

-                    .getClass());

-            if (funcId == null) {

-                funcId = new FunctionIdentifier(ExpressionConstant.NAMESPACE, hiveFunction.getClass().getName());

-            }

+			FunctionIdentifier funcId = HiveAlgebricksBuiltInFunctionMap.INSTANCE

+					.getAlgebricksFunctionId(hiveFunction.getClass());

+			if (funcId == null) {

+				funcId = new FunctionIdentifier(ExpressionConstant.NAMESPACE,

+						hiveFunction.getClass().getName());

+			}

 

-            Object functionInfo = null;

-            if (genericUdf instanceof GenericUDFBridge) {

-                functionInfo = funcExpr;

-            }

+			Object functionInfo = null;

+			if (genericUdf instanceof GenericUDFBridge) {

+				functionInfo = funcExpr;

+			}

 

-            /**

-             * generate the function call expression

-             */

-            ScalarFunctionCallExpression AlgebricksFuncExpr = new ScalarFunctionCallExpression(new HiveFunctionInfo(

-                    funcId, functionInfo), arguments);

-            AlgebricksExpr = AlgebricksFuncExpr;

+			/**

+			 * generate the function call expression

+			 */

+			ScalarFunctionCallExpression AlgebricksFuncExpr = new ScalarFunctionCallExpression(

+					new HiveFunctionInfo(funcId, functionInfo), arguments);

+			AlgebricksExpr = AlgebricksFuncExpr;

 

-        } else if (hiveExpr instanceof ExprNodeColumnDesc) {

-            ExprNodeColumnDesc column = (ExprNodeColumnDesc) hiveExpr;

-            LogicalVariable var = this.getVariable(column.getColumn());

-            AlgebricksExpr = new VariableReferenceExpression(var);

+		} else if (hiveExpr instanceof ExprNodeColumnDesc) {

+			ExprNodeColumnDesc column = (ExprNodeColumnDesc) hiveExpr;

+			LogicalVariable var = this.getVariable(column.getColumn());

+			AlgebricksExpr = new VariableReferenceExpression(var);

 

-        } else if (hiveExpr instanceof ExprNodeFieldDesc) {

-            FunctionIdentifier funcId;

-            funcId = new FunctionIdentifier(ExpressionConstant.NAMESPACE, ExpressionConstant.FIELDACCESS);

+		} else if (hiveExpr instanceof ExprNodeFieldDesc) {

+			FunctionIdentifier funcId;

+			funcId = new FunctionIdentifier(ExpressionConstant.NAMESPACE,

+					ExpressionConstant.FIELDACCESS);

 

-            ScalarFunctionCallExpression AlgebricksFuncExpr = new ScalarFunctionCallExpression(new HiveFunctionInfo(

-                    funcId, hiveExpr));

-            AlgebricksExpr = AlgebricksFuncExpr;

-        } else if (hiveExpr instanceof ExprNodeConstantDesc) {

-            ExprNodeConstantDesc hiveConst = (ExprNodeConstantDesc) hiveExpr;

-            Object value = hiveConst.getValue();

-            AlgebricksExpr = new ConstantExpression(new HivesterixConstantValue(value));

-        } else if (hiveExpr instanceof ExprNodeNullDesc) {

-            FunctionIdentifier funcId;

-            funcId = new FunctionIdentifier(ExpressionConstant.NAMESPACE, ExpressionConstant.NULL);

+			ScalarFunctionCallExpression AlgebricksFuncExpr = new ScalarFunctionCallExpression(

+					new HiveFunctionInfo(funcId, hiveExpr));

+			AlgebricksExpr = AlgebricksFuncExpr;

+		} else if (hiveExpr instanceof ExprNodeConstantDesc) {

+			ExprNodeConstantDesc hiveConst = (ExprNodeConstantDesc) hiveExpr;

+			Object value = hiveConst.getValue();

+			AlgebricksExpr = new ConstantExpression(

+					new HivesterixConstantValue(value));

+		} else if (hiveExpr instanceof ExprNodeNullDesc) {

+			FunctionIdentifier funcId;

+			funcId = new FunctionIdentifier(ExpressionConstant.NAMESPACE,

+					ExpressionConstant.NULL);

 

-            ScalarFunctionCallExpression AlgebricksFuncExpr = new ScalarFunctionCallExpression(new HiveFunctionInfo(

-                    funcId, hiveExpr));

+			ScalarFunctionCallExpression AlgebricksFuncExpr = new ScalarFunctionCallExpression(

+					new HiveFunctionInfo(funcId, hiveExpr));

 

-            AlgebricksExpr = AlgebricksFuncExpr;

-        } else {

-            throw new IllegalStateException("unknown hive expression");

-        }

-        return new MutableObject<ILogicalExpression>(AlgebricksExpr);

-    }

+			AlgebricksExpr = AlgebricksFuncExpr;

+		} else {

+			throw new IllegalStateException("unknown hive expression");

+		}

+		return new MutableObject<ILogicalExpression>(AlgebricksExpr);

+	}

 

-    /**

-     * translate aggregation function expression

-     * 

-     * @param aggregateDesc

-     * @return

-     */

-    public Mutable<ILogicalExpression> translateAggregation(AggregationDesc aggregateDesc) {

+	/**

+	 * translate aggregation function expression

+	 * 

+	 * @param aggregateDesc

+	 * @return

+	 */

+	public Mutable<ILogicalExpression> translateAggregation(

+			AggregationDesc aggregateDesc) {

 

-        String UDAFName = aggregateDesc.getGenericUDAFName();

+		String UDAFName = aggregateDesc.getGenericUDAFName();

 

-        List<Mutable<ILogicalExpression>> arguments = new ArrayList<Mutable<ILogicalExpression>>();

-        List<ExprNodeDesc> children = aggregateDesc.getParameters();

+		List<Mutable<ILogicalExpression>> arguments = new ArrayList<Mutable<ILogicalExpression>>();

+		List<ExprNodeDesc> children = aggregateDesc.getParameters();

 

-        for (ExprNodeDesc child : children)

-            arguments.add(translateScalarFucntion(child));

+		for (ExprNodeDesc child : children)

+			arguments.add(translateScalarFucntion(child));

 

-        FunctionIdentifier funcId = new FunctionIdentifier(ExpressionConstant.NAMESPACE, UDAFName + "("

-                + aggregateDesc.getMode() + ")");

-        HiveFunctionInfo funcInfo = new HiveFunctionInfo(funcId, aggregateDesc);

-        AggregateFunctionCallExpression aggregationExpression = new AggregateFunctionCallExpression(funcInfo, false,

-                arguments);

-        return new MutableObject<ILogicalExpression>(aggregationExpression);

-    }

+		FunctionIdentifier funcId = new FunctionIdentifier(

+				ExpressionConstant.NAMESPACE, UDAFName + "("

+						+ aggregateDesc.getMode() + ")");

+		HiveFunctionInfo funcInfo = new HiveFunctionInfo(funcId, aggregateDesc);

+		AggregateFunctionCallExpression aggregationExpression = new AggregateFunctionCallExpression(

+				funcInfo, false, arguments);

+		return new MutableObject<ILogicalExpression>(aggregationExpression);

+	}

 

-    /**

-     * translate aggregation function expression

-     * 

-     * @param aggregator

-     * @return

-     */

-    public Mutable<ILogicalExpression> translateUnnestFunction(UDTFDesc udtfDesc, Mutable<ILogicalExpression> argument) {

+	/**

+	 * translate aggregation function expression

+	 * 

+	 * @param aggregator

+	 * @return

+	 */

+	public Mutable<ILogicalExpression> translateUnnestFunction(

+			UDTFDesc udtfDesc, Mutable<ILogicalExpression> argument) {

 

-        String UDTFName = udtfDesc.getUDTFName();

+		String UDTFName = udtfDesc.getUDTFName();

 

-        FunctionIdentifier funcId = new FunctionIdentifier(ExpressionConstant.NAMESPACE, UDTFName);

-        UnnestingFunctionCallExpression unnestingExpression = new UnnestingFunctionCallExpression(new HiveFunctionInfo(

-                funcId, udtfDesc));

-        unnestingExpression.getArguments().add(argument);

-        return new MutableObject<ILogicalExpression>(unnestingExpression);

-    }

+		FunctionIdentifier funcId = new FunctionIdentifier(

+				ExpressionConstant.NAMESPACE, UDTFName);

+		UnnestingFunctionCallExpression unnestingExpression = new UnnestingFunctionCallExpression(

+				new HiveFunctionInfo(funcId, udtfDesc));

+		unnestingExpression.getArguments().add(argument);

+		return new MutableObject<ILogicalExpression>(unnestingExpression);

+	}

 

-    /**

-     * get typeinfo

-     */

-    @Override

-    public TypeInfo getType(LogicalVariable var) {

-        return variableToType.get(var);

-    }

+	/**

+	 * get typeinfo

+	 */

+	@Override

+	public TypeInfo getType(LogicalVariable var) {

+		return variableToType.get(var);

+	}

 

-    /**

-     * get variable from variable name

-     */

-    @Override

-    public LogicalVariable getVariable(String name) {

-        return nameToLogicalVariableMap.get(name);

-    }

+	/**

+	 * get variable from variable name

+	 */

+	@Override

+	public LogicalVariable getVariable(String name) {

+		return nameToLogicalVariableMap.get(name);

+	}

 

-    @Override

-    public LogicalVariable getVariableFromFieldName(String fieldName) {

-        return this.getVariableOnly(fieldName);

-    }

+	@Override

+	public LogicalVariable getVariableFromFieldName(String fieldName) {

+		return this.getVariableOnly(fieldName);

+	}

 

-    /**

-     * set the metadata provider

-     */

-    @Override

-    public void setMetadataProvider(IMetadataProvider<PartitionDesc, Object> metadata) {

-        this.metaData = metadata;

-    }

+	/**

+	 * set the metadata provider

+	 */

+	@Override

+	public void setMetadataProvider(

+			IMetadataProvider<PartitionDesc, Object> metadata) {

+		this.metaData = metadata;

+	}

 

-    /**

-     * insert ReplicateOperator when necessary

-     */

-    private void insertReplicateOperator(List<Mutable<ILogicalOperator>> roots) {

-        Map<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> childToParentsMap = new HashMap<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>>();

-        buildChildToParentsMapping(roots, childToParentsMap);

-        for (Entry<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> entry : childToParentsMap.entrySet()) {

-            List<Mutable<ILogicalOperator>> pList = entry.getValue();

-            if (pList.size() > 1) {

-                ILogicalOperator rop = new ReplicateOperator(pList.size());

-                Mutable<ILogicalOperator> ropRef = new MutableObject<ILogicalOperator>(rop);

-                Mutable<ILogicalOperator> childRef = entry.getKey();

-                rop.getInputs().add(childRef);

-                for (Mutable<ILogicalOperator> parentRef : pList) {

-                    ILogicalOperator parentOp = parentRef.getValue();

-                    int index = parentOp.getInputs().indexOf(childRef);

-                    parentOp.getInputs().set(index, ropRef);

-                }

-            }

-        }

-    }

+	/**

+	 * insert ReplicateOperator when necessary

+	 */

+	private void insertReplicateOperator(List<Mutable<ILogicalOperator>> roots) {

+		Map<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> childToParentsMap = new HashMap<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>>();

+		buildChildToParentsMapping(roots, childToParentsMap);

+		for (Entry<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> entry : childToParentsMap

+				.entrySet()) {

+			List<Mutable<ILogicalOperator>> pList = entry.getValue();

+			if (pList.size() > 1) {

+				ILogicalOperator rop = new ReplicateOperator(pList.size());

+				Mutable<ILogicalOperator> ropRef = new MutableObject<ILogicalOperator>(

+						rop);

+				Mutable<ILogicalOperator> childRef = entry.getKey();

+				rop.getInputs().add(childRef);

+				for (Mutable<ILogicalOperator> parentRef : pList) {

+					ILogicalOperator parentOp = parentRef.getValue();

+					int index = parentOp.getInputs().indexOf(childRef);

+					parentOp.getInputs().set(index, ropRef);

+				}

+			}

+		}

+	}

 

-    /**

-     * build the mapping from child to Parents

-     * 

-     * @param roots

-     * @param childToParentsMap

-     */

-    private void buildChildToParentsMapping(List<Mutable<ILogicalOperator>> roots,

-            Map<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> map) {

-        for (Mutable<ILogicalOperator> opRef : roots) {

-            List<Mutable<ILogicalOperator>> childRefs = opRef.getValue().getInputs();

-            for (Mutable<ILogicalOperator> childRef : childRefs) {

-                List<Mutable<ILogicalOperator>> parentList = map.get(childRef);

-                if (parentList == null) {

-                    parentList = new ArrayList<Mutable<ILogicalOperator>>();

-                    map.put(childRef, parentList);

-                }

-                if (!parentList.contains(opRef))

-                    parentList.add(opRef);

-            }

-            buildChildToParentsMapping(childRefs, map);

-        }

-    }

+	/**

+	 * build the mapping from child to Parents

+	 * 

+	 * @param roots

+	 * @param childToParentsMap

+	 */

+	private void buildChildToParentsMapping(

+			List<Mutable<ILogicalOperator>> roots,

+			Map<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> map) {

+		for (Mutable<ILogicalOperator> opRef : roots) {

+			List<Mutable<ILogicalOperator>> childRefs = opRef.getValue()

+					.getInputs();

+			for (Mutable<ILogicalOperator> childRef : childRefs) {

+				List<Mutable<ILogicalOperator>> parentList = map.get(childRef);

+				if (parentList == null) {

+					parentList = new ArrayList<Mutable<ILogicalOperator>>();

+					map.put(childRef, parentList);

+				}

+				if (!parentList.contains(opRef))

+					parentList.add(opRef);

+			}

+			buildChildToParentsMapping(childRefs, map);

+		}

+	}

 }

diff --git a/hivesterix/src/main/java/edu/uci/ics/hivesterix/runtime/exec/HyracksExecutionEngine.java b/hivesterix/src/main/java/edu/uci/ics/hivesterix/runtime/exec/HyracksExecutionEngine.java
index 6c1ac72..ed5ab70 100644
--- a/hivesterix/src/main/java/edu/uci/ics/hivesterix/runtime/exec/HyracksExecutionEngine.java
+++ b/hivesterix/src/main/java/edu/uci/ics/hivesterix/runtime/exec/HyracksExecutionEngine.java
@@ -74,8 +74,6 @@
 

     private static final Log LOG = LogFactory.getLog(HyracksExecutionEngine.class.getName());

 

-    // private static final String[] locConstraints = {}

-

     private static List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> DEFAULT_LOGICAL_REWRITES = new ArrayList<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>>();

     private static List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> DEFAULT_PHYSICAL_REWRITES = new ArrayList<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>>();

     static {

@@ -273,7 +271,6 @@
              * list of map-reduce tasks

              */

             Task<? extends Serializable> task = rootTasks.get(i);

-            // System.out.println("!" + task.getName());

 

             if (task instanceof MapRedTask) {

                 List<Operator> mapRootOps = articulateMapReduceOperators(task, rootOps, aliasToPath, rootTasks);

diff --git a/hivesterix/src/main/java/edu/uci/ics/hivesterix/runtime/operator/filescan/HiveFileScanOperatorDescriptor.java b/hivesterix/src/main/java/edu/uci/ics/hivesterix/runtime/operator/filescan/HiveFileScanOperatorDescriptor.java
index d248486..9e62c73 100644
--- a/hivesterix/src/main/java/edu/uci/ics/hivesterix/runtime/operator/filescan/HiveFileScanOperatorDescriptor.java
+++ b/hivesterix/src/main/java/edu/uci/ics/hivesterix/runtime/operator/filescan/HiveFileScanOperatorDescriptor.java
@@ -110,7 +110,7 @@
 			if (returnedSplits[i] != null)
 				splits[i] = returnedSplits[i];
 
-		System.out.println("!!! number of splits: " + splits.length);
+		System.out.println("number of splits: " + splits.length);
 		constraintsByHostNames = new String[splits.length];
 		for (int i = 0; i < splits.length; i++) {
 			try {