/** * It checks if an alias name included in the target of this node is for aggregation function. * If so, it returns TRUE. Otherwise, it returns FALSE. */ public boolean isAggregationColumn(String simpleName) { for (int i = groupingKeys.length; i < targets.length; i++) { if (simpleName.equals(targets[i].getNamedColumn().getSimpleName()) || simpleName.equals(targets[i].getAlias())) { return true; } } return false; } }
/** * It checks if an alias name included in the target of this node is for aggregation function. * If so, it returns TRUE. Otherwise, it returns FALSE. */ public boolean isAggregationColumn(String simpleName) { for (Target t : targets) { if (simpleName.equals(t.getNamedColumn().getSimpleName()) || simpleName.equals(t.getAlias())) { return true; } } return false; } }
private static SortSpec[] annotateSortSpecs(QueryBlock block, String [] referNames, Sort.SortSpec[] rawSortSpecs) { int sortKeyNum = rawSortSpecs.length; Column column; List<SortSpec> annotatedSortSpecs = Lists.newArrayList(); for (int i = 0; i < sortKeyNum; i++) { String refName = referNames[i]; if (block.isConstReference(refName)) { continue; } else if (block.namedExprsMgr.isEvaluated(refName)) { column = block.namedExprsMgr.getTarget(refName).getNamedColumn(); } else { throw new IllegalStateException("Unexpected State: " + StringUtils.join(rawSortSpecs)); } annotatedSortSpecs.add(new SortSpec(column, rawSortSpecs[i].isAscending(), rawSortSpecs[i].isNullsFirst())); } return annotatedSortSpecs.toArray(new SortSpec[annotatedSortSpecs.size()]); }
private static SortSpec[] annotateSortSpecs(QueryBlock block, String [] referNames, Sort.SortSpec[] rawSortSpecs) { int sortKeyNum = rawSortSpecs.length; Column column; List<SortSpec> annotatedSortSpecs = Lists.newArrayList(); for (int i = 0; i < sortKeyNum; i++) { String refName = referNames[i]; if (block.isConstReference(refName)) { continue; } else if (block.namedExprsMgr.isEvaluated(refName)) { column = block.namedExprsMgr.getTarget(refName).getNamedColumn(); } else { throw new IllegalStateException("Unexpected State: " + StringUtils.join(rawSortSpecs)); } annotatedSortSpecs.add(new SortSpec(column, rawSortSpecs[i].isAscending(), rawSortSpecs[i].isNullsFirst())); } return annotatedSortSpecs.toArray(new SortSpec[annotatedSortSpecs.size()]); }
private SortExec createSortExecForDistinctGroupby(TaskAttemptContext context, DistinctGroupbyNode distinctNode, PhysicalExec subOp, int phase) throws IOException { SortNode sortNode = LogicalPlan.createNodeWithoutPID(SortNode.class); //2 phase: seq, groupby columns, distinct1 keys, distinct2 keys, //3 phase: groupby columns, seq, distinct1 keys, distinct2 keys, List<SortSpec> sortSpecs = new ArrayList<>(); if (phase == 2) { sortSpecs.add(new SortSpec(distinctNode.getTargets().get(0).getNamedColumn())); } for (Column eachColumn: distinctNode.getGroupingColumns()) { sortSpecs.add(new SortSpec(eachColumn)); } if (phase == 3) { sortSpecs.add(new SortSpec(distinctNode.getTargets().get(0).getNamedColumn())); } for (GroupbyNode eachGroupbyNode: distinctNode.getSubPlans()) { for (Column eachColumn: eachGroupbyNode.getGroupingColumns()) { sortSpecs.add(new SortSpec(eachColumn)); } } sortNode.setSortSpecs(sortSpecs.toArray(new SortSpec[sortSpecs.size()])); sortNode.setInSchema(distinctNode.getInSchema()); sortNode.setOutSchema(distinctNode.getInSchema()); ExternalSortExec sortExec = new ExternalSortExec(context, sortNode, subOp); return sortExec; }
Collections.addAll(groupingColumnSet, eachGroupby.getGroupingColumns()); for (Target eachTarget: eachGroupby.getTargets()) { if (!groupingColumnSet.contains(eachTarget.getNamedColumn())) { groupbyResultTupleIndex.put(eachTarget.getNamedColumn(), resultTupleIndex); resultTupleIndex++;
private SortExec createSortExecForDistinctGroupby(TaskAttemptContext context, DistinctGroupbyNode distinctNode, PhysicalExec subOp, int phase) throws IOException { SortNode sortNode = LogicalPlan.createNodeWithoutPID(SortNode.class); //2 phase: seq, groupby columns, distinct1 keys, distinct2 keys, //3 phase: groupby columns, seq, distinct1 keys, distinct2 keys, List<SortSpec> sortSpecs = new ArrayList<SortSpec>(); if (phase == 2) { sortSpecs.add(new SortSpec(distinctNode.getTargets()[0].getNamedColumn())); } for (Column eachColumn: distinctNode.getGroupingColumns()) { sortSpecs.add(new SortSpec(eachColumn)); } if (phase == 3) { sortSpecs.add(new SortSpec(distinctNode.getTargets()[0].getNamedColumn())); } for (GroupbyNode eachGroupbyNode: distinctNode.getSubPlans()) { for (Column eachColumn: eachGroupbyNode.getGroupingColumns()) { sortSpecs.add(new SortSpec(eachColumn)); } } sortNode.setSortSpecs(sortSpecs.toArray(new SortSpec[]{})); sortNode.setInSchema(distinctNode.getInSchema()); sortNode.setOutSchema(distinctNode.getInSchema()); ExternalSortExec sortExec = new ExternalSortExec(context, sortNode, subOp); return sortExec; }
Collections.addAll(groupingColumnSet, eachGroupby.getGroupingColumns()); for (Target eachTarget: eachGroupby.getTargets()) { if (!groupingColumnSet.contains(eachTarget.getNamedColumn())) { groupbyResultTupleIndex.put(eachTarget.getNamedColumn(), resultTupleIndex); resultTupleIndex++;
continue; } else if (block.namedExprsMgr.isEvaluated(refName)) { groupingColumns.add(block.namedExprsMgr.getTarget(refName).getNamedColumn()); } else { throw makeSyntaxError("Each grouping column expression must be a scalar expression.");
Target target = context.targetListMgr.getTarget(sortKey); if (context.targetListMgr.isEvaluated(sortKey)) { Column c = target.getNamedColumn(); SortSpec sortSpec = new SortSpec(c, node.getSortKeys()[i].isAscending(), node.getSortKeys()[i].isNullsFirst()); if (!sortSpecs.contains(sortSpec)) {
@Test public final void testInsertInto6() throws TajoException { QueryContext qc = createQueryContext(); Expr expr = sqlAnalyzer.parse(insertStatements[6]); LogicalPlan plan = planner.createPlan(qc, expr); assertEquals(1, plan.getQueryBlocks().size()); InsertNode insertNode = getInsertNode(plan); ProjectionNode subquery = insertNode.getChild(); List<Target> targets = subquery.getTargets(); // targets MUST be manager, NULL as empid, deptname assertEquals(targets.get(0).getNamedColumn().getQualifiedName(), "default.dept.manager"); assertEquals(targets.get(1).getAlias(), "empid"); assertEquals(targets.get(1).getEvalTree().getType(), EvalType.CONST); assertEquals(targets.get(2).getNamedColumn().getQualifiedName(), "default.dept.deptname"); }
Target target = context.targetListMgr.getTarget(sortKey); if (context.targetListMgr.isEvaluated(sortKey)) { Column c = target.getNamedColumn(); SortSpec sortSpec = new SortSpec(c, node.getSortKeys()[i].isAscending(), node.getSortKeys()[i].isNullsFirst()); if (!sortSpecs.contains(sortSpec)) {
LinkedHashSet<String> nonFunctionColumns = Sets.newLinkedHashSet(); for (int i = 0; i < nonFunctionColumnNum; i++) { FieldEval fieldEval = (new FieldEval(node.getTargets().get(i).getNamedColumn())); nonFunctionColumns.add(newContext.addExpr(fieldEval)); targets.add(new Target(new FieldEval(target.getNamedColumn()))); } else { if (target.getEvalTree().getType() == EvalType.FIELD) { context.targetListMgr.markAsEvaluated(target); targets.add(new Target(new FieldEval(target.getNamedColumn())));
Target fieldReference = new Target(new FieldEval(target.getNamedColumn()));
Target fieldReference = new Target(new FieldEval(target.getNamedColumn()));
LinkedHashSet<String> nonFunctionColumns = Sets.newLinkedHashSet(); for (int i = 0; i < nonFunctionColumnNum; i++) { FieldEval fieldEval = (new FieldEval(node.getTargets()[i].getNamedColumn())); nonFunctionColumns.add(newContext.addExpr(fieldEval)); targets.add(new Target(new FieldEval(target.getNamedColumn()))); } else { if (target.getEvalTree().getType() == EvalType.FIELD) { context.targetListMgr.markAsEvaluated(target); targets.add(new Target(new FieldEval(target.getNamedColumn())));
public LogicalNode visitFilter(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, SelectionNode node, Stack<LogicalNode> stack) throws TajoException { Context newContext = new Context(context); String referenceName = newContext.targetListMgr.add(node.getQual()); newContext.addNecessaryReferences(node.getQual()); LogicalNode child = super.visitFilter(newContext, plan, block, node, stack); node.setInSchema(child.getOutSchema()); node.setOutSchema(child.getOutSchema()); Target target = context.targetListMgr.getTarget(referenceName); if (newContext.targetListMgr.isEvaluated(referenceName)) { node.setQual(new FieldEval(target.getNamedColumn())); } else { node.setQual(target.getEvalTree()); newContext.targetListMgr.markAsEvaluated(target); } return node; }
@Override public LogicalNode visitHaving(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, HavingNode node, Stack<LogicalNode> stack) throws TajoException { Context newContext = new Context(context); String referenceName = newContext.targetListMgr.add(node.getQual()); newContext.addNecessaryReferences(node.getQual()); LogicalNode child = super.visitHaving(newContext, plan, block, node, stack); node.setInSchema(child.getOutSchema()); node.setOutSchema(child.getOutSchema()); Target target = context.targetListMgr.getTarget(referenceName); if (newContext.targetListMgr.isEvaluated(referenceName)) { node.setQual(new FieldEval(target.getNamedColumn())); } else { node.setQual(target.getEvalTree()); newContext.targetListMgr.markAsEvaluated(target); } return node; }
public LogicalNode visitFilter(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, SelectionNode node, Stack<LogicalNode> stack) throws TajoException { Context newContext = new Context(context); String referenceName = newContext.targetListMgr.add(node.getQual()); newContext.addNecessaryReferences(node.getQual()); LogicalNode child = super.visitFilter(newContext, plan, block, node, stack); node.setInSchema(child.getOutSchema()); node.setOutSchema(child.getOutSchema()); Target target = context.targetListMgr.getTarget(referenceName); if (newContext.targetListMgr.isEvaluated(referenceName)) { node.setQual(new FieldEval(target.getNamedColumn())); } else { node.setQual(target.getEvalTree()); newContext.targetListMgr.markAsEvaluated(target); } return node; }
@Override public LogicalNode visitHaving(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, HavingNode node, Stack<LogicalNode> stack) throws TajoException { Context newContext = new Context(context); String referenceName = newContext.targetListMgr.add(node.getQual()); newContext.addNecessaryReferences(node.getQual()); LogicalNode child = super.visitHaving(newContext, plan, block, node, stack); node.setInSchema(child.getOutSchema()); node.setOutSchema(child.getOutSchema()); Target target = context.targetListMgr.getTarget(referenceName); if (newContext.targetListMgr.isEvaluated(referenceName)) { node.setQual(new FieldEval(target.getNamedColumn())); } else { node.setQual(target.getEvalTree()); newContext.targetListMgr.markAsEvaluated(target); } return node; }