use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readConstructQueryMetadataBuilder.
private ConstructQueryMetadata.Builder readConstructQueryMetadataBuilder(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.CONSTRUCT_GRAPH, FluoQueryColumns.CONSTRUCT_CHILD_NODE_ID, FluoQueryColumns.CONSTRUCT_PARENT_NODE_ID, FluoQueryColumns.CONSTRUCT_VARIABLE_ORDER);
final String graphString = values.get(FluoQueryColumns.CONSTRUCT_GRAPH);
final ConstructGraph graph = ConstructGraphSerializer.toConstructGraph(graphString);
final String childNodeId = values.get(FluoQueryColumns.CONSTRUCT_CHILD_NODE_ID);
final String parentNodeId = values.get(FluoQueryColumns.CONSTRUCT_PARENT_NODE_ID);
final String varOrderString = values.get(FluoQueryColumns.CONSTRUCT_VARIABLE_ORDER);
return ConstructQueryMetadata.builder().setNodeId(nodeId).setParentNodeId(parentNodeId).setConstructGraph(graph).setVarOrder(new VariableOrder(varOrderString)).setChildNodeId(childNodeId);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method write.
/**
* Write an instance of {@link AggregationMetadata} to the Fluo table.
*
* @param tx - The transaction that will be used to commit the metadata. (not null)
* @param metadata - The Aggregation node metadata that will be written to the table. (not null)
*/
public void write(final TransactionBase tx, final AggregationMetadata metadata) {
requireNonNull(tx);
requireNonNull(metadata);
final String rowId = metadata.getNodeId();
tx.set(rowId, FluoQueryColumns.AGGREGATION_NODE_ID, rowId);
tx.set(rowId, FluoQueryColumns.AGGREGATION_VARIABLE_ORDER, metadata.getVariableOrder().toString());
tx.set(rowId, FluoQueryColumns.AGGREGATION_PARENT_NODE_ID, metadata.getParentNodeId());
tx.set(rowId, FluoQueryColumns.AGGREGATION_CHILD_NODE_ID, metadata.getChildNodeId());
// Store the Group By variable order.
final VariableOrder groupByVars = metadata.getGroupByVariableOrder();
final String groupByString = Joiner.on(";").join(groupByVars.getVariableOrders());
tx.set(rowId, FluoQueryColumns.AGGREGATION_GROUP_BY_BINDING_NAMES, groupByString);
// Serialize the collection of AggregationElements.
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (final ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(metadata.getAggregations());
} catch (final IOException e) {
throw new RuntimeException("Problem encountered while writing AggregationMetadata to the Fluo table. Unable " + "to serialize the AggregationElements to a byte[].", e);
}
tx.set(Bytes.of(rowId.getBytes(Charsets.UTF_8)), FluoQueryColumns.AGGREGATION_AGGREGATIONS, Bytes.of(baos.toByteArray()));
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readStatementPatternMetadataBuilder.
private StatementPatternMetadata.Builder readStatementPatternMetadataBuilder(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.STATEMENT_PATTERN_VARIABLE_ORDER, FluoQueryColumns.STATEMENT_PATTERN_PATTERN, FluoQueryColumns.STATEMENT_PATTERN_PARENT_NODE_ID);
// Return an object holding them.
final String varOrderString = values.get(FluoQueryColumns.STATEMENT_PATTERN_VARIABLE_ORDER);
final VariableOrder varOrder = new VariableOrder(varOrderString);
final String pattern = values.get(FluoQueryColumns.STATEMENT_PATTERN_PATTERN);
final String parentNodeId = values.get(FluoQueryColumns.STATEMENT_PATTERN_PARENT_NODE_ID);
return StatementPatternMetadata.builder(nodeId).setVarOrder(varOrder).setStatementPattern(pattern).setParentNodeId(parentNodeId);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class FluoQueryMetadataDAO method readProjectionMetadataBuilder.
private ProjectionMetadata.Builder readProjectionMetadataBuilder(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.PROJECTION_VARIABLE_ORDER, FluoQueryColumns.PROJECTION_PROJECTED_VARS, FluoQueryColumns.PROJECTION_PARENT_NODE_ID, FluoQueryColumns.PROJECTION_CHILD_NODE_ID);
// Return an object holding them.
final String varOrderString = values.get(FluoQueryColumns.PROJECTION_VARIABLE_ORDER);
final String projectedVarString = values.get(FluoQueryColumns.PROJECTION_PROJECTED_VARS);
final VariableOrder varOrder = new VariableOrder(varOrderString);
final VariableOrder projectedVars = new VariableOrder(projectedVarString);
final String childNodeId = values.get(FluoQueryColumns.PROJECTION_CHILD_NODE_ID);
final String parentNodeId = values.get(FluoQueryColumns.PROJECTION_PARENT_NODE_ID);
return ProjectionMetadata.builder(nodeId).setVarOrder(varOrder).setProjectedVars(projectedVars).setParentNodeId(parentNodeId).setChildNodeId(childNodeId);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class MongoPcjDocuments method makeMetadataDocument.
/**
* Creates a {@link Document} containing the metadata defining the PCj.
*
* @param pcjId - Uniquely identifies a PCJ within Rya. (not null)
* @param sparql - The sparql query the PCJ will use.
* @return The document built around the provided metadata.
* @throws PCJStorageException - Thrown when the sparql query is malformed.
*/
public Document makeMetadataDocument(final String pcjId, final String sparql) throws PCJStorageException {
requireNonNull(pcjId);
requireNonNull(sparql);
final Set<VariableOrder> varOrders;
try {
varOrders = pcjVarOrderFactory.makeVarOrders(sparql);
} catch (final MalformedQueryException e) {
throw new PCJStorageException("Can not create the PCJ. The SPARQL is malformed.", e);
}
return new Document().append(PCJ_METADATA_ID, makeMetadataID(pcjId)).append(SPARQL_FIELD, sparql).append(CARDINALITY_FIELD, 0).append(VAR_ORDER_FIELD, varOrders);
}
Aggregations