use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class JoinBatchInformationTypeAdapter method deserialize.
@Override
public JoinBatchInformation deserialize(final JsonElement element, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
final JsonObject json = element.getAsJsonObject();
final int batchSize = json.get("batchSize").getAsInt();
final Task task = Task.valueOf(json.get("task").getAsString());
final String[] colArray = json.get("column").getAsString().split("\u0000");
final Column column = new Column(colArray[0], colArray[1]);
final String[] rows = json.get("span").getAsString().split("\u0000");
final boolean startInc = json.get("startInc").getAsBoolean();
final boolean endInc = json.get("endInc").getAsBoolean();
final Span span = new Span(new RowColumn(rows[0]), startInc, new RowColumn(rows[1]), endInc);
final VariableOrder updateVarOrder = new VariableOrder(json.get("updateVarOrder").getAsString());
final VisibilityBindingSet bs = converter.convert(json.get("bindingSet").getAsString(), updateVarOrder);
final Side side = Side.valueOf(json.get("side").getAsString());
final JoinType join = JoinType.valueOf(json.get("joinType").getAsString());
return JoinBatchInformation.builder().setBatchSize(batchSize).setTask(task).setSpan(span).setColumn(column).setBs(bs).setSide(side).setJoinType(join).build();
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class ExporterManager method exportBindingSet.
/**
* Exports BindingSet using the exporters for a given {@link QueryType}.
* @param exporters - exporters corresponding to a given queryType
* @param strategies - export strategies used to export results (possibly a subset of those in the exporters map)
* @param pcjId - id of the query whose results are being exported
* @param data - serialized BindingSet result
* @throws ResultExportException
*/
private void exportBindingSet(final Map<ExportStrategy, IncrementalResultExporter> exporters, final Set<ExportStrategy> strategies, final String pcjId, final Bytes data) throws ResultExportException {
VisibilityBindingSet bs;
try {
bs = BS_SERDE.deserialize(data);
simplifyVisibilities(bs);
} catch (final Exception e) {
throw new ResultExportException("Unable to deserialize the given BindingSet.", e);
}
try {
for (final ExportStrategy strategy : strategies) {
final IncrementalBindingSetExporter exporter = (IncrementalBindingSetExporter) exporters.get(strategy);
exporter.export(pcjId, bs);
}
} catch (final Exception e) {
throw new ResultExportException("Unable to export the given BindingSet " + bs + " with the given set of ExportStrategies " + strategies, e);
}
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class KafkaLatencyBenchmark method updateStatsFromKafka.
private void updateStatsFromKafka(final String topic) {
try (KafkaConsumer<String, VisibilityBindingSet> consumer = new KafkaConsumer<>(options.getKafkaConsumerProperties(), new StringDeserializer(), new KryoVisibilityBindingSetSerializer())) {
consumer.subscribe(Arrays.asList(topic));
while (!futureList.isEmpty()) {
// check kafka at most twice a second.
final ConsumerRecords<String, VisibilityBindingSet> records = consumer.poll(500);
handle(records);
}
} catch (final Exception e) {
logger.warn("Exception occurred", e);
}
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class JoinObserver method parseObservation.
@Override
public Observation parseObservation(final TransactionBase tx, final Bytes row) throws Exception {
requireNonNull(tx);
requireNonNull(row);
// Read the Join metadata.
final String joinNodeId = BindingSetRow.makeFromShardedRow(Bytes.of(JOIN_PREFIX), row).getNodeId();
final JoinMetadata joinMetadata = queryDao.readJoinMetadata(tx, joinNodeId);
// Read the Visibility Binding Set from the value.
final Bytes valueBytes = tx.get(row, FluoQueryColumns.JOIN_BINDING_SET);
final VisibilityBindingSet joinBindingSet = BS_SERDE.deserialize(valueBytes);
// Figure out which node needs to handle the new metadata.
final String parentNodeId = joinMetadata.getParentNodeId();
return new Observation(joinNodeId, joinBindingSet, parentNodeId);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class BindingHashShardingFunctionTest method shardAddAndRemoveTest.
@Test
public void shardAddAndRemoveTest() {
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);
Bytes shardlessRow = BindingHashShardingFunction.removeHash(Bytes.of(SP_PREFIX), shardedRow);
Assert.assertEquals(row, shardlessRow);
}
Aggregations