/** * <code>BIND(expression AS variable)</code> * * @param valueNode * The expression * @param varNode * The variable. */ protected AssignmentNode bind(final IValueExpressionNode valueNode, final VarNode varNode) { return new AssignmentNode(varNode, valueNode); }
/** * <code>BIND(expression AS variable)</code> * * @param valueNode * The expression * @param varNode * The variable. */ protected AssignmentNode bind(final IValueExpressionNode valueNode, final VarNode varNode) { return new AssignmentNode(varNode, valueNode); }
/** * Adds a variable to be projected. The variable is modeled as an assignment * of itself to itself, so everything in the projection node winds up * looking like an assignment. * * @param var * The variable. */ public void addProjectionVar(final VarNode var) { addExpr(new AssignmentNode(var, var)); }
/** * Adds a variable to be projected. The variable is modeled as an assignment * of itself to itself, so everything in the projection node winds up * looking like an assignment. * * @param var * The variable. */ public void addProjectionVar(final VarNode var) { addExpr(new AssignmentNode(var, var)); }
/** * <code>BIND(expression AS variable)</code> * * @param valueNode * The expression * @param varNode * The variable. */ protected AssignmentNode bind(final IValueExpressionNode valueNode, final VarNode varNode) { return new AssignmentNode(varNode, valueNode); }
public void addGroupByVar(final VarNode var) { addExpr(new AssignmentNode(var, var)); }
public void addGroupByVar(final VarNode var) { addExpr(new AssignmentNode(var, var)); }
/** * 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); }
/** * A LET is just an alternative syntax for BIND * * @return The {@link AssignmentNode}. */ @Override final public AssignmentNode visit(final ASTLet node, final Object data) throws VisitorException { if (node.jjtGetNumChildren() != 2) throw new AssertionError("Expecting two children, not " + node.jjtGetNumChildren() + ", node=" + node.dump(">>>")); final ValueExpressionNode ve = (ValueExpressionNode) node .jjtGetChild(1).jjtAccept(this, data); final Node aliasNode = node.jjtGetChild(0); final String alias = ((ASTVar) aliasNode).getName(); final AssignmentNode bind = new AssignmentNode(new VarNode(alias), ve); graphPattern.add(bind); return bind; }
/** * A LET is just an alternative syntax for BIND * * @return The {@link AssignmentNode}. */ @Override final public AssignmentNode visit(final ASTLet node, final Object data) throws VisitorException { if (node.jjtGetNumChildren() != 2) throw new AssertionError("Expecting two children, not " + node.jjtGetNumChildren() + ", node=" + node.dump(">>>")); final ValueExpressionNode ve = (ValueExpressionNode) node .jjtGetChild(1).jjtAccept(this, data); final Node aliasNode = node.jjtGetChild(0); final String alias = ((ASTVar) aliasNode).getName(); final AssignmentNode bind = new AssignmentNode(new VarNode(alias), ve); graphPattern.add(bind); return bind; }
/** * 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); }
/** * 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 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); }
/** * 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()); }