use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class TripleObserver method process.
@Override
public void process(final TransactionBase tx, final Bytes brow, final Column column) {
// Get string representation of triple.
final RyaStatement ryaStatement = IncUpdateDAO.deserializeTriple(brow);
log.trace("Transaction ID: {}\nRya Statement: {}\n", tx.getStartTimestamp(), ryaStatement);
log.trace("Beginging to process triple.");
final String triple = IncUpdateDAO.getTripleString(ryaStatement);
Set<String> spIDs = SP_ID_CACHE.getStatementPatternIds(tx);
// see if triple matches conditions of any of the SP
for (String spID : spIDs) {
// Fetch its metadata.
final StatementPatternMetadata spMetadata = QUERY_METADATA_DAO.readStatementPatternMetadata(tx, spID);
log.trace("Retrieved metadata: {}", spMetadata);
// Attempt to match the triple against the pattern.
final String pattern = spMetadata.getStatementPattern();
final VariableOrder varOrder = spMetadata.getVariableOrder();
final String bindingSetString = getBindingSet(triple, pattern, varOrder);
log.trace("Created binding set match string: {}", bindingSetString);
// Statement matches to a binding set.
if (bindingSetString.length() != 0) {
// Fetch the triple's visibility label.
final String visibility = tx.gets(brow.toString(), FluoQueryColumns.TRIPLES, "");
// Make BindingSet and sharded row
final VisibilityBindingSet visBindingSet = VIS_BS_CONVERTER.convert(bindingSetString, varOrder);
visBindingSet.setVisibility(visibility);
Bytes row = BindingHashShardingFunction.addShard(spID, varOrder, visBindingSet);
// If this is a new Binding Set, then emit it.
if (tx.get(row, FluoQueryColumns.STATEMENT_PATTERN_BINDING_SET) == null) {
try {
final Bytes valueBytes = BS_SERDE.serialize(visBindingSet);
log.trace("Transaction ID: {}\nMatched Statement Pattern: {}\nBinding Set: {}\n", tx.getStartTimestamp(), spID, visBindingSet);
tx.set(row, FluoQueryColumns.STATEMENT_PATTERN_BINDING_SET, valueBytes);
} catch (final Exception e) {
log.error("Couldn't serialize a Binding Set. This value will be skipped.", e);
}
}
}
}
// Once the triple has been handled, it may be deleted.
tx.delete(brow, column);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readAggregationMetadataBuilder.
private AggregationMetadata.Builder readAggregationMetadataBuilder(final SnapshotBase sx, final String nodeId) {
requireNonNull(sx);
requireNonNull(nodeId);
// Fetch the values from the Fluo table.
final String rowId = nodeId;
final Map<Column, String> values = sx.gets(rowId, FluoQueryColumns.AGGREGATION_VARIABLE_ORDER, FluoQueryColumns.AGGREGATION_PARENT_NODE_ID, FluoQueryColumns.AGGREGATION_CHILD_NODE_ID, FluoQueryColumns.AGGREGATION_GROUP_BY_BINDING_NAMES);
// Return an object holding them.
final String varOrderString = values.get(FluoQueryColumns.AGGREGATION_VARIABLE_ORDER);
final VariableOrder varOrder = new VariableOrder(varOrderString);
final String parentNodeId = values.get(FluoQueryColumns.AGGREGATION_PARENT_NODE_ID);
final String childNodeId = values.get(FluoQueryColumns.AGGREGATION_CHILD_NODE_ID);
// Read the Group By variable order if one was present.
final String groupByString = values.get(FluoQueryColumns.AGGREGATION_GROUP_BY_BINDING_NAMES);
final VariableOrder groupByVars = groupByString.isEmpty() ? new VariableOrder() : new VariableOrder(groupByString.split(";"));
// Deserialize the collection of AggregationElements.
final Bytes aggBytes = sx.get(Bytes.of(nodeId.getBytes(Charsets.UTF_8)), FluoQueryColumns.AGGREGATION_AGGREGATIONS);
final Collection<AggregationElement> aggregations;
try (final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(aggBytes.toInputStream())) // // this is how you find classes that you missed in the vois.accept() list, below.
// { @Override protected void invalidClassNameFound(String className) throws java.io.InvalidClassException {
// System.out.println("vois.accept(" + className + ".class, ");};};
{
// These classes are allowed to be deserialized. Others throw InvalidClassException.
vois.accept(java.util.ArrayList.class, java.lang.Enum.class, AggregationElement.class, AggregationType.class);
final Object object = vois.readObject();
if (!(object instanceof Collection<?>)) {
throw new InvalidClassException("Object read was not of type Collection. It was: " + object.getClass());
}
aggregations = (Collection<AggregationElement>) object;
} catch (final IOException | ClassNotFoundException e) {
throw new RuntimeException("Problem encountered while reading AggregationMetadata from the Fluo table. Unable " + "to deserialize the AggregationElements from a byte[].", e);
}
final AggregationMetadata.Builder builder = AggregationMetadata.builder(nodeId).setVarOrder(varOrder).setParentNodeId(parentNodeId).setChildNodeId(childNodeId).setGroupByVariableOrder(groupByVars);
for (final AggregationElement aggregation : aggregations) {
builder.addAggregation(aggregation);
}
return builder;
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readQueryMetadataBuilder.
private QueryMetadata.Builder readQueryMetadataBuilder(final SnapshotBase sx, final String nodeId) {
requireNonNull(sx);
requireNonNull(nodeId);
// Fetch the values from the Fluo table.
final String rowId = nodeId;
final Map<Column, String> values = sx.gets(rowId, FluoQueryColumns.QUERY_VARIABLE_ORDER, FluoQueryColumns.QUERY_SPARQL, FluoQueryColumns.QUERY_TYPE, FluoQueryColumns.QUERY_EXPORT_STRATEGIES, FluoQueryColumns.QUERY_CHILD_NODE_ID);
// Return an object holding them.
final String varOrderString = values.get(FluoQueryColumns.QUERY_VARIABLE_ORDER);
final VariableOrder varOrder = new VariableOrder(varOrderString);
final String sparql = values.get(FluoQueryColumns.QUERY_SPARQL);
final String childNodeId = values.get(FluoQueryColumns.QUERY_CHILD_NODE_ID);
final String queryType = values.get(FluoQueryColumns.QUERY_TYPE);
final String[] exportStrategies = values.get(FluoQueryColumns.QUERY_EXPORT_STRATEGIES).split(IncrementalUpdateConstants.VAR_DELIM);
final Set<ExportStrategy> strategies = new HashSet<>();
for (final String strategy : exportStrategies) {
if (!strategy.isEmpty()) {
strategies.add(ExportStrategy.valueOf(strategy));
}
}
return QueryMetadata.builder(nodeId).setVarOrder(varOrder).setSparql(sparql).setExportStrategies(strategies).setQueryType(QueryType.valueOf(queryType)).setChildNodeId(childNodeId);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readFilterMetadataBuilder.
private FilterMetadata.Builder readFilterMetadataBuilder(final SnapshotBase sx, final String nodeId) {
requireNonNull(sx);
requireNonNull(nodeId);
// Fetch the values from the Fluo table.
final String rowId = nodeId;
final Map<Column, String> values = sx.gets(rowId, FluoQueryColumns.FILTER_VARIABLE_ORDER, FluoQueryColumns.FILTER_SPARQL, FluoQueryColumns.FILTER_PARENT_NODE_ID, FluoQueryColumns.FILTER_CHILD_NODE_ID);
// Return an object holding them.
final String varOrderString = values.get(FluoQueryColumns.FILTER_VARIABLE_ORDER);
final VariableOrder varOrder = new VariableOrder(varOrderString);
final String originalSparql = values.get(FluoQueryColumns.FILTER_SPARQL);
final String parentNodeId = values.get(FluoQueryColumns.FILTER_PARENT_NODE_ID);
final String childNodeId = values.get(FluoQueryColumns.FILTER_CHILD_NODE_ID);
return FilterMetadata.builder(nodeId).setVarOrder(varOrder).setFilterSparql(originalSparql).setParentNodeId(parentNodeId).setChildNodeId(childNodeId);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder 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();
}
Aggregations