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) {
// ?? 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 TransformElementLib method applyVar.
public static Var applyVar(Var v, ExprTransform exprTransform) {
if (exprTransform == null)
return v;
ExprVar expr = new ExprVar(v);
Expr e = exprTransform.transform(expr);
if (e instanceof ExprVar)
return ((ExprVar) e).asVar();
throw new InternalErrorException("Managed to turn a variable " + v + " into " + e);
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class TestQueryIterSort method setup.
@Before
public void setup() {
random = new Random();
Var[] vars = new Var[] { Var.alloc("1"), Var.alloc("2"), Var.alloc("3"), Var.alloc("4"), Var.alloc("5"), Var.alloc("6"), Var.alloc("7"), Var.alloc("8"), Var.alloc("9"), Var.alloc("0") };
unsorted = new ArrayList<>();
for (int i = 0; i < 500; i++) {
unsorted.add(randomBinding(vars));
}
List<SortCondition> conditions = new ArrayList<>();
conditions.add(new SortCondition(new ExprVar("8"), Query.ORDER_ASCENDING));
comparator = new BindingComparator(conditions);
iterator = new CallbackIterator(unsorted.iterator(), 25, null);
iterator.setCallback(new Callback() {
@Override
public void call() {
throw new QueryCancelledException();
}
});
}
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);
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class TestSortedDataBag method testTemporaryFilesAreCleanedUpAfterCompletion.
@Test
public void testTemporaryFilesAreCleanedUpAfterCompletion() {
List<Binding> unsorted = randomBindings(500);
List<SortCondition> conditions = new ArrayList<>();
conditions.add(new SortCondition(new ExprVar("8"), Query.ORDER_ASCENDING));
BindingComparator comparator = new BindingComparator(conditions);
SortedDataBag<Binding> db = new SortedDataBag<>(new ThresholdPolicyCount<Binding>(10), SerializationFactoryFinder.bindingSerializationFactory(), comparator);
List<File> spillFiles = new ArrayList<>();
try {
db.addAll(unsorted);
spillFiles.addAll(db.getSpillFiles());
int count = 0;
for (File file : spillFiles) {
if (file.exists()) {
count++;
}
}
// 500 bindings divided into 50 chunks (49 in files, and 1 in memory)
assertEquals(49, count);
Iterator<Binding> iter = db.iterator();
while (iter.hasNext()) {
iter.next();
}
Iter.close(iter);
} finally {
db.close();
}
int count = 0;
for (File file : spillFiles) {
if (file.exists()) {
count++;
}
}
assertEquals(0, count);
}
Aggregations