@Override public Aggregation visitGroupby_clause(Groupby_clauseContext ctx) { Aggregation clause = new Aggregation(); clause.setGroups(groups.subList(0, groupSize).toArray(new GroupElement[groupSize])); } else if (groupSize > 1) { clause.setGroups(groups.subList(1, groupSize).toArray(new GroupElement[groupSize - 1]));
@Override public RESULT visitGroupBy(CONTEXT ctx, Stack<Expr> stack, Aggregation expr) throws TajoException { stack.push(expr); for (org.apache.tajo.algebra.Aggregation.GroupElement groupElement : expr.getGroupSet()) { for (Expr groupingSet : groupElement.getGroupingSets()) { visit(ctx, stack, groupingSet); } } RESULT result = visit(ctx, stack, expr.getChild()); stack.pop(); return result; }
private Expr generateOneExpr() { Expr expr = new BinaryOperator(OpType.LessThan, new LiteralValue("1", LiteralType.Unsigned_Integer), new LiteralValue("2", LiteralType.Unsigned_Integer)); Relation relation = new Relation("employee"); Selection selection = new Selection(expr); selection.setChild(relation); Aggregation aggregation = new Aggregation(); aggregation.setTargets(new NamedExpr[]{ new NamedExpr(new ColumnReferenceExpr("col1")) }); aggregation.setChild(selection); Sort.SortSpec spec = new Sort.SortSpec(new ColumnReferenceExpr("col2"), false, false); Sort sort = new Sort(new Sort.SortSpec[]{spec}); sort.setChild(aggregation); return sort; }
@Override public int hashCode() { return Objects.hashCode(Objects.hashCode(namedExprs), Objects.hashCode(groups), getChild()); }
aggregation.setChild(current); current = aggregation;
@Override public Expr visitGroupBy(Context context, Stack<Expr> stack, Aggregation expr) throws TajoException { super.visitGroupBy(context, stack, expr); // Enforcer only ordinary grouping set. for (Aggregation.GroupElement groupingElement : expr.getGroupSet()) { if (groupingElement.getType() != Aggregation.GroupType.OrdinaryGroup) { context.state.addVerification(ExceptionUtil.makeNotSupported(groupingElement.getType().name())); } } Projection projection = null; for (Expr parent : stack) { if (parent.getType() == OpType.Projection) { projection = (Projection) parent; break; } } if (projection == null) { throw new TajoInternalError("No Projection"); } return expr; }
@Test public void testEquals() throws Exception { Expr expr = new BinaryOperator(OpType.LessThan, new LiteralValue("1", LiteralType.Unsigned_Integer), new LiteralValue("2", LiteralType.Unsigned_Integer)); Relation relation = new Relation("employee"); Selection selection = new Selection(expr); selection.setChild(relation); Aggregation aggregation = new Aggregation(); aggregation.setTargets(new NamedExpr[]{ new NamedExpr(new ColumnReferenceExpr("col1")) } ); aggregation.setChild(selection); Sort.SortSpec spec = new Sort.SortSpec(new ColumnReferenceExpr("col2")); Sort sort = new Sort(new Sort.SortSpec[]{spec}); sort.setChild(aggregation); assertEquals(sort, sort); Expr different = generateOneExpr(); assertFalse(sort.equals(different)); }
@Override public int hashCode() { return Objects.hashCode(Objects.hashCode(namedExprs), Objects.hashCode(groups), getChild()); }
aggregation.setChild(current); current = aggregation;
@Override public Expr visitGroupBy(Context context, Stack<Expr> stack, Aggregation expr) throws TajoException { super.visitGroupBy(context, stack, expr); // Enforcer only ordinary grouping set. for (Aggregation.GroupElement groupingElement : expr.getGroupSet()) { if (groupingElement.getType() != Aggregation.GroupType.OrdinaryGroup) { context.state.addVerification(ExceptionUtil.makeNotSupported(groupingElement.getType().name())); } } Projection projection = null; for (Expr parent : stack) { if (parent.getType() == OpType.Projection) { projection = (Projection) parent; break; } } if (projection == null) { throw new TajoInternalError("No Projection"); } return expr; }
@Test public void testJson2() { Expr expr = new BinaryOperator(OpType.LessThan, new LiteralValue("1", LiteralType.Unsigned_Integer), new LiteralValue("2", LiteralType.Unsigned_Integer)); Relation relation = new Relation("employee"); Selection selection = new Selection(expr); selection.setChild(relation); Aggregation aggregation = new Aggregation(); aggregation.setTargets(new NamedExpr[]{ new NamedExpr(new ColumnReferenceExpr("col1")) } ); aggregation.setChild(selection); Sort.SortSpec spec = new Sort.SortSpec(new ColumnReferenceExpr("col2")); Sort sort = new Sort(new Sort.SortSpec[]{spec}); sort.setChild(aggregation); String json = sort.toJson(); Expr fromJson = JsonHelper.fromJson(json, Expr.class); assertEquals(sort, fromJson); } }
@Override public RESULT visitGroupBy(CONTEXT ctx, Stack<Expr> stack, Aggregation expr) throws TajoException { stack.push(expr); for (org.apache.tajo.algebra.Aggregation.GroupElement groupElement : expr.getGroupSet()) { for (Expr groupingSet : groupElement.getGroupingSets()) { visit(ctx, stack, groupingSet); } } RESULT result = visit(ctx, stack, expr.getChild()); stack.pop(); return result; }
@Override public LogicalNode visitGroupBy(ProcessorContext ctx, Stack<Expr> stack, Aggregation expr) throws TajoException { super.visitGroupBy(ctx, stack, expr); GroupbyNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getChild()); node.setInSchema(child.getOutSchema()); return node; }
@Override public Aggregation visitGroupby_clause(Groupby_clauseContext ctx) { Aggregation clause = new Aggregation(); clause.setGroups(groups.subList(0, groupSize).toArray(new GroupElement[groupSize])); } else if (groupSize > 1) { clause.setGroups(groups.subList(1, groupSize).toArray(new GroupElement[groupSize - 1]));
int groupingKeyNum = aggregation.getGroupSet()[0].getGroupingSets().length; ExprNormalizedResult [] normalizedResults = new ExprNormalizedResult[groupingKeyNum]; for (int i = 0; i < groupingKeyNum; i++) { Expr groupingKey = aggregation.getGroupSet()[0].getGroupingSets()[i]; normalizedResults[i] = normalizer.normalize(context, groupingKey); LogicalNode child = visit(context, stack, aggregation.getChild()); stack.pop();
@Override public LogicalNode visitGroupBy(ProcessorContext ctx, Stack<Expr> stack, Aggregation expr) throws TajoException { super.visitGroupBy(ctx, stack, expr); GroupbyNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getChild()); node.setInSchema(child.getOutSchema()); return node; }
int groupingKeyNum = aggregation.getGroupSet()[0].getGroupingSets().length; ExprNormalizedResult [] normalizedResults = new ExprNormalizedResult[groupingKeyNum]; for (int i = 0; i < groupingKeyNum; i++) { Expr groupingKey = aggregation.getGroupSet()[0].getGroupingSets()[i]; normalizedResults[i] = normalizer.normalize(context, groupingKey); LogicalNode child = visit(context, stack, aggregation.getChild()); stack.pop();
@Override public LogicalNode visitGroupBy(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, Aggregation expr) throws TajoException { stack.push(expr); // <--- push LogicalNode child = visit(ctx, stack, expr.getChild()); Projection projection = ctx.getQueryBlock().getSingletonExpr(OpType.Projection); int finalTargetNum = projection.getNamedExprs().size(); List<Target> targets = new ArrayList<>(); if (PlannerUtil.hasAsterisk(projection.getNamedExprs())) { projection.setNamedExprs(voidResolveAsteriskNamedExpr(ctx, projection.getNamedExprs())); } for (int i = 0; i < finalTargetNum; i++) { NamedExpr namedExpr = projection.getNamedExprs().get(i); EvalNode evalNode = annotator.createEvalNode(ctx, namedExpr.getExpr(), NameResolvingMode.SUBEXPRS_AND_RELS, true); if (namedExpr.hasAlias()) { targets.add(new Target(evalNode, namedExpr.getAlias())); } else { targets.add(new Target(evalNode, "?name_" + i)); } } stack.pop(); GroupbyNode groupByNode = ctx.getPlan().createNode(GroupbyNode.class); groupByNode.setInSchema(child.getOutSchema()); groupByNode.setOutSchema(PlannerUtil.targetToSchema(targets)); return groupByNode; }
@Override public LogicalNode visitGroupBy(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, Aggregation expr) throws TajoException { stack.push(expr); // <--- push LogicalNode child = visit(ctx, stack, expr.getChild()); Projection projection = ctx.getQueryBlock().getSingletonExpr(OpType.Projection); int finalTargetNum = projection.getNamedExprs().length; Target [] targets = new Target[finalTargetNum]; if (PlannerUtil.hasAsterisk(projection.getNamedExprs())) { projection.setNamedExprs(voidResolveAsteriskNamedExpr(ctx, projection.getNamedExprs())); } for (int i = 0; i < finalTargetNum; i++) { NamedExpr namedExpr = projection.getNamedExprs()[i]; EvalNode evalNode = annotator.createEvalNode(ctx, namedExpr.getExpr(), NameResolvingMode.SUBEXPRS_AND_RELS, true); if (namedExpr.hasAlias()) { targets[i] = new Target(evalNode, namedExpr.getAlias()); } else { targets[i] = new Target(evalNode, "?name_" + i); } } stack.pop(); GroupbyNode groupByNode = ctx.getPlan().createNode(GroupbyNode.class); groupByNode.setInSchema(child.getOutSchema()); groupByNode.setOutSchema(PlannerUtil.targetToSchema(targets)); return groupByNode; }