tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [1/2] tajo git commit: TAJO-1946: Change Projectable::setTargets and getTargets to set and get List<Target>.
Date Wed, 18 Nov 2015 06:22:59 GMT
Repository: tajo
Updated Branches:
  refs/heads/master 4fd1739d4 -> a2a5c14e4


http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ProjectionNode.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ProjectionNode.java b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ProjectionNode.java
index ef6734e..35ca47f 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ProjectionNode.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ProjectionNode.java
@@ -18,29 +18,30 @@
 
 package org.apache.tajo.plan.logical;
 
-import java.util.Arrays;
-
 import com.google.gson.annotations.Expose;
-
 import org.apache.tajo.plan.PlanString;
-import org.apache.tajo.plan.util.PlannerUtil;
 import org.apache.tajo.plan.Target;
+import org.apache.tajo.plan.util.PlannerUtil;
 import org.apache.tajo.util.StringUtils;
 import org.apache.tajo.util.TUtil;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
 public class ProjectionNode extends UnaryNode implements Projectable {
 
   @Expose private boolean distinct = false;
   /**
    * the targets are always filled even if the query is 'select *'
    */
-  @Expose	private Target [] targets;
+  @Expose	private List<Target> targets = null;
 
 	public ProjectionNode(int pid) {
 		super(pid, NodeType.PROJECTION);
 	}
 
-  public void init(boolean distinct, Target [] targets) {
+  public void init(boolean distinct, List<Target> targets) {
     this.distinct = distinct;
     this.targets = targets;
   }
@@ -54,13 +55,13 @@ public class ProjectionNode extends UnaryNode implements Projectable {
   }
 
   @Override
-  public void setTargets(Target[] targets) {
+  public void setTargets(List<Target> targets) {
     this.targets = targets;
     this.setOutSchema(PlannerUtil.targetToSchema(targets));
   }
 
   @Override
-  public Target [] getTargets() {
+  public List<Target> getTargets() {
     return this.targets;
   }
 	
@@ -81,7 +82,7 @@ public class ProjectionNode extends UnaryNode implements Projectable {
     final int prime = 31;
     int result = 1;
     result = prime * result + (distinct ? 1231 : 1237);
-    result = prime * result + Arrays.hashCode(targets);
+    result = prime * result + Objects.hashCode(targets);
     return result;
   }
 
@@ -101,7 +102,10 @@ public class ProjectionNode extends UnaryNode implements Projectable
{
 	@Override
   public Object clone() throws CloneNotSupportedException {
 	  ProjectionNode projNode = (ProjectionNode) super.clone();
-	  projNode.targets = targets.clone();
+      projNode.targets = new ArrayList<>();
+      for (Target t : targets) {
+        projNode.targets.add((Target) t.clone());
+      }
 	  
 	  return projNode;
 	}
@@ -117,9 +121,9 @@ public class ProjectionNode extends UnaryNode implements Projectable {
 
     StringBuilder sb = new StringBuilder("Targets: ");
     if (targets != null) {
-      for (int i = 0; i < targets.length; i++) {
-        sb.append(targets[i]);
-        if (i < targets.length - 1) {
+      for (int i = 0; i < targets.size(); i++) {
+        sb.append(targets.get(i));
+        if (i < targets.size() - 1) {
           sb.append(", ");
         }
       }

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ScanNode.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ScanNode.java b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ScanNode.java
index 4b8a9e9..3de8c1d 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ScanNode.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/ScanNode.java
@@ -23,20 +23,23 @@ import com.google.common.base.Preconditions;
 import com.google.gson.annotations.Expose;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.catalog.SchemaUtil;
 import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.plan.PlanString;
-import org.apache.tajo.plan.util.PlannerUtil;
-import org.apache.tajo.catalog.SchemaUtil;
 import org.apache.tajo.plan.Target;
 import org.apache.tajo.plan.expr.EvalNode;
+import org.apache.tajo.plan.util.PlannerUtil;
 import org.apache.tajo.util.TUtil;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class ScanNode extends RelationNode implements Projectable, SelectableNode, Cloneable
{
 	@Expose protected TableDesc tableDesc;
   @Expose protected String alias;
   @Expose protected Schema logicalSchema;
 	@Expose protected EvalNode qual;
-	@Expose protected Target[] targets;
+	@Expose protected List<Target> targets = null;
   @Expose protected boolean broadcastTable;
   @Expose protected long limit = -1; // -1 means no set
 
@@ -142,15 +145,19 @@ public class ScanNode extends RelationNode implements Projectable, SelectableNod
 	}
 
   @Override
-	public void setTargets(Target [] targets) {
+	public void setTargets(List<Target> targets) {
 	  this.targets = targets;
     setOutSchema(PlannerUtil.targetToSchema(targets));
 	}
 
   @Override
-	public Target [] getTargets() {
-	  return this.targets;
-	}
+  public List<Target> getTargets() {
+    if (hasTargets()) {
+      return this.targets;
+    } else {
+      return null;
+    }
+  }
 
   /**
    *
@@ -224,9 +231,9 @@ public class ScanNode extends RelationNode implements Projectable, SelectableNod
     }
 
     if (hasTargets()) {
-      scanNode.targets = new Target[targets.length];
-      for (int i = 0; i < targets.length; i++) {
-        scanNode.targets[i] = (Target) targets[i].clone();
+      scanNode.targets = new ArrayList<>();
+      for (Target t : targets) {
+        scanNode.targets.add((Target) t.clone());
       }
     }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/logical/TableSubQueryNode.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/TableSubQueryNode.java b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/TableSubQueryNode.java
index 4e9bd5c..bcf8851 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/TableSubQueryNode.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/TableSubQueryNode.java
@@ -21,15 +21,18 @@ package org.apache.tajo.plan.logical;
 import com.google.common.base.Objects;
 import com.google.gson.annotations.Expose;
 import org.apache.tajo.catalog.Schema;
-import org.apache.tajo.plan.PlanString;
-import org.apache.tajo.plan.util.PlannerUtil;
 import org.apache.tajo.catalog.SchemaUtil;
+import org.apache.tajo.plan.PlanString;
 import org.apache.tajo.plan.Target;
+import org.apache.tajo.plan.util.PlannerUtil;
+
+import java.util.ArrayList;
+import java.util.List;
 
 public class TableSubQueryNode extends RelationNode implements Projectable {
   @Expose private String tableName;
   @Expose private LogicalNode subQuery;
-  @Expose private Target [] targets; // unused
+  @Expose private List<Target> targets = null; // unused
 
   public TableSubQueryNode(int pid) {
     super(pid, NodeType.TABLE_SUBQUERY);
@@ -108,14 +111,19 @@ public class TableSubQueryNode extends RelationNode implements Projectable
{
   }
 
   @Override
-  public void setTargets(Target[] targets) {
+  public void setTargets(List<Target> targets) {
     this.targets = targets;
     setOutSchema(PlannerUtil.targetToSchema(targets));
   }
 
   @Override
-  public Target[] getTargets() {
-    return targets;
+  public List<Target> getTargets() {
+    if (hasTargets()) {
+      return targets;
+    } else {
+      return null;
+    }
+
   }
 
   @Override
@@ -125,9 +133,9 @@ public class TableSubQueryNode extends RelationNode implements Projectable
{
 
     if (hasTargets()) {
       StringBuilder sb = new StringBuilder("Targets: ");
-      for (int i = 0; i < targets.length; i++) {
-        sb.append(targets[i]);
-        if( i < targets.length - 1) {
+      for (int i = 0; i < targets.size(); i++) {
+        sb.append(targets.get(i));
+        if( i < targets.size() - 1) {
           sb.append(", ");
         }
       }
@@ -164,9 +172,9 @@ public class TableSubQueryNode extends RelationNode implements Projectable
{
     newTableSubQueryNode.tableName = tableName;
     newTableSubQueryNode.subQuery = (LogicalNode) subQuery.clone();
     if (hasTargets()) {
-      newTableSubQueryNode.targets = new Target[targets.length];
-      for (int i = 0; i < targets.length; i++) {
-        newTableSubQueryNode.targets[i] = (Target) targets[i].clone();
+      newTableSubQueryNode.targets = new ArrayList<>();
+      for (Target t : targets) {
+        newTableSubQueryNode.targets.add((Target) t.clone());
       }
     }
     return newTableSubQueryNode;

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/logical/WindowAggNode.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/WindowAggNode.java b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/WindowAggNode.java
index 1bee34c..b0b8788 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/logical/WindowAggNode.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/logical/WindowAggNode.java
@@ -23,12 +23,15 @@ import com.google.gson.annotations.Expose;
 import org.apache.tajo.catalog.Column;
 import org.apache.tajo.catalog.SortSpec;
 import org.apache.tajo.plan.PlanString;
-import org.apache.tajo.plan.util.PlannerUtil;
 import org.apache.tajo.plan.Target;
 import org.apache.tajo.plan.expr.WindowFunctionEval;
+import org.apache.tajo.plan.util.PlannerUtil;
 import org.apache.tajo.util.StringUtils;
 import org.apache.tajo.util.TUtil;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class WindowAggNode extends UnaryNode implements Projectable, Cloneable {
 	/** partition key sets */
   @Expose private Column [] partitionKeys;
@@ -41,7 +44,7 @@ public class WindowAggNode extends UnaryNode implements Projectable, Cloneable
{
    * It's a list of targets. The partition key columns should be followed by window functions.
    * aggrFunctions keep actual aggregation functions, but it only contains field references.
    * */
-  @Expose private Target [] targets;
+  @Expose private List<Target> targets = null;
   @Expose private boolean hasDistinct = false;
 
   public WindowAggNode(int pid) {
@@ -98,13 +101,13 @@ public class WindowAggNode extends UnaryNode implements Projectable,
Cloneable {
   }
 
   @Override
-  public void setTargets(Target[] targets) {
+  public void setTargets(List<Target> targets) {
     this.targets = targets;
     setOutSchema(PlannerUtil.targetToSchema(targets));
   }
 
   @Override
-  public Target[] getTargets() {
+  public List<Target> getTargets() {
     return this.targets;
   }
   
@@ -167,9 +170,9 @@ public class WindowAggNode extends UnaryNode implements Projectable, Cloneable
{
     }
 
     if (targets != null) {
-      grp.targets = new Target[targets.length];
-      for (int i = 0; i < targets.length; i++) {
-        grp.targets[i] = (Target) targets[i].clone();
+      grp.targets = new ArrayList<>();
+      for (Target t : targets) {
+        grp.targets.add((Target) t.clone());
       }
     }
 
@@ -224,9 +227,9 @@ public class WindowAggNode extends UnaryNode implements Projectable, Cloneable
{
     }
 
     sb = new StringBuilder("target list: ");
-    for (int i = 0; i < targets.length; i++) {
-      sb.append(targets[i]);
-      if( i < targets.length - 1) {
+    for (int i = 0; i < targets.size(); i++) {
+      sb.append(targets.get(i));
+      if( i < targets.size() - 1) {
         sb.append(", ");
       }
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/BaseSchemaBuildPhase.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/BaseSchemaBuildPhase.java
b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/BaseSchemaBuildPhase.java
index b30cee4..8776d8f 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/BaseSchemaBuildPhase.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/BaseSchemaBuildPhase.java
@@ -242,7 +242,7 @@ public class BaseSchemaBuildPhase extends LogicalPlanPreprocessPhase {
         }
       }
 
-      Target[] targets = buildTargets(ctx, expr.getNamedExprs());
+      List<Target> targets = buildTargets(ctx, expr.getNamedExprs());
 
       stack.pop(); // <--- Pop
 
@@ -254,17 +254,16 @@ public class BaseSchemaBuildPhase extends LogicalPlanPreprocessPhase
{
       return projectionNode;
     }
 
-    private Target [] buildTargets(LogicalPlanner.PlanContext context, NamedExpr [] exprs)
throws TajoException {
-      Target [] targets = new Target[exprs.length];
-      for (int i = 0; i < exprs.length; i++) {
-        NamedExpr namedExpr = exprs[i];
+    private List<Target> buildTargets(LogicalPlanner.PlanContext context, NamedExpr
[] exprs) throws TajoException {
+      List<Target> targets = new ArrayList<>();
+      for (NamedExpr namedExpr : exprs) {
         TajoDataTypes.DataType dataType = typeDeterminant.determineDataType(context, namedExpr.getExpr());
 
         if (namedExpr.hasAlias()) {
-          targets[i] = new Target(new FieldEval(new Column(namedExpr.getAlias(), dataType)));
+          targets.add(new Target(new FieldEval(new Column(namedExpr.getAlias(), dataType))));
         } else {
           String generatedName = context.getPlan().generateUniqueColumnName(namedExpr.getExpr());
-          targets[i] = new Target(new FieldEval(new Column(generatedName, dataType)));
+          targets.add(new Target(new FieldEval(new Column(generatedName, dataType))));
         }
       }
       return targets;
@@ -316,7 +315,7 @@ public class BaseSchemaBuildPhase extends LogicalPlanPreprocessPhase {
 
       Projection projection = ctx.getQueryBlock().getSingletonExpr(OpType.Projection);
       int finalTargetNum = projection.getNamedExprs().length;
-      Target [] targets = new Target[finalTargetNum];
+      List<Target> targets = new ArrayList<>();
 
       if (PlannerUtil.hasAsterisk(projection.getNamedExprs())) {
         projection.setNamedExprs(voidResolveAsteriskNamedExpr(ctx, projection.getNamedExprs()));
@@ -327,9 +326,9 @@ public class BaseSchemaBuildPhase extends LogicalPlanPreprocessPhase {
         EvalNode evalNode = annotator.createEvalNode(ctx, namedExpr.getExpr(), NameResolvingMode.SUBEXPRS_AND_RELS,
true);
 
         if (namedExpr.hasAlias()) {
-          targets[i] = new Target(evalNode, namedExpr.getAlias());
+          targets.add(new Target(evalNode, namedExpr.getAlias()));
         } else {
-          targets[i] = new Target(evalNode, "?name_" + i);
+          targets.add(new Target(evalNode, "?name_" + i));
         }
       }
       stack.pop();

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/InSubqueryRewriteRule.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/InSubqueryRewriteRule.java
b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/InSubqueryRewriteRule.java
index a0d0242..6265e38 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/InSubqueryRewriteRule.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/InSubqueryRewriteRule.java
@@ -128,7 +128,7 @@ public class InSubqueryRewriteRule implements LogicalPlanRewriteRule {
         joinNode.setOutSchema(node.getOutSchema());
 
         List<Target> targets = TUtil.newList(PlannerUtil.schemaToTargets(inSchema));
-        joinNode.setTargets(targets.toArray(new Target[targets.size()]));
+        joinNode.setTargets(targets);
 
         block.addJoinType(joinType);
         block.registerNode(joinNode);

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
index 1d32376..3c30c67 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/ProjectionPushDownRule.java
@@ -457,11 +457,11 @@ public class ProjectionPushDownRule extends
   public LogicalNode visitProjection(Context context, LogicalPlan plan, LogicalPlan.QueryBlock
block,
                                      ProjectionNode node, Stack<LogicalNode> stack)
throws TajoException {
     Context newContext = new Context(context);
-    Target [] targets = node.getTargets();
-    int targetNum = targets.length;
+    List<Target> targets = node.getTargets();
+    int targetNum = targets.size();
     String [] referenceNames = new String[targetNum];
     for (int i = 0; i < targetNum; i++) {
-      referenceNames[i] = newContext.addExpr(targets[i]);
+      referenceNames[i] = newContext.addExpr(targets.get(i));
     }
 
     LogicalNode child = super.visitProjection(newContext, plan, block, node, stack);
@@ -489,7 +489,7 @@ public class ProjectionPushDownRule extends
       }
     }
 
-    node.setTargets(finalTargets.toArray(new Target[finalTargets.size()]));
+    node.setTargets(finalTargets);
     LogicalPlanner.verifyProjectedFields(block, node);
 
     // Removing ProjectionNode
@@ -642,10 +642,10 @@ public class ProjectionPushDownRule extends
     }
 
 
-    int nonFunctionColumnNum = node.getTargets().length - node.getWindowFunctions().length;
+    int nonFunctionColumnNum = node.getTargets().size() - node.getWindowFunctions().length;
     LinkedHashSet<String> nonFunctionColumns = Sets.newLinkedHashSet();
     for (int i = 0; i < nonFunctionColumnNum; i++) {
-      FieldEval fieldEval = (new FieldEval(node.getTargets()[i].getNamedColumn()));
+      FieldEval fieldEval = (new FieldEval(node.getTargets().get(i).getNamedColumn()));
       nonFunctionColumns.add(newContext.addExpr(fieldEval));
     }
 
@@ -653,9 +653,9 @@ public class ProjectionPushDownRule extends
     if (node.hasAggFunctions()) {
       final int evalNum = node.getWindowFunctions().length;
       aggEvalNames = new String[evalNum];
-      for (int evalIdx = 0, targetIdx = nonFunctionColumnNum; targetIdx < node.getTargets().length;
evalIdx++,
+      for (int evalIdx = 0, targetIdx = nonFunctionColumnNum; targetIdx < node.getTargets().size();
evalIdx++,
           targetIdx++) {
-        Target target = node.getTargets()[targetIdx];
+        Target target = node.getTargets().get(targetIdx);
         WindowFunctionEval winFunc = node.getWindowFunctions()[evalIdx];
         aggEvalNames[evalIdx] = newContext.addExpr(new Target(winFunc, target.getCanonicalName()));
       }
@@ -706,7 +706,7 @@ public class ProjectionPushDownRule extends
       }
     }
 
-    node.setTargets(targets.toArray(new Target[targets.size()]));
+    node.setTargets(targets);
     return node;
   }
 
@@ -734,9 +734,9 @@ public class ProjectionPushDownRule extends
       if (node.hasAggFunctions()) {
         final int evalNum = node.getAggFunctions().length;
         aggEvalNames = new String[evalNum];
-        for (int evalIdx = 0, targetIdx = node.getGroupingColumns().length; targetIdx <
node.getTargets().length;
+        for (int evalIdx = 0, targetIdx = node.getGroupingColumns().length; targetIdx <
node.getTargets().size();
              evalIdx++, targetIdx++) {
-          Target target = node.getTargets()[targetIdx];
+          Target target = node.getTargets().get(targetIdx);
           EvalNode evalNode = node.getAggFunctions()[evalIdx];
           aggEvalNames[evalIdx] = newContext.addExpr(new Target(evalNode, target.getCanonicalName()));
         }
@@ -810,7 +810,7 @@ public class ProjectionPushDownRule extends
         node.setAggFunctions(aggEvals);
       }
     }
-    Target [] finalTargets = buildGroupByTarget(node, targets, aggEvalNames);
+    List<Target> finalTargets = buildGroupByTarget(node, targets, aggEvalNames);
     node.setTargets(finalTargets);
 
     LogicalPlanner.verifyProjectedFields(block, node);
@@ -818,28 +818,27 @@ public class ProjectionPushDownRule extends
     return node;
   }
 
-  public static Target [] buildGroupByTarget(GroupbyNode groupbyNode, @Nullable List<Target>
groupingKeyTargets,
+  public static List<Target> buildGroupByTarget(GroupbyNode groupbyNode, @Nullable
List<Target> groupingKeyTargets,
                                              String [] aggEvalNames) {
     final int groupingKeyNum =
         groupingKeyTargets == null ? groupbyNode.getGroupingColumns().length : groupingKeyTargets.size();
     final int aggrFuncNum = aggEvalNames != null ? aggEvalNames.length : 0;
     EvalNode [] aggEvalNodes = groupbyNode.getAggFunctions();
-    Target [] targets = new Target[groupingKeyNum + aggrFuncNum];
+    List<Target> targets = new ArrayList<>();
 
     if (groupingKeyTargets != null) {
       for (int groupingKeyIdx = 0; groupingKeyIdx < groupingKeyNum; groupingKeyIdx++)
{
-        targets[groupingKeyIdx] = groupingKeyTargets.get(groupingKeyIdx);
+        targets.add(groupingKeyTargets.get(groupingKeyIdx));
       }
     } else {
       for (int groupingKeyIdx = 0; groupingKeyIdx < groupingKeyNum; groupingKeyIdx++)
{
-        targets[groupingKeyIdx] = new Target(new FieldEval(groupbyNode.getGroupingColumns()[groupingKeyIdx]));
+        targets.add(new Target(new FieldEval(groupbyNode.getGroupingColumns()[groupingKeyIdx])));
       }
     }
 
     if (aggEvalNames != null) {
       for (int aggrFuncIdx = 0, targetIdx = groupingKeyNum; aggrFuncIdx < aggrFuncNum;
aggrFuncIdx++, targetIdx++) {
-        targets[targetIdx] =
-            new Target(new FieldEval(aggEvalNames[aggrFuncIdx], aggEvalNodes[aggrFuncIdx].getValueType()));
+        targets.add(new Target(new FieldEval(aggEvalNames[aggrFuncIdx], aggEvalNodes[aggrFuncIdx].getValueType())));
       }
     }
 
@@ -906,7 +905,7 @@ public class ProjectionPushDownRule extends
 
     String [] referenceNames = null;
     if (node.hasTargets()) {
-      referenceNames = new String[node.getTargets().length];
+      referenceNames = new String[node.getTargets().size()];
       int i = 0;
       for (Iterator<Target> it = getFilteredTarget(node.getTargets(), context.requiredSet);
it.hasNext();) {
         Target target = it.next();
@@ -954,7 +953,7 @@ public class ProjectionPushDownRule extends
       }
     }
 
-    node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()]));
+    node.setTargets(new ArrayList<>(projectedTargets));
     LogicalPlanner.verifyProjectedFields(block, node);
     return node;
   }
@@ -1000,14 +999,14 @@ public class ProjectionPushDownRule extends
     }
   }
 
-  static Iterator<Target> getFilteredTarget(Target[] targets, Set<String> required)
{
+  static Iterator<Target> getFilteredTarget(List<Target> targets, Set<String>
required) {
     return new FilteredIterator(targets, required);
   }
 
   static class FilteredIterator implements Iterator<Target> {
     Iterator<Target> iterator;
 
-    FilteredIterator(Target [] targets, Set<String> requiredReferences) {
+    FilteredIterator(List<Target> targets, Set<String> requiredReferences) {
       List<Target> filtered = TUtil.newList();
       Map<String, Target> targetSet = new HashMap<>();
       for (Target t : targets) {
@@ -1070,7 +1069,7 @@ public class ProjectionPushDownRule extends
 
     Context newContext = new Context(context);
 
-    Target [] targets;
+    List<Target> targets;
     if (node.hasTargets()) {
       targets = node.getTargets();
     } else {
@@ -1092,7 +1091,7 @@ public class ProjectionPushDownRule extends
       }
     }
 
-    node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()]));
+    node.setTargets(new ArrayList<>(projectedTargets));
     LogicalPlanner.verifyProjectedFields(block, node);
     return node;
   }
@@ -1104,7 +1103,7 @@ public class ProjectionPushDownRule extends
 
     Context newContext = new Context(context);
 
-    Target [] targets;
+    List<Target> targets;
     if (node.hasTargets()) {
       targets = node.getTargets();
     } else {
@@ -1126,7 +1125,7 @@ public class ProjectionPushDownRule extends
       }
     }
 
-    node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()]));
+    node.setTargets(new ArrayList<>(projectedTargets));
     LogicalPlanner.verifyProjectedFields(block, node);
     return node;
   }
@@ -1146,7 +1145,7 @@ public class ProjectionPushDownRule extends
     node.setSubQuery(child);
     stack.pop();
 
-    Target [] targets;
+    List<Target> targets;
     if (node.hasTargets()) {
       targets = node.getTargets();
     } else {
@@ -1168,7 +1167,7 @@ public class ProjectionPushDownRule extends
       }
     }
 
-    node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()]));
+    node.setTargets(new ArrayList<>(projectedTargets));
     LogicalPlanner.verifyProjectedFields(block, node);
     return node;
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
index 2051dfb..fdad4c4 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeDeserializer.java
@@ -741,18 +741,19 @@ public class LogicalNodeDeserializer {
     return columns;
   }
 
-  public static Target[] convertTargets(OverridableConf context, EvalContext evalContext,
+  public static List<Target> convertTargets(OverridableConf context, EvalContext evalContext,
                                         List<PlanProto.Target> targetsProto) {
-    Target [] targets = new Target[targetsProto.size()];
-    for (int i = 0; i < targets.length; i++) {
-      PlanProto.Target targetProto = targetsProto.get(i);
+    List<Target> targets = new ArrayList<>();
+    for (PlanProto.Target targetProto : targetsProto) {
       EvalNode evalNode = EvalNodeDeserializer.deserialize(context, evalContext, targetProto.getExpr());
+
       if (targetProto.hasAlias()) {
-        targets[i] = new Target(evalNode, targetProto.getAlias());
+        targets.add(new Target(evalNode, targetProto.getAlias()));
       } else {
-        targets[i] = new Target((FieldEval) evalNode);
+        targets.add(new Target((FieldEval) evalNode));
       }
     }
+
     return targets;
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
index 7907668..6b082f7 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/serder/LogicalNodeSerializer.java
@@ -23,6 +23,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.tajo.algebra.JoinType;
 import org.apache.tajo.catalog.SortSpec;
 import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.apache.tajo.common.ProtoObject;
 import org.apache.tajo.exception.TajoException;
 import org.apache.tajo.exception.TajoInternalError;
 import org.apache.tajo.exception.NotImplementedException;
@@ -148,7 +149,7 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
                                    EvalExprNode exprEval, Stack<LogicalNode> stack)
throws TajoException {
     PlanProto.EvalExprNode.Builder exprEvalBuilder = PlanProto.EvalExprNode.newBuilder();
     exprEvalBuilder.addAllTargets(
-        ProtoUtil.<PlanProto.Target>toProtoObjects(exprEval.getTargets()));
+        ProtoUtil.<PlanProto.Target>toProtoObjects(exprEval.getTargets().toArray(new
ProtoObject[exprEval.getTargets().size()])));
 
     PlanProto.LogicalNode.Builder nodeBuilder = createNodeBuilder(context, exprEval);
     nodeBuilder.setExprEval(exprEvalBuilder);
@@ -167,7 +168,7 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
     PlanProto.ProjectionNode.Builder projectionBuilder = PlanProto.ProjectionNode.newBuilder();
     projectionBuilder.setChildSeq(childIds[0]);
     projectionBuilder.addAllTargets(
-        ProtoUtil.<PlanProto.Target>toProtoObjects(projection.getTargets()));
+        ProtoUtil.<PlanProto.Target>toProtoObjects(projection.getTargets().toArray(new
ProtoObject[projection.getTargets().size()])));
     projectionBuilder.setDistinct(projection.isDistinct());
 
     PlanProto.LogicalNode.Builder nodeBuilder = createNodeBuilder(context, projection);
@@ -222,7 +223,7 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
     }
     if (windowAgg.hasTargets()) {
       windowAggBuilder.addAllTargets(
-          ProtoUtil.<PlanProto.Target>toProtoObjects(windowAgg.getTargets()));
+          ProtoUtil.<PlanProto.Target>toProtoObjects(windowAgg.getTargets().toArray(new
ProtoObject[windowAgg.getTargets().size()])));
     }
 
     PlanProto.LogicalNode.Builder nodeBuilder = createNodeBuilder(context, windowAgg);
@@ -297,7 +298,7 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
           ProtoUtil.<PlanProto.EvalNodeTree>toProtoObjects(node.getAggFunctions()));
     }
     if (node.hasTargets()) {
-      groupbyBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets()));
+      groupbyBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets().toArray(new
ProtoObject[node.getTargets().size()])));
     }
 
     PlanProto.LogicalNode.Builder nodeBuilder = createNodeBuilder(context, node);
@@ -332,7 +333,7 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
           ProtoUtil.<PlanProto.EvalNodeTree>toProtoObjects(node.getAggFunctions()));
     }
     if (node.hasTargets()) {
-      distGroupbyBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets()));
+      distGroupbyBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets().toArray(new
ProtoObject[node.getTargets().size()])));
     }
     for (int cid : node.getResultColumnIds()) {
       distGroupbyBuilder.addResultId(cid);
@@ -381,7 +382,7 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
 
     if (join.hasTargets()) {
       joinBuilder.setExistsTargets(true);
-      joinBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(join.getTargets()));
+      joinBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(join.getTargets().toArray(new
ProtoObject[join.getTargets().size()])));
     } else {
       joinBuilder.setExistsTargets(false);
     }
@@ -434,7 +435,7 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
 
     if (scan.hasTargets()) {
       scanBuilder.setExistTargets(true);
-      scanBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(scan.getTargets()));
+      scanBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(scan.getTargets().toArray(new
ProtoObject[scan.getTargets().size()])));
     } else {
       scanBuilder.setExistTargets(false);
     }
@@ -505,7 +506,7 @@ public class LogicalNodeSerializer extends BasicLogicalPlanVisitor<LogicalNodeSe
     builder.setTableName(node.getTableName());
 
     if (node.hasTargets()) {
-      builder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets()));
+      builder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets().toArray(new
ProtoObject[node.getTargets().size()])));
     }
     builder.setNameResolveBase(node.isNameResolveBase());
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java b/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java
index 507ae8b..f9a6a70 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/util/PlannerUtil.java
@@ -536,13 +536,13 @@ public class PlannerUtil {
     }
   }
 
-  public static Target[] schemaToTargets(Schema schema) {
-    Target[] targets = new Target[schema.size()];
+  public static List<Target> schemaToTargets(Schema schema) {
+    List<Target> targets = new ArrayList<>();
 
     FieldEval eval;
     for (int i = 0; i < schema.size(); i++) {
       eval = new FieldEval(schema.getColumn(i));
-      targets[i] = new Target(eval);
+      targets.add(new Target(eval));
     }
     return targets;
   }
@@ -653,10 +653,10 @@ public class PlannerUtil {
   }
 
   public static Schema targetToSchema(Collection<Target> targets) {
-    return targetToSchema(targets.toArray(new Target[targets.size()]));
+    return targetToSchema(targets);
   }
 
-  public static Schema targetToSchema(Target[] targets) {
+  public static Schema targetToSchema(List<Target> targets) {
     Schema schema = new Schema();
     for (Target t : targets) {
       DataType type = t.getEvalTree().getValueType();
@@ -680,16 +680,16 @@ public class PlannerUtil {
    * @param sourceTargets The targets to be stripped
    * @return The stripped targets
    */
-  public static Target[] stripTarget(Target[] sourceTargets) {
-    Target[] copy = new Target[sourceTargets.length];
-    for (int i = 0; i < sourceTargets.length; i++) {
+  public static List<Target> stripTarget(List<Target> sourceTargets) {
+    List<Target> copy = new ArrayList<>();
+    for (int i = 0; i < sourceTargets.size(); i++) {
       try {
-        copy[i] = (Target) sourceTargets[i].clone();
+        copy.add((Target) sourceTargets.get(i).clone());
       } catch (CloneNotSupportedException e) {
         throw new InternalError(e.getMessage());
       }
-      if (copy[i].getEvalTree().getType() == EvalType.FIELD) {
-        FieldEval fieldEval = copy[i].getEvalTree();
+      if (copy.get(i).getEvalTree().getType().equals(EvalType.FIELD)) {
+        FieldEval fieldEval = copy.get(i).getEvalTree();
         if (fieldEval.getColumnRef().hasQualifier()) {
           fieldEval.replaceColumnRef(fieldEval.getColumnName());
         }

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/LogicalPlanVerifier.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/LogicalPlanVerifier.java
b/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/LogicalPlanVerifier.java
index c87ceb3..aff95df 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/LogicalPlanVerifier.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/verifier/LogicalPlanVerifier.java
@@ -65,7 +65,7 @@ public class LogicalPlanVerifier extends BasicLogicalPlanVisitor<LogicalPlanVeri
     Schema outputSchema = node.getOutSchema();
     Schema targetSchema = PlannerUtil.targetToSchema(node.getTargets());
 
-    if (outputSchema.size() != node.getTargets().length) {
+    if (outputSchema.size() != node.getTargets().size()) {
       throw new TajoInternalError(String.format("Output schema and Target's schema are mismatched
at Node (%d)",
           + node.getPID()));
     }

http://git-wip-us.apache.org/repos/asf/tajo/blob/a2a5c14e/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/SQLBuilder.java
----------------------------------------------------------------------
diff --git a/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/SQLBuilder.java
b/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/SQLBuilder.java
index ca1c128..14d5eb8 100644
--- a/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/SQLBuilder.java
+++ b/tajo-storage/tajo-storage-jdbc/src/main/java/org/apache/tajo/storage/jdbc/SQLBuilder.java
@@ -29,6 +29,7 @@ import org.apache.tajo.util.StringUtils;
 
 import javax.annotation.Nullable;
 import java.sql.DatabaseMetaData;
+import java.util.List;
 import java.util.Stack;
 
 /**
@@ -153,7 +154,7 @@ public class SQLBuilder {
   public void visitScan(SQLBuilderContext ctx, ScanNode scan, Stack<LogicalNode> stack)
{
 
     StringBuilder selectClause = new StringBuilder("SELECT ");
-    if (scan.getTargets().length > 0) {
+    if (scan.getTargets().size() > 0) {
       selectClause.append(generateTargetList(scan.getTargets()));
     } else {
       selectClause.append("1");
@@ -172,7 +173,7 @@ public class SQLBuilder {
     }
   }
 
-  public String generateTargetList(Target [] targets) {
+  public String generateTargetList(List<Target> targets) {
     return StringUtils.join(targets, ",", new Function<Target, String>() {
       @Override
       public String apply(@Nullable Target t) {


Mime
View raw message