@Override final public GroupByNode visit(final ASTGroupClause node, Object data) throws VisitorException { final GroupByNode groupBy = new GroupByNode(); final int childCount = node.jjtGetNumChildren(); for (int i = 0; i < childCount; i++) { /* * Delegate to the value expression builder. */ final AssignmentNode expr = (AssignmentNode) node.jjtGetChild(i) .jjtAccept(this, null/* data */); groupBy.addExpr((AssignmentNode) expr); } return groupBy; }
@Override final public GroupByNode visit(final ASTGroupClause node, Object data) throws VisitorException { final GroupByNode groupBy = new GroupByNode(); final int childCount = node.jjtGetNumChildren(); for (int i = 0; i < childCount; i++) { /* * Delegate to the value expression builder. */ final AssignmentNode expr = (AssignmentNode) node.jjtGetChild(i) .jjtAccept(this, null/* data */); groupBy.addExpr((AssignmentNode) expr); } return groupBy; }
/** * Unit test with SELECT clause having one value expression, which is a * simple variable also appearing as the sole value expression in the * GROUP_BY clause. * <pre> * SELECT ?org * GROUP BY ?org * </pre> */ public void test_aggregateExpr_01() { final VarNode org = new VarNode("org"); final ProjectionNode select = new ProjectionNode(); select.addProjectionVar(org); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(org); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Unit test with SELECT clause having one value expression, which is a * simple variable also appearing as the sole value expression in the * GROUP_BY clause. However, in this case we rename the variable when it is * projected out of the SELECT expression. * * <pre> * SELECT ?org as ?newVar * GROUP BY ?org * </pre> */ public void test_aggregateExpr_02() { final VarNode org = new VarNode("org"); final VarNode newVar = new VarNode("newVar"); @SuppressWarnings({ "unchecked", "rawtypes" }) final ProjectionNode select = new ProjectionNode(); select.addProjectionExpression(new AssignmentNode(newVar, org)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(org); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Unit test for references to aggregate declared in GROUP_BY with AS. * <pre> * SELECT ?org2 * GROUP BY UCASE(?org) as ?org2 * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_aggregateExpr_03() { // Note: UcaseBOp is what we need here. final VarNode org = new VarNode("org"); final VarNode org2 = new VarNode("org2"); final IValueExpressionNode ucaseExpr = new FunctionNode(FunctionRegistry.UCASE, null, org); final ProjectionNode select = new ProjectionNode(); select.addProjectionVar(org2); final GroupByNode groupBy = new GroupByNode(); groupBy.addExpr(new AssignmentNode(org2, ucaseExpr)); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Unit test for {@link IGroupByState#isAnyDistinct()) where the DISTINCT * keyword appears within an {@link IAggregate} in the SELECT clause. * <pre> * SELECT SUM(DISTINCT ?y) as ?x * GROUP BY ?z * HAVING ?x > 10 * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_isAnyDistinct_select() { final VarNode y = new VarNode("y"); final VarNode x = new VarNode("x"); final VarNode z = new VarNode("z"); final Map<String, Object> scalarValues = new HashMap<>(); scalarValues.put(Annotations.DISTINCT, Boolean.TRUE); final IValueExpressionNode xExpr = new FunctionNode(FunctionRegistry.SUM, scalarValues, y); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(x, xExpr)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(z); final HavingNode having = new HavingNode(); having.addExpr(FunctionNode.GT( x, new ConstantNode(new XSDNumericIV(10)) )); new VerifyAggregates(select, groupBy, having); }
/** * Unit test with SELECT clause having one value expression, which is a * simple variable also appearing as the sole value expression in the * GROUP_BY clause. * <pre> * SELECT ?org * GROUP BY ?org * </pre> */ public void test_aggregateExpr_01() { final VarNode org = new VarNode("org"); final ProjectionNode select = new ProjectionNode(); select.addProjectionVar(org); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(org); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Unit test with simple aggregate function in SELECT clause. * <pre> * SELECT ?org, SUM(?lprice) AS ?totalPrice * GROUP BY ?org * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_simpleAggregate() { final VarNode org = new VarNode("org"); final VarNode lprice = new VarNode("lprice"); final VarNode totalPrice = new VarNode("totalPrice"); final IValueExpressionNode totalPriceExprNode = new FunctionNode( FunctionRegistry.SUM, null, lprice); final ProjectionNode select = new ProjectionNode(); select.addProjectionVar(org); select.addProjectionExpression(new AssignmentNode(totalPrice, totalPriceExprNode)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(org); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Unit test verifies that a constant within a group by clause does not * cause the group by clause to be interpreted as an aggregate. * * <pre> * select ?index * group by (?o + 1 AS ?index) * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_aggregateExpr_04() { final VarNode index = new VarNode("index"); final VarNode o = new VarNode("o"); final IValueExpressionNode mathExpr = FunctionNode.add( o, new ConstantNode(new XSDNumericIV(1))); final ProjectionNode select = new ProjectionNode(); select.addProjectionVar(index); final GroupByNode groupBy = new GroupByNode(); groupBy.addExpr(new AssignmentNode(index, mathExpr)); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * <pre> * SELECT SUM(?x+MIN(?y)) as ?z * GROUP BY ?a * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_nestedAggregates() { final VarNode a = new VarNode("a"); final VarNode x = new VarNode("x"); final VarNode y = new VarNode("y"); final VarNode z = new VarNode("z"); final IValueExpressionNode zExpr = new FunctionNode(FunctionRegistry.SUM, null, FunctionNode.add(x, new FunctionNode( FunctionRegistry.MIN, null, y))); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(z, zExpr)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(a); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Unit test with SELECT clause having one value expression, which is a * simple variable also appearing as the sole value expression in the * GROUP_BY clause. However, in this case we rename the variable when it is * projected out of the SELECT expression. * * <pre> * SELECT ?org as ?newVar * GROUP BY ?org * </pre> */ public void test_aggregateExpr_02() { final VarNode org = new VarNode("org"); final VarNode newVar = new VarNode("newVar"); @SuppressWarnings({ "unchecked", "rawtypes" }) final ProjectionNode select = new ProjectionNode(); select.addProjectionExpression(new AssignmentNode(newVar, org)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(org); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * <pre> * SELECT SUM(?y) as ?x * GROUP BY ?z * HAVING ?x > 10 * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_simpleHavingClause() { final VarNode y = new VarNode("y"); final VarNode x = new VarNode("x"); final VarNode z = new VarNode("z"); final IValueExpressionNode xExpr = new FunctionNode( FunctionRegistry.SUM, null, y); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(x, xExpr)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(z); final HavingNode having = new HavingNode(); having.addExpr(FunctionNode.GT( x, new ConstantNode(new XSDNumericIV(10)) )); new VerifyAggregates(select, groupBy, having); }
/** * Unit test for references to aggregate declared in GROUP_BY with AS. * <pre> * SELECT ?org2 * GROUP BY UCASE(?org) as ?org2 * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_aggregateExpr_03() { // Note: UcaseBOp is what we need here. final VarNode org = new VarNode("org"); final VarNode org2 = new VarNode("org2"); final IValueExpressionNode ucaseExpr = new FunctionNode(FunctionRegistry.UCASE, null, org); final ProjectionNode select = new ProjectionNode(); select.addProjectionVar(org2); final GroupByNode groupBy = new GroupByNode(); groupBy.addExpr(new AssignmentNode(org2, ucaseExpr)); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Verify that a reference to a variable defined by a previous select * expression is allowed and that the select dependency is recognized. * * <pre> * SELECT SUM(?y) as ?z, SUM(?x)+?z as ?a * GROUP BY ?b * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_reverseReference_allowed_aka_select_dependency() { final VarNode a = new VarNode("a"); final VarNode b = new VarNode("b"); final VarNode x = new VarNode("x"); final VarNode y = new VarNode("y"); final VarNode z = new VarNode("z"); final IValueExpressionNode zExpr = new FunctionNode(FunctionRegistry.SUM, null,y); final IValueExpressionNode aExpr = FunctionNode.add(new FunctionNode(FunctionRegistry.SUM, null,x), z); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(z, zExpr)); select.addExpr(new AssignmentNode(a, aExpr)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(b); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * <pre> * SELECT SUM(?y) as ?x * GROUP BY ?z * HAVING SUM(?y) > 10 * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_complexHavingClause() { final VarNode y = new VarNode("y"); final VarNode x = new VarNode("x"); final VarNode z = new VarNode("z"); final FunctionNode xExpr = new FunctionNode( FunctionRegistry.SUM, null, y); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(x, xExpr)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(new VarNode(z)); final HavingNode having = new HavingNode(); having.addExpr(FunctionNode.GT( xExpr, new ConstantNode(new XSDNumericIV(10)) )); new VerifyAggregates(select, groupBy, having); }
/** * Unit test with simple aggregate function in SELECT clause. * <pre> * SELECT ?org, SUM(?lprice) AS ?totalPrice * GROUP BY ?org * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_simpleAggregate() { final VarNode org = new VarNode("org"); final VarNode lprice = new VarNode("lprice"); final VarNode totalPrice = new VarNode("totalPrice"); final IValueExpressionNode totalPriceExprNode = new FunctionNode( FunctionRegistry.SUM, null, lprice); final ProjectionNode select = new ProjectionNode(); select.addProjectionVar(org); select.addProjectionExpression(new AssignmentNode(totalPrice, totalPriceExprNode)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(org); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Unit test verifies that a constant within a group by clause does not * cause the group by clause to be interpreted as an aggregate. * * <pre> * select ?index * group by (?o + 1 AS ?index) * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_aggregateExpr_04() { final VarNode index = new VarNode("index"); final VarNode o = new VarNode("o"); final IValueExpressionNode mathExpr = FunctionNode.add( o, new ConstantNode(new XSDNumericIV(1))); final ProjectionNode select = new ProjectionNode(); select.addProjectionVar(index); final GroupByNode groupBy = new GroupByNode(); groupBy.addExpr(new AssignmentNode(index, mathExpr)); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * <pre> * SELECT SUM(?x+MIN(?y)) as ?z * GROUP BY ?a * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_nestedAggregates() { final VarNode a = new VarNode("a"); final VarNode x = new VarNode("x"); final VarNode y = new VarNode("y"); final VarNode z = new VarNode("z"); final IValueExpressionNode zExpr = new FunctionNode(FunctionRegistry.SUM, null, FunctionNode.add(x, new FunctionNode( FunctionRegistry.MIN, null, y))); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(z, zExpr)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(a); final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * <pre> * SELECT SUM(?y) as ?x * GROUP BY ?z * HAVING ?x > 10 * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_simpleHavingClause() { final VarNode y = new VarNode("y"); final VarNode x = new VarNode("x"); final VarNode z = new VarNode("z"); final IValueExpressionNode xExpr = new FunctionNode( FunctionRegistry.SUM, null, y); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(x, xExpr)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(z); final HavingNode having = new HavingNode(); having.addExpr(FunctionNode.GT( x, new ConstantNode(new XSDNumericIV(10)) )); new VerifyAggregates(select, groupBy, having); }
/** * <pre> * SELECT SUM(?y) as ?x * GROUP BY ?z * HAVING SUM(?y) > 10 * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_complexHavingClause() { final VarNode y = new VarNode("y"); final VarNode x = new VarNode("x"); final VarNode z = new VarNode("z"); final FunctionNode xExpr = new FunctionNode( FunctionRegistry.SUM, null, y); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(x, xExpr)); final GroupByNode groupBy = new GroupByNode(); groupBy.addGroupByVar(new VarNode(z)); final HavingNode having = new HavingNode(); having.addExpr(FunctionNode.GT( xExpr, new ConstantNode(new XSDNumericIV(10)) )); new VerifyAggregates(select, groupBy, having); }