use of org.apache.jena.sparql.core.Var in project jena by apache.
the class TestDistinctDataBag method testTemporaryFilesAreCleanedUpAfterCompletion.
@Test
public void testTemporaryFilesAreCleanedUpAfterCompletion() {
List<Binding> undistinct = new ArrayList<>();
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") };
for (int i = 0; i < 500; i++) {
undistinct.add(randomBinding(vars));
}
DistinctDataBag<Binding> db = new DistinctDataBag<>(new ThresholdPolicyCount<Binding>(10), SerializationFactoryFinder.bindingSerializationFactory(), new BindingComparator(new ArrayList<SortCondition>()));
List<File> spillFiles = new ArrayList<>();
try {
db.addAll(undistinct);
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);
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class TestFunctionExpansion method test_function_expansion_11.
@Test
public void test_function_expansion_11() {
Expr single = new ExprVar("x");
UserDefinedFunctionFactory.getFactory().add("http://example/single", single, new ArrayList<>(single.getVarsMentioned()));
//Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
//when the outer function has differing numbers of arguments
List<Var> args = new ArrayList<>();
args.add(Var.alloc("x"));
args.add(Var.alloc("y"));
Expr add = new E_Add(new E_Function("http://example/single", new ExprList(new ExprVar("y"))), new ExprVar("y"));
UserDefinedFunctionFactory.getFactory().add("http://example/add", add, args);
UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/add");
Expr base = def.getBaseExpr();
Assert.assertTrue(base instanceof E_Add);
E_Add actual = (E_Add) base;
Assert.assertTrue(actual.getArg1() instanceof ExprVar);
Assert.assertTrue(actual.getArg2() instanceof ExprVar);
Assert.assertEquals("y", actual.getArg1().getVarName());
Assert.assertEquals("y", actual.getArg2().getVarName());
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class TestFunctionExpansion method test_function_expansion_10.
@Test
public void test_function_expansion_10() {
Expr single = new ExprVar("x");
UserDefinedFunctionFactory.getFactory().add("http://example/single", single, new ArrayList<>(single.getVarsMentioned()));
//Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
//when the outer function has differing numbers of arguments
List<Var> args = new ArrayList<>();
args.add(Var.alloc("x"));
args.add(Var.alloc("y"));
Expr add = new E_Add(new E_Function("http://example/single", new ExprList(new ExprVar("x"))), new ExprVar("y"));
UserDefinedFunctionFactory.getFactory().add("http://example/add", add, args);
UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/add");
Expr base = def.getBaseExpr();
Assert.assertTrue(base instanceof E_Add);
E_Add actual = (E_Add) base;
Assert.assertTrue(actual.getArg1() instanceof ExprVar);
Assert.assertTrue(actual.getArg2() instanceof ExprVar);
Assert.assertEquals("x", actual.getArg1().getVarName());
Assert.assertEquals("y", actual.getArg2().getVarName());
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class TestFunctionExpansion method test_function_expansion_08.
@Test
public void test_function_expansion_08() {
Expr takeaway = new E_Subtract(new ExprVar("x"), new ExprVar("y"));
List<Var> args = new ArrayList<>();
args.add(Var.alloc("x"));
args.add(Var.alloc("y"));
UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
//Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
ExprList altArgs = new ExprList();
altArgs.add(new ExprVar("a"));
altArgs.add(new ExprVar("b"));
ArrayList<Var> defArgs = new ArrayList<>();
defArgs.add(Var.alloc("a"));
defArgs.add(Var.alloc("b"));
Expr test = new E_Function("http://example/takeaway", altArgs);
UserDefinedFunctionFactory.getFactory().add("http://example/test", test, defArgs);
UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/test");
Expr base = def.getBaseExpr();
Assert.assertTrue(base instanceof E_Subtract);
E_Subtract subtract = (E_Subtract) base;
Assert.assertTrue(subtract.getArg1() instanceof ExprVar);
Assert.assertTrue(subtract.getArg2() instanceof ExprVar);
Assert.assertEquals(subtract.getArg1().getVarName(), "a");
Assert.assertEquals(subtract.getArg2().getVarName(), "b");
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class TestFunctionExpansion method test_function_expansion_06.
@Test
public void test_function_expansion_06() {
Expr takeaway = new E_Subtract(new ExprVar("x"), new ExprVar("y"));
List<Var> args = new ArrayList<>();
args.add(Var.alloc("x"));
args.add(Var.alloc("y"));
UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
//Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
ExprList numArgs = new ExprList();
numArgs.add(new NodeValueInteger(1));
numArgs.add(new NodeValueDouble(2.3));
Expr test = new E_Function("http://example/takeaway", numArgs);
UserDefinedFunctionFactory.getFactory().add("http://example/test", test, new ArrayList<Var>());
UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/test");
Expr base = def.getBaseExpr();
Assert.assertTrue(base instanceof E_Subtract);
E_Subtract subtract = (E_Subtract) base;
Assert.assertTrue(subtract.getArg1() instanceof NodeValueInteger);
Assert.assertTrue(subtract.getArg2() instanceof NodeValueDouble);
}
Aggregations