Search in sources :

Example 1 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class AccumuloGraphTestBase method testLegacyStreamingPropertyValuesWithTimestampInRowKey.

@Test
public void testLegacyStreamingPropertyValuesWithTimestampInRowKey() throws Exception {
    String vertexId = "v1";
    graph.prepareVertex(vertexId, VISIBILITY_EMPTY).save(AUTHORIZATIONS_EMPTY);
    graph.flush();
    long timestamp = new Date().getTime();
    String propertyKey = "k1";
    String propertyName = "prop1";
    String propertyValue = "Hello";
    addLegacySPVData(vertexId, timestamp, propertyKey, propertyName, propertyValue);
    getGraph().flush();
    // verify we can still retrieve it
    Vertex v1 = graph.getVertex(vertexId, AUTHORIZATIONS_EMPTY);
    StreamingPropertyValue spv = (StreamingPropertyValue) v1.getPropertyValue(propertyKey, propertyName);
    assertNotNull("spv should not be null", spv);
    assertEquals(propertyValue, IOUtils.toString(spv.getInputStream()));
}
Also used : StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) Test(org.junit.Test)

Example 2 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class AccumuloGraphTestBase method testDeleteHistoricalLegacyStreamingPropertyValueData_mixOfOldAndNew.

@Test
public void testDeleteHistoricalLegacyStreamingPropertyValueData_mixOfOldAndNew() throws Exception {
    String vertexId = "v1";
    graph.prepareVertex(vertexId, VISIBILITY_EMPTY).save(AUTHORIZATIONS_EMPTY);
    graph.flush();
    long timestamp = new Date().getTime();
    String propertyKey = "prefix";
    String propertyName = "prop1";
    String propertyValue1 = "Hello1";
    String propertyValue2 = "Hello2";
    addLegacySPVData(vertexId, timestamp - 100, propertyKey, propertyName, propertyValue1);
    StreamingPropertyValue newSpv = StreamingPropertyValue.create(propertyValue2);
    getGraph().getVertex("v1", AUTHORIZATIONS_EMPTY).addPropertyValue(propertyKey, propertyName, newSpv, VISIBILITY_EMPTY, AUTHORIZATIONS_EMPTY);
    getGraph().flush();
    new DeleteHistoricalLegacyStreamingPropertyValueData(getGraph()).execute(new DeleteHistoricalLegacyStreamingPropertyValueData.Options().setDryRun(false).setVersionsToKeep(1), AUTHORIZATIONS_EMPTY);
    // verify we can still retrieve it
    Vertex v1 = graph.getVertex(vertexId, AUTHORIZATIONS_EMPTY);
    StreamingPropertyValue spv = (StreamingPropertyValue) v1.getPropertyValue(propertyKey, propertyName);
    assertNotNull("spv should not be null", spv);
    assertEquals(propertyValue2, IOUtils.toString(spv.getInputStream()));
}
Also used : StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) DeleteHistoricalLegacyStreamingPropertyValueData(org.vertexium.accumulo.tools.DeleteHistoricalLegacyStreamingPropertyValueData) Test(org.junit.Test)

Example 3 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class DataInDataTableStreamingPropertyValueStorageStrategy method saveStreamingPropertyValue.

@Override
public StreamingPropertyValueRef saveStreamingPropertyValue(ElementMutationBuilder elementMutationBuilder, String rowKey, Property property, StreamingPropertyValue streamingPropertyValue) {
    try {
        String dataTableRowKey = new DataTableRowKey(rowKey, property).getRowKey();
        InputStream in = streamingPropertyValue.getInputStream();
        byte[] buffer = new byte[dataInDataTablePartSize];
        long offset = 0;
        while (true) {
            int read = in.read(buffer);
            if (read <= 0) {
                break;
            }
            Mutation dataMutation = new Mutation(dataTableRowKey);
            Text columnQualifier = new Text(String.format("%08x", offset));
            dataMutation.put(DATA_COLUMN_FAMILY, columnQualifier, property.getTimestamp(), new Value(buffer, 0, read));
            elementMutationBuilder.saveDataMutation(dataMutation);
            offset += read;
        }
        Mutation dataMutation = new Mutation(dataTableRowKey);
        dataMutation.put(METADATA_COLUMN_FAMILY, METADATA_LENGTH_COLUMN_QUALIFIER, property.getTimestamp(), new Value(Longs.toByteArray(offset)));
        elementMutationBuilder.saveDataMutation(dataMutation);
        return new StreamingPropertyValueTableDataRef(dataTableRowKey, streamingPropertyValue, offset);
    } catch (Exception ex) {
        throw new VertexiumException("Could not store streaming property value", ex);
    }
}
Also used : InputStream(java.io.InputStream) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) StreamingPropertyValueTableDataRef(org.vertexium.accumulo.StreamingPropertyValueTableDataRef) VertexiumException(org.vertexium.VertexiumException) VertexiumException(org.vertexium.VertexiumException) DataTableRowKey(org.vertexium.accumulo.keys.DataTableRowKey)

Example 4 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class Elasticsearch5SearchIndex method getExtendedDataColumnsAsFields.

private Map<String, Object> getExtendedDataColumnsAsFields(Graph graph, List<ExtendedDataMutation> columns) {
    Map<String, Object> fieldsMap = new HashMap<>();
    List<ExtendedDataMutation> streamingColumns = new ArrayList<>();
    for (ExtendedDataMutation column : columns) {
        if (column.getValue() != null && shouldIgnoreType(column.getValue().getClass())) {
            continue;
        }
        if (column.getValue() instanceof StreamingPropertyValue) {
            StreamingPropertyValue spv = (StreamingPropertyValue) column.getValue();
            if (isStreamingPropertyValueIndexable(graph, column.getColumnName(), spv)) {
                streamingColumns.add(column);
            }
        } else {
            addExtendedDataColumnToFieldMap(graph, column, column.getValue(), fieldsMap);
        }
    }
    addStreamingExtendedDataColumnsValuesToMap(graph, streamingColumns, fieldsMap);
    return fieldsMap;
}
Also used : ExtendedDataMutation(org.vertexium.mutation.ExtendedDataMutation) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue)

Example 5 with StreamingPropertyValue

use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.

the class Elasticsearch5SearchIndex method getPropertiesAsFields.

private Map<String, Object> getPropertiesAsFields(Graph graph, Iterable<Property> properties) {
    Map<String, Object> fieldsMap = new HashMap<>();
    List<Property> streamingProperties = new ArrayList<>();
    for (Property property : properties) {
        if (property.getValue() != null && shouldIgnoreType(property.getValue().getClass())) {
            continue;
        }
        if (property.getValue() instanceof StreamingPropertyValue) {
            StreamingPropertyValue spv = (StreamingPropertyValue) property.getValue();
            if (isStreamingPropertyValueIndexable(graph, property.getName(), spv)) {
                streamingProperties.add(property);
            }
        } else {
            addPropertyToFieldMap(graph, property, property.getValue(), fieldsMap);
        }
    }
    addStreamingPropertyValuesToFieldMap(graph, streamingProperties, fieldsMap);
    return fieldsMap;
}
Also used : StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue)

Aggregations

StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)22 LargeStringInputStream (org.vertexium.test.util.LargeStringInputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)6 PropertyValue (org.vertexium.property.PropertyValue)6 Test (org.junit.Test)4 IndexHint (org.vertexium.search.IndexHint)4 Mutation (org.apache.accumulo.core.data.Mutation)3 Value (org.apache.accumulo.core.data.Value)3 DataTableRowKey (org.vertexium.accumulo.keys.DataTableRowKey)3 Text (org.apache.hadoop.io.Text)2 JSONObject (org.json.JSONObject)2 DeleteHistoricalLegacyStreamingPropertyValueData (org.vertexium.accumulo.tools.DeleteHistoricalLegacyStreamingPropertyValueData)2 VertexiumException (org.vertexium.VertexiumException)1 StreamingPropertyValueTableDataRef (org.vertexium.accumulo.StreamingPropertyValueTableDataRef)1 InMemoryGraph (org.vertexium.inmemory.InMemoryGraph)1 AlterPropertyVisibility (org.vertexium.mutation.AlterPropertyVisibility)1 ExtendedDataMutation (org.vertexium.mutation.ExtendedDataMutation)1 SetPropertyMetadata (org.vertexium.mutation.SetPropertyMetadata)1 MutablePropertyImpl (org.vertexium.property.MutablePropertyImpl)1