use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class AccumuloDocIdIndexer method deserializeKey.
private QueryBindingSet deserializeKey(final Key key, final StarQuery sq, final BindingSet currentBs, final Set<String> unCommonVar) {
final QueryBindingSet currentSolutionBs = new QueryBindingSet();
final Text row = key.getRow();
final Text cq = key.getColumnQualifier();
final String[] cqArray = cq.toString().split(DocIndexIteratorUtil.DOC_ID_INDEX_DELIM);
boolean commonVarSet = false;
// if common Var is constant there is no common variable to assign a value to
if (sq.commonVarConstant()) {
commonVarSet = true;
}
if (!commonVarSet && sq.isCommonVarURI()) {
final RyaURI rURI = new RyaURI(row.toString());
currentSolutionBs.addBinding(sq.getCommonVarName(), RyaToRdfConversions.convertValue(rURI));
commonVarSet = true;
}
for (final String s : sq.getUnCommonVars()) {
final byte[] cqBytes = cqArray[sq.getVarPos().get(s)].getBytes(StandardCharsets.UTF_8);
final int firstIndex = Bytes.indexOf(cqBytes, DELIM_BYTE);
final int secondIndex = Bytes.lastIndexOf(cqBytes, DELIM_BYTE);
final int typeIndex = Bytes.indexOf(cqBytes, TYPE_DELIM_BYTE);
final String tripleComponent = new String(Arrays.copyOfRange(cqBytes, firstIndex + 1, secondIndex), StandardCharsets.UTF_8);
final byte[] cqContent = Arrays.copyOfRange(cqBytes, secondIndex + 1, typeIndex);
final byte[] objType = Arrays.copyOfRange(cqBytes, typeIndex, cqBytes.length);
if (tripleComponent.equals("object")) {
final byte[] object = Bytes.concat(cqContent, objType);
org.openrdf.model.Value v = null;
try {
v = RyaToRdfConversions.convertValue(RyaContext.getInstance().deserialize(object));
} catch (final RyaTypeResolverException e) {
e.printStackTrace();
}
currentSolutionBs.addBinding(s, v);
} else if (tripleComponent.equals("subject")) {
if (!commonVarSet) {
final byte[] object = Bytes.concat(row.getBytes(), objType);
org.openrdf.model.Value v = null;
try {
v = RyaToRdfConversions.convertValue(RyaContext.getInstance().deserialize(object));
} catch (final RyaTypeResolverException e) {
e.printStackTrace();
}
currentSolutionBs.addBinding(sq.getCommonVarName(), v);
commonVarSet = true;
}
final RyaURI rURI = new RyaURI(new String(cqContent, StandardCharsets.UTF_8));
currentSolutionBs.addBinding(s, RyaToRdfConversions.convertValue(rURI));
} else {
throw new IllegalArgumentException("Invalid row.");
}
}
for (final String s : unCommonVar) {
currentSolutionBs.addBinding(s, currentBs.getValue(s));
}
return currentSolutionBs;
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class ConstructProjectionTest method testConstructProjectionProjectSubj.
@Test
public void testConstructProjectionProjectSubj() throws MalformedQueryException, UnsupportedEncodingException {
String query = "select ?x where { ?x <uri:talksTo> <uri:Bob> }";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
ConstructProjection projection = new ConstructProjection(patterns.get(0));
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", vf.createURI("uri:Joe"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO");
RyaStatement statement = projection.projectBindingSet(vBs, new HashMap<>());
RyaStatement expected = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaURI("uri:Bob"));
expected.setColumnVisibility("FOUO".getBytes("UTF-8"));
expected.setTimestamp(statement.getTimestamp());
assertEquals(expected, statement);
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class ConstructProjectionTest method testConstructProjectionBNodes.
@Test
public void testConstructProjectionBNodes() throws MalformedQueryException {
String query = "select ?o where { _:b <uri:talksTo> ?o }";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
ConstructProjection projection = new ConstructProjection(patterns.get(0));
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("o", vf.createURI("uri:Bob"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
BNode bNode = vf.createBNode();
Map<String, BNode> bNodeMap = new HashMap<>();
bNodeMap.put("-anon-1", bNode);
RyaStatement statement = projection.projectBindingSet(vBs, bNodeMap);
RyaStatement expected = new RyaStatement(RdfToRyaConversions.convertResource(bNode), new RyaURI("uri:talksTo"), new RyaURI("uri:Bob"));
expected.setTimestamp(statement.getTimestamp());
expected.setColumnVisibility(new byte[0]);
assertEquals(expected, statement);
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class BatchInformationSerializerTest method testJoinBatchInformationSerialization.
@Test
public void testJoinBatchInformationSerialization() {
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("a", new URIImpl("urn:123"));
bs.addBinding("b", new URIImpl("urn:456"));
VisibilityBindingSet vBis = new VisibilityBindingSet(bs, "FOUO");
JoinBatchInformation batch = JoinBatchInformation.builder().setBatchSize(1000).setTask(Task.Update).setColumn(FluoQueryColumns.PERIODIC_QUERY_BINDING_SET).setSpan(Span.prefix(Bytes.of("prefix346"))).setJoinType(JoinType.LEFT_OUTER_JOIN).setSide(Side.RIGHT).setBs(vBis).build();
byte[] batchBytes = BatchInformationSerializer.toBytes(batch);
Optional<BatchInformation> decodedBatch = BatchInformationSerializer.fromBytes(batchBytes);
assertEquals(batch, decodedBatch.get());
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class BindingHashShardingFunctionTest method bindingSetRowTest.
@Test
public void bindingSetRowTest() {
String nodeId = NodeType.generateNewFluoIdForType(NodeType.STATEMENT_PATTERN);
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("entity", vf.createURI("urn:entity"));
bs.addBinding("location", vf.createLiteral("location_1"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
VariableOrder varOrder = new VariableOrder("entity", "location");
Bytes row = RowKeyUtil.makeRowKey(nodeId, varOrder, vBs);
Bytes shardedRow = BindingHashShardingFunction.addShard(nodeId, varOrder, vBs);
BindingSetRow expected = BindingSetRow.make(row);
BindingSetRow actual = BindingSetRow.makeFromShardedRow(Bytes.of(SP_PREFIX), shardedRow);
Assert.assertEquals(expected, actual);
}
Aggregations