use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class BindingSetStringConverterTest method fromString_nullValues.
/**
* Ensures that when a binding set is converted from a String back to a
* BindingSet, null values do not get converted into Bindings.
*/
@Test
public void fromString_nullValues() throws BindingSetConversionException {
// Setup the String that will be converted.
final String bindingSetString = "http://value 1<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" + BindingSetStringConverter.NULL_VALUE_STRING + ":::" + "http://value 2<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" + BindingSetStringConverter.NULL_VALUE_STRING;
// Convert it to a BindingSet
final VariableOrder varOrder = new VariableOrder("x", "a", "y", "b");
final BindingSetConverter<String> converter = new BindingSetStringConverter();
final BindingSet bindingSet = converter.convert(bindingSetString, varOrder);
// Ensure it converted to the expected reuslt.
final MapBindingSet expected = new MapBindingSet();
expected.addBinding("x", new URIImpl("http://value 1"));
expected.addBinding("y", new URIImpl("http://value 2"));
assertEquals(expected, bindingSet);
}
use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class BindingSetStringConverterTest method noBindings.
@Test
public void noBindings() throws BindingSetConversionException {
// Create a BindingSet that doesn't have any bindings.
final MapBindingSet original = new MapBindingSet();
// Convert it to a String.
final VariableOrder varOrder = new VariableOrder();
final BindingSetConverter<String> converter = new BindingSetStringConverter();
final String bindingSetString = converter.convert(original, varOrder);
// Convert it back to a binding set.
final BindingSet converted = converter.convert(bindingSetString, varOrder);
// Ensure it is still an empty BindingSet.
assertEquals(original, converted);
}
use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class BindingSetStringConverterTest method toString_Decimal.
@Test
public void toString_Decimal() throws BindingSetConversionException {
// Setup the binding set that will be converted.
final MapBindingSet originalBindingSet = new MapBindingSet();
originalBindingSet.addBinding("x", new DecimalLiteralImpl(new BigDecimal(2.5)));
// Convert it to a String.
final VariableOrder varOrder = new VariableOrder("x");
final BindingSetConverter<String> converter = new BindingSetStringConverter();
final String bindingSetString = converter.convert(originalBindingSet, varOrder);
// Ensure it converted to the expected result.
final String expected = "2.5<<~>>http://www.w3.org/2001/XMLSchema#decimal";
assertEquals(expected, bindingSetString);
}
use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class PcjTablesIT method addResults.
/**
* Ensure when results have been written to the PCJ table that they are in Accumulo.
* <p>
* The method being tested is {@link PcjTables#addResults(Connector, String, java.util.Collection)}
*/
@Test
public void addResults() throws PcjException, TableNotFoundException, BindingSetConversionException, AccumuloException, AccumuloSecurityException {
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final Connector accumuloConn = cluster.getConnector();
// Create a PCJ table in the Mini Accumulo.
final String pcjTableName = new PcjTableNameFactory().makeTableName(getRyaInstanceName(), "testPcj");
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(new VariableOrder("name;age"));
final PcjTables pcjs = new PcjTables();
pcjs.createPcjTable(accumuloConn, pcjTableName, varOrders, sparql);
// Add a few results to the PCJ table.
final MapBindingSet alice = new MapBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
final MapBindingSet bob = new MapBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
final MapBindingSet charlie = new MapBindingSet();
charlie.addBinding("name", new URIImpl("http://Charlie"));
charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
final Set<BindingSet> results = Sets.<BindingSet>newHashSet(alice, bob, charlie);
pcjs.addResults(accumuloConn, pcjTableName, Sets.<VisibilityBindingSet>newHashSet(new VisibilityBindingSet(alice), new VisibilityBindingSet(bob), new VisibilityBindingSet(charlie)));
// Make sure the cardinality was updated.
final PcjMetadata metadata = pcjs.getPcjMetadata(accumuloConn, pcjTableName);
assertEquals(3, metadata.getCardinality());
// Scan Accumulo for the stored results.
final Multimap<String, BindingSet> fetchedResults = loadPcjResults(accumuloConn, pcjTableName);
// Ensure the expected results match those that were stored.
final Multimap<String, BindingSet> expectedResults = HashMultimap.create();
expectedResults.putAll("name;age", results);
expectedResults.putAll("age;name", results);
assertEquals(expectedResults, fetchedResults);
}
use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class PcjTablesIT method purge.
@Test
public void purge() throws PCJStorageException, AccumuloException, AccumuloSecurityException {
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final Connector accumuloConn = cluster.getConnector();
// Create a PCJ table in the Mini Accumulo.
final String pcjTableName = new PcjTableNameFactory().makeTableName(getRyaInstanceName(), "testPcj");
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(new VariableOrder("name;age"));
final PcjTables pcjs = new PcjTables();
pcjs.createPcjTable(accumuloConn, pcjTableName, varOrders, sparql);
// Add a few results to the PCJ table.
final MapBindingSet alice = new MapBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
final MapBindingSet bob = new MapBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
final MapBindingSet charlie = new MapBindingSet();
charlie.addBinding("name", new URIImpl("http://Charlie"));
charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
pcjs.addResults(accumuloConn, pcjTableName, Sets.<VisibilityBindingSet>newHashSet(new VisibilityBindingSet(alice), new VisibilityBindingSet(bob), new VisibilityBindingSet(charlie)));
// Make sure the cardinality was updated.
PcjMetadata metadata = pcjs.getPcjMetadata(accumuloConn, pcjTableName);
assertEquals(3, metadata.getCardinality());
// Purge the data.
pcjs.purgePcjTable(accumuloConn, pcjTableName);
// Make sure the cardinality was updated to 0.
metadata = pcjs.getPcjMetadata(accumuloConn, pcjTableName);
assertEquals(0, metadata.getCardinality());
}
Aggregations