Search in sources :

Example 66 with VisibilityBindingSet

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();
}
Also used : Task(org.apache.rya.indexing.pcj.fluo.app.batch.BatchInformation.Task) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) RowColumn(org.apache.fluo.api.data.RowColumn) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) JsonObject(com.google.gson.JsonObject) JoinType(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata.JoinType) Span(org.apache.fluo.api.data.Span) Side(org.apache.rya.api.function.join.LazyJoiningIterator.Side) RowColumn(org.apache.fluo.api.data.RowColumn) Column(org.apache.fluo.api.data.Column)

Example 67 with VisibilityBindingSet

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);
    }
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ExportStrategy(org.apache.rya.api.client.CreatePCJ.ExportStrategy) ResultExportException(org.apache.rya.indexing.pcj.fluo.app.export.IncrementalBindingSetExporter.ResultExportException) ResultExportException(org.apache.rya.indexing.pcj.fluo.app.export.IncrementalBindingSetExporter.ResultExportException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 68 with VisibilityBindingSet

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);
    }
}
Also used : KryoVisibilityBindingSetSerializer(org.apache.rya.indexing.pcj.fluo.app.export.kafka.KryoVisibilityBindingSetSerializer) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) ParameterException(com.beust.jcommander.ParameterException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) RyaClientException(org.apache.rya.api.client.RyaClientException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 69 with VisibilityBindingSet

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);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) JoinMetadata(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata)

Example 70 with VisibilityBindingSet

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);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Aggregations

VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)140 Test (org.junit.Test)105 MapBindingSet (org.openrdf.query.impl.MapBindingSet)93 ValueFactory (org.openrdf.model.ValueFactory)66 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)66 HashSet (java.util.HashSet)52 ArrayList (java.util.ArrayList)31 UUID (java.util.UUID)28 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)28 TopologyFactory (org.apache.rya.streams.kafka.topology.TopologyFactory)24 BindingSet (org.openrdf.query.BindingSet)24 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)23 RandomUUIDFactory (org.apache.rya.api.function.projection.RandomUUIDFactory)23 URIImpl (org.openrdf.model.impl.URIImpl)19 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)19 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)18 Bytes (org.apache.fluo.api.data.Bytes)16 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)15 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)12 Statement (org.openrdf.model.Statement)12