/** * Return a PROJECTION node. * * @param varNodes * The variables that will appear in the projection. */ protected ProjectionNode projection(final VarNode... varNodes) { // Setup projection. final ProjectionNode projection = new ProjectionNode(); for (VarNode varNode : varNodes) projection.addProjectionVar(varNode); return projection; }
/** * Return a PROJECTION node. * * @param varNodes * The variables that will appear in the projection. */ protected ProjectionNode projection(final VarNode... varNodes) { // Setup projection. final ProjectionNode projection = new ProjectionNode(); for (VarNode varNode : varNodes) projection.addProjectionVar(varNode); return projection; }
/** * Return a PROJECTION node. * * @param varNodes * The variables that will appear in the projection. */ protected ProjectionNode projection(final VarNode... varNodes) { // Setup projection. final ProjectionNode projection = new ProjectionNode(); for (VarNode varNode : varNodes) projection.addProjectionVar(varNode); return projection; }
/** * 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 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 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); }
/** * Unit test for simple SELECT query * * <pre> * SELECT ?s where {?s ?p ?o} * </pre> */ public void test_select_s_where_s_p_o() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ?s where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { { final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(PrefixDeclProcessor.defaultDecls); expected.setPrefixDecls(prefixDecls); } final ProjectionNode projection = new ProjectionNode(); projection.addProjectionVar(new VarNode("s")); expected.setProjection(projection); final JoinGroupNode whereClause = new JoinGroupNode(); whereClause.addChild(new StatementPatternNode(new VarNode("s"), new VarNode("p"), new VarNode("o"), null/* c */, Scope.DEFAULT_CONTEXTS)); expected.setWhereClause(whereClause); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected, actual); }
/** * Unit test for SELECT query with a wildcard (<code>*</code>). * * <pre> * SELECT * where {?s ?p ?o} * </pre> */ public void test_select_star() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select * where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { { final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(PrefixDeclProcessor.defaultDecls); expected.setPrefixDecls(prefixDecls); } final ProjectionNode projection = new ProjectionNode(); projection.addProjectionVar(new VarNode("*")); expected.setProjection(projection); final JoinGroupNode whereClause = new JoinGroupNode(); whereClause.addChild(new StatementPatternNode(new VarNode("s"), new VarNode("p"), new VarNode("o"), null/* c */, Scope.DEFAULT_CONTEXTS)); expected.setWhereClause(whereClause); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected, actual); }
/** * Unit test for simple triple pattern in the default context consisting of * three variables. * * <pre> * SELECT ?s where {?s ?p ?o} * </pre> */ public void test_triple_pattern_var_var_var() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ?s where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { { final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(PrefixDeclProcessor.defaultDecls); expected.setPrefixDecls(prefixDecls); } final ProjectionNode projection = new ProjectionNode(); projection.addProjectionVar(new VarNode("s")); expected.setProjection(projection); final JoinGroupNode whereClause = new JoinGroupNode(); whereClause.addChild(new StatementPatternNode(new VarNode("s"), new VarNode("p"), new VarNode("o"), null/* c */, Scope.DEFAULT_CONTEXTS)); expected.setWhereClause(whereClause); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected, actual); }
projection.addProjectionVar(new VarNode("s")); projection.setDistinct(true); expected.setProjection(projection);
/** * 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 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); }
/** * Unit test for simple SELECT query * * <pre> * SELECT ?s where {?s ?p ?o} * </pre> */ public void test_select_s_where_s_p_o() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ?s where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { { final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(PrefixDeclProcessor.defaultDecls); expected.setPrefixDecls(prefixDecls); } final ProjectionNode projection = new ProjectionNode(); projection.addProjectionVar(new VarNode("s")); expected.setProjection(projection); final JoinGroupNode whereClause = new JoinGroupNode(); whereClause.addChild(new StatementPatternNode(new VarNode("s"), new VarNode("p"), new VarNode("o"), null/* c */, Scope.DEFAULT_CONTEXTS)); expected.setWhereClause(whereClause); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected, actual); }
/** * Unit test for SELECT query with a wildcard (<code>*</code>). * * <pre> * SELECT * where {?s ?p ?o} * </pre> */ public void test_select_star() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select * where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { { final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(PrefixDeclProcessor.defaultDecls); expected.setPrefixDecls(prefixDecls); } final ProjectionNode projection = new ProjectionNode(); projection.addProjectionVar(new VarNode("*")); expected.setProjection(projection); final JoinGroupNode whereClause = new JoinGroupNode(); whereClause.addChild(new StatementPatternNode(new VarNode("s"), new VarNode("p"), new VarNode("o"), null/* c */, Scope.DEFAULT_CONTEXTS)); expected.setWhereClause(whereClause); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected, actual); }
/** * Unit test for simple triple pattern in the default context consisting of * three variables. * * <pre> * SELECT ?s where {?s ?p ?o} * </pre> */ public void test_triple_pattern_var_var_var() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ?s where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { { final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(PrefixDeclProcessor.defaultDecls); expected.setPrefixDecls(prefixDecls); } final ProjectionNode projection = new ProjectionNode(); projection.addProjectionVar(new VarNode("s")); expected.setProjection(projection); final JoinGroupNode whereClause = new JoinGroupNode(); whereClause.addChild(new StatementPatternNode(new VarNode("s"), new VarNode("p"), new VarNode("o"), null/* c */, Scope.DEFAULT_CONTEXTS)); expected.setWhereClause(whereClause); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected, actual); }
projection.addProjectionVar(new VarNode("s")); projection.setDistinct(true); expected.setProjection(projection);
projection.addProjectionVar(new VarNode("s")); projection.setReduced(true); expected.setProjection(projection);