use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class PcjDocumentsIntegrationTest method createPcjTable.
/**
* Ensure that when a new PCJ table is created, it is initialized with the
* correct metadata values.
* <p>
* The method being tested is {@link PcjTables#createPcjTable(Connector, String, Set, String)}
*/
@Test
public void createPcjTable() throws PcjException, AccumuloException, AccumuloSecurityException {
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = "testPcj";
final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
pcjs.createPcj(pcjTableName, sparql);
// Fetch the PcjMetadata and ensure it has the correct values.
final PcjMetadata pcjMetadata = pcjs.getPcjMetadata(pcjTableName);
// Ensure the metadata matches the expected value.
final PcjMetadata expected = new PcjMetadata(sparql, 0L, Sets.newHashSet(new VariableOrder("name", "age"), new VariableOrder("age", "name")));
assertEquals(expected, pcjMetadata);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class AggregationResultUpdater method updateAggregateResults.
/**
* Updates the results of an Aggregation node where its child has emitted a new Binding Set.
*
* @param tx - The transaction all Fluo queries will use. (not null)
* @param childBindingSet - The Binding Set that was omitted by the Aggregation Node's child. (not null)
* @param aggregationMetadata - The metadata of the Aggregation node whose results will be updated. (not null)
* @throws Exception The update could not be successfully performed.
*/
public void updateAggregateResults(final TransactionBase tx, final VisibilityBindingSet childBindingSet, final AggregationMetadata aggregationMetadata) throws Exception {
requireNonNull(tx);
requireNonNull(childBindingSet);
requireNonNull(aggregationMetadata);
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "Child Binding Set:\n" + childBindingSet + "\n");
// The Row ID for the Aggregation State that needs to be updated is defined by the Group By variables.
final String aggregationNodeId = aggregationMetadata.getNodeId();
final VariableOrder groupByVars = aggregationMetadata.getGroupByVariableOrder();
final Bytes rowId = makeRowKey(aggregationNodeId, groupByVars, childBindingSet);
// Load the old state from the bytes if one was found; otherwise initialize the state.
final Optional<Bytes> stateBytes = Optional.ofNullable(tx.get(rowId, FluoQueryColumns.AGGREGATION_BINDING_SET));
final AggregationState state;
if (stateBytes.isPresent()) {
// Deserialize the old state
final byte[] bytes = stateBytes.get().toArray();
state = AGG_STATE_SERDE.deserialize(bytes);
} else {
// Initialize a new state.
state = new AggregationState();
// If we have group by bindings, their values need to be added to the state's binding set.
final MapBindingSet bindingSet = state.getBindingSet();
for (final String variable : aggregationMetadata.getGroupByVariableOrder()) {
bindingSet.addBinding(childBindingSet.getBinding(variable));
}
}
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "Before Update: " + LogUtils.clean(state.getBindingSet().toString()) + "\n");
// Update the visibilities of the result binding set based on the child's visibilities.
final String oldVisibility = state.getVisibility();
final String updateVisibilities = VisibilitySimplifier.unionAndSimplify(oldVisibility, childBindingSet.getVisibility());
state.setVisibility(updateVisibilities);
// Update the Aggregation State with each Aggregation function included within this group.
for (final AggregationElement aggregation : aggregationMetadata.getAggregations()) {
final AggregationType type = aggregation.getAggregationType();
final AggregationFunction function = FUNCTIONS.get(type);
if (function == null) {
throw new RuntimeException("Unrecognized aggregation function: " + type);
}
function.update(aggregation, state, childBindingSet);
}
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "After Update:" + LogUtils.clean(state.getBindingSet().toString()) + "\n");
// Store the updated state. This will write on top of any old state that was present for the Group By values.
tx.set(rowId, FluoQueryColumns.AGGREGATION_BINDING_SET, Bytes.of(AGG_STATE_SERDE.serialize(state)));
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class QueryResultUpdater method updateQueryResults.
/**
* Updates the results of a Query node when one of its children has added a
* new Binding Set to its results.
*
* @param tx - The transaction all Fluo queries will use. (not null)
* @param childBindingSet - A binding set that the query's child node has emmitted. (not null)
* @param queryMetadata - The metadata of the Query whose results will be updated. (not null)
* @throws Exception A problem caused the update to fail.
*/
public void updateQueryResults(final TransactionBase tx, final VisibilityBindingSet childBindingSet, final QueryMetadata queryMetadata) throws Exception {
checkNotNull(tx);
checkNotNull(childBindingSet);
checkNotNull(queryMetadata);
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "Join Node ID: " + queryMetadata.getNodeId() + "\n" + "Child Node ID: " + queryMetadata.getChildNodeId() + "\n" + "Child Binding Set:\n" + childBindingSet + "\n");
// Create the query's Binding Set from the child node's binding set.
final VariableOrder queryVarOrder = queryMetadata.getVariableOrder();
// Create the Row Key for the result. If the child node groups results, then the key must only contain the Group By variables.
final Bytes resultRow = makeRowKey(queryMetadata.getNodeId(), queryVarOrder, childBindingSet);
// Create the Binding Set that goes in the Node Value. It does contain visibilities.
final Bytes nodeValueBytes = BS_SERDE.serialize(childBindingSet);
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Binding Set: " + childBindingSet + "\n");
tx.set(resultRow, FluoQueryColumns.QUERY_BINDING_SET, nodeValueBytes);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readPeriodicQueryMetadataBuilder.
private PeriodicQueryMetadata.Builder readPeriodicQueryMetadataBuilder(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.PERIODIC_QUERY_VARIABLE_ORDER, FluoQueryColumns.PERIODIC_QUERY_PARENT_NODE_ID, FluoQueryColumns.PERIODIC_QUERY_CHILD_NODE_ID, FluoQueryColumns.PERIODIC_QUERY_PERIOD, FluoQueryColumns.PERIODIC_QUERY_WINDOWSIZE, FluoQueryColumns.PERIODIC_QUERY_TIMEUNIT, FluoQueryColumns.PERIODIC_QUERY_TEMPORAL_VARIABLE);
// Return an object holding them.
final String varOrderString = values.get(FluoQueryColumns.PERIODIC_QUERY_VARIABLE_ORDER);
final VariableOrder varOrder = new VariableOrder(varOrderString);
final String parentNodeId = values.get(FluoQueryColumns.PERIODIC_QUERY_PARENT_NODE_ID);
final String childNodeId = values.get(FluoQueryColumns.PERIODIC_QUERY_CHILD_NODE_ID);
final String temporalVariable = values.get(FluoQueryColumns.PERIODIC_QUERY_TEMPORAL_VARIABLE);
final String period = values.get(FluoQueryColumns.PERIODIC_QUERY_PERIOD);
final String window = values.get(FluoQueryColumns.PERIODIC_QUERY_WINDOWSIZE);
final String timeUnit = values.get(FluoQueryColumns.PERIODIC_QUERY_TIMEUNIT);
return PeriodicQueryMetadata.builder().setNodeId(nodeId).setVarOrder(varOrder).setParentNodeId(parentNodeId).setChildNodeId(childNodeId).setWindowSize(Long.parseLong(window)).setPeriod(Long.parseLong(period)).setTemporalVariable(temporalVariable).setUnit(TimeUnit.valueOf(timeUnit));
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readJoinMetadataBuilder.
private JoinMetadata.Builder readJoinMetadataBuilder(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.JOIN_VARIABLE_ORDER, FluoQueryColumns.JOIN_TYPE, FluoQueryColumns.JOIN_PARENT_NODE_ID, FluoQueryColumns.JOIN_LEFT_CHILD_NODE_ID, FluoQueryColumns.JOIN_BATCH_SIZE, FluoQueryColumns.JOIN_RIGHT_CHILD_NODE_ID);
// Return an object holding them.
final String varOrderString = values.get(FluoQueryColumns.JOIN_VARIABLE_ORDER);
final VariableOrder varOrder = new VariableOrder(varOrderString);
final String joinTypeString = values.get(FluoQueryColumns.JOIN_TYPE);
final JoinType joinType = JoinType.valueOf(joinTypeString);
final String parentNodeId = values.get(FluoQueryColumns.JOIN_PARENT_NODE_ID);
final String leftChildNodeId = values.get(FluoQueryColumns.JOIN_LEFT_CHILD_NODE_ID);
final int joinBatchSize = Integer.parseInt(values.get(FluoQueryColumns.JOIN_BATCH_SIZE));
final String rightChildNodeId = values.get(FluoQueryColumns.JOIN_RIGHT_CHILD_NODE_ID);
return JoinMetadata.builder(nodeId).setVarOrder(varOrder).setJoinType(joinType).setParentNodeId(parentNodeId).setJoinBatchSize(joinBatchSize).setLeftChildNodeId(leftChildNodeId).setRightChildNodeId(rightChildNodeId);
}
Aggregations