Search in sources :

Example 66 with VariableOrder

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);
}
Also used : Column(org.apache.fluo.api.data.Column) ConstructGraph(org.apache.rya.indexing.pcj.fluo.app.ConstructGraph) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

Example 67 with VariableOrder

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()));
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 68 with VariableOrder

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);
}
Also used : Column(org.apache.fluo.api.data.Column) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

Example 69 with VariableOrder

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);
}
Also used : Column(org.apache.fluo.api.data.Column) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

Example 70 with VariableOrder

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);
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) MalformedQueryException(org.openrdf.query.MalformedQueryException) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException) Document(org.bson.Document)

Aggregations

VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)79 Test (org.junit.Test)47 HashSet (java.util.HashSet)18 MapBindingSet (org.openrdf.query.impl.MapBindingSet)18 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)17 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)15 Bytes (org.apache.fluo.api.data.Bytes)14 BindingSet (org.openrdf.query.BindingSet)14 Column (org.apache.fluo.api.data.Column)13 FluoClient (org.apache.fluo.api.client.FluoClient)12 URIImpl (org.openrdf.model.impl.URIImpl)12 Transaction (org.apache.fluo.api.client.Transaction)11 Snapshot (org.apache.fluo.api.client.Snapshot)10 ShiftVarOrderFactory (org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory)10 AccumuloPcjSerializer (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjSerializer)9 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)8 Connector (org.apache.accumulo.core.client.Connector)5 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)5 RowColumn (org.apache.fluo.api.data.RowColumn)4