use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class TransformQuadGraph method transform.
@Override
public Op transform(OpGraph opGraph, Op op) {
//System.err.println("transform(OpGraph)\n"+opGraph+op) ;
// ?? Could just leave the (graph) in place always - just rewrite BGPs.
boolean noPattern = false;
/* One case to consider is when the pattern for the GRAPH
* statement includes uses the variable inside the GRAPH clause.
* In this case, we must rename away the inner variable
* to allow stream execution via index joins,
* and then put back the value via an assign.
* (This is what QueryIterGraph does using a streaming join
* for triples)
*/
// Note: op is already quads by this point.
// Must test scoping by the subOp of GRAPH
QuadSlot qSlot = tracker.peek();
Node actualName = qSlot.actualGraphName;
Node rewriteName = qSlot.rewriteGraphName;
if (OpBGP.isBGP(op)) {
// Empty BGP
if (((OpBGP) op).getPattern().isEmpty())
noPattern = true;
} else if (op instanceof OpTable) {
// Empty BGP compiled to a unit table
if (((OpTable) op).isJoinIdentity())
noPattern = true;
}
if (noPattern) {
// which are ways of accessing the names in the dataset.
return new OpDatasetNames(opGraph.getNode());
}
if (actualName != rewriteName)
op = OpAssign.assign(op, Var.alloc(actualName), new ExprVar(rewriteName));
// have been converted to quads.
return op;
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class TestUserDefinedFunctionFactory method test_user_defined_function_factory_add_02.
@Test
public void test_user_defined_function_factory_add_02() {
Expr e1 = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
Expr e2 = new E_Multiply(new ExprVar("y"), new ExprVar("y"));
UserDefinedFunctionFactory.getFactory().add("http://example/square", e1, new ArrayList<>(e1.getVarsMentioned()));
Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
Assert.assertEquals(e1, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
UserDefinedFunctionFactory.getFactory().add("http://example/square", e2, new ArrayList<>(e2.getVarsMentioned()));
Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
Assert.assertEquals(e2, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class TestUserDefinedFunctionFactory method test_user_defined_function_factory_add_01.
@Test
public void test_user_defined_function_factory_add_01() {
Expr e = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
UserDefinedFunctionFactory.getFactory().add("http://example/square", e, new ArrayList<>(e.getVarsMentioned()));
Assert.assertTrue(UserDefinedFunctionFactory.getFactory().isRegistered("http://example/square"));
Assert.assertEquals(e, UserDefinedFunctionFactory.getFactory().get("http://example/square").getBaseExpr());
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class TestUserFunctionsInSparql method setup.
@BeforeClass
public static void setup() {
UserDefinedFunctionFactory.getFactory().clear();
//Define a square function
Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<>(square.getVarsMentioned()));
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class TestSortedDataBag method testSorting.
private void testSorting(int numBindings, int threshold) {
List<Binding> unsorted = randomBindings(numBindings);
List<SortCondition> conditions = new ArrayList<>();
conditions.add(new SortCondition(new ExprVar("8"), Query.ORDER_ASCENDING));
conditions.add(new SortCondition(new ExprVar("1"), Query.ORDER_ASCENDING));
conditions.add(new SortCondition(new ExprVar("0"), Query.ORDER_DESCENDING));
BindingComparator comparator = new BindingComparator(conditions);
List<Binding> sorted = new ArrayList<>();
SortedDataBag<Binding> db = new SortedDataBag<>(new ThresholdPolicyCount<Binding>(threshold), SerializationFactoryFinder.bindingSerializationFactory(), comparator);
try {
db.addAll(unsorted);
Iterator<Binding> iter = db.iterator();
while (iter.hasNext()) {
sorted.add(iter.next());
}
Iter.close(iter);
} finally {
db.close();
}
Collections.sort(unsorted, comparator);
assertEquals(unsorted, sorted);
}
Aggregations