/** * 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 assignmentNodes * The BIND()s that will appear in the projection. */ protected ProjectionNode projection(final AssignmentNode... assignmentNodes) { // Setup projection. final ProjectionNode projection = new ProjectionNode(); for (AssignmentNode varNode : assignmentNodes) projection.addProjectionExpression(varNode); return projection; }
/** * Return a PROJECTION node. * * @param assignmentNodes * The BIND()s that will appear in the projection. */ protected ProjectionNode projection(final AssignmentNode... assignmentNodes) { // Setup projection. final ProjectionNode projection = new ProjectionNode(); for (AssignmentNode varNode : assignmentNodes) projection.addProjectionExpression(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; }
/** * Return a PROJECTION node. * * @param assignmentNodes * The BIND()s that will appear in the projection. */ protected ProjectionNode projection(final AssignmentNode... assignmentNodes) { // Setup projection. final ProjectionNode projection = new ProjectionNode(); for (AssignmentNode varNode : assignmentNodes) projection.addProjectionExpression(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 with simple aggregate function in SELECT clause and no GROUP BY * clause (the aggregation is taken across all solutions as if they were a * single group). * * <pre> * SELECT SUM(?lprice) AS ?totalPrice * </pre> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void test_simpleAggregate_noGroupBy() { 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.addProjectionExpression(new AssignmentNode(totalPrice, totalPriceExprNode)); final GroupByNode groupBy = null; final HavingNode having = null; new VerifyAggregates(select, groupBy, having); }
/** * Unit test when projecting a constant * <pre> * SELECT 12 as ?x * </pre> */ public void test_with_constant() { @SuppressWarnings({ "unchecked", "rawtypes" }) final VarNode x = new VarNode("x"); @SuppressWarnings({ "rawtypes", "unchecked" }) final ConstantNode xExpr = new ConstantNode( new XSDNumericIV(12)); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(x, xExpr)); final GroupByNode groupBy = null; 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); }
/** * Simple unit test for a value expression which is a URI. */ public void test_select_uri() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ( <http://xmlns.com/foaf/0.1/> as ?x) where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { final ProjectionNode projection = new ProjectionNode(); projection.addProjectionExpression(// new AssignmentNode(// new VarNode("x"), // new ConstantNode(makeIV(valueFactory .createURI("http://xmlns.com/foaf/0.1/"))))); expected.setProjection(projection); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected.getProjection(), actual.getProjection()); }
/** * Simple unit test for a value expression which is a plain literal. */ public void test_select_literal() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select (\"abc\" as ?x) where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { final ProjectionNode projection = new ProjectionNode(); projection.addProjectionExpression(// new AssignmentNode(// new VarNode("x"), // new ConstantNode(makeIV(valueFactory .createLiteral("abc"))))); expected.setProjection(projection); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected.getProjection(), actual.getProjection()); }
/** * Simple unit test for a value expression which is a <code>xsd:int</code>. */ public void test_select_xsd_int() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select (\"12\"^^<http://www.w3.org/2001/XMLSchema#int> as ?x) where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { final ProjectionNode projection = new ProjectionNode(); projection.addProjectionExpression(// new AssignmentNode(// new VarNode("x"), // new ConstantNode(makeIV(valueFactory .createLiteral(12))))); expected.setProjection(projection); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected.getProjection(), actual.getProjection()); }
/** * Unit test when projecting a constant * <pre> * SELECT 12 as ?x * </pre> */ public void test_with_constant() { @SuppressWarnings({ "unchecked", "rawtypes" }) final VarNode x = new VarNode("x"); @SuppressWarnings({ "rawtypes", "unchecked" }) final ConstantNode xExpr = new ConstantNode( new XSDNumericIV(12)); final ProjectionNode select = new ProjectionNode(); select.addExpr(new AssignmentNode(x, xExpr)); final GroupByNode groupBy = null; 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); }
/** * <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); }
/** * Simple unit test for a value expression which is a plain literal. */ public void test_select_literal() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select (\"abc\" as ?x) where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { final ProjectionNode projection = new ProjectionNode(); projection.addProjectionExpression(// new AssignmentNode(// new VarNode("x"), // new ConstantNode(makeIV(valueFactory .createLiteral("abc"))))); expected.setProjection(projection); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected.getProjection(), actual.getProjection()); }
/** * Simple unit test for a value expression which is a <code>xsd:int</code>. */ public void test_select_xsd_int() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select (\"12\"^^<http://www.w3.org/2001/XMLSchema#int> as ?x) where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { final ProjectionNode projection = new ProjectionNode(); projection.addProjectionExpression(// new AssignmentNode(// new VarNode("x"), // new ConstantNode(makeIV(valueFactory .createLiteral(12))))); expected.setProjection(projection); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected.getProjection(), actual.getProjection()); }
/** * Simple unit test for a value expression which is a URI. */ public void test_select_uri() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "select ( <http://xmlns.com/foaf/0.1/> as ?x) where {?s ?p ?o}"; final QueryRoot expected = new QueryRoot(QueryType.SELECT); { final ProjectionNode projection = new ProjectionNode(); projection.addProjectionExpression(// new AssignmentNode(// new VarNode("x"), // new ConstantNode(makeIV(valueFactory .createURI("http://xmlns.com/foaf/0.1/"))))); expected.setProjection(projection); } final QueryRoot actual = parse(sparql, baseURI); assertSameAST(sparql, expected.getProjection(), actual.getProjection()); }