Search in sources :

Example 6 with VertexiumException

use of org.vertexium.VertexiumException 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 7 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class OverflowIntoHdfsStreamingPropertyValueStorageStrategy method streamingPropertyValueTableDatas.

private Map<String, byte[]> streamingPropertyValueTableDatas(List<String> dataRowKeys) {
    try {
        if (dataRowKeys.size() == 0) {
            return Collections.emptyMap();
        }
        List<org.apache.accumulo.core.data.Range> ranges = dataRowKeys.stream().map(RangeUtils::createRangeFromString).collect(Collectors.toList());
        final long timerStartTime = System.currentTimeMillis();
        ScannerBase scanner = graph.createBatchScanner(graph.getDataTableName(), ranges, new org.apache.accumulo.core.security.Authorizations());
        graph.getGraphLogger().logStartIterator(scanner);
        Span trace = Trace.start("streamingPropertyValueTableData");
        trace.data("dataRowKeyCount", Integer.toString(dataRowKeys.size()));
        try {
            Map<String, byte[]> results = new HashMap<>();
            for (Map.Entry<Key, Value> col : scanner) {
                results.put(col.getKey().getRow().toString(), col.getValue().get());
            }
            return results;
        } finally {
            scanner.close();
            trace.stop();
            graph.getGraphLogger().logEndIterator(System.currentTimeMillis() - timerStartTime);
        }
    } catch (Exception ex) {
        throw new VertexiumException(ex);
    }
}
Also used : HashMap(java.util.HashMap) ScannerBase(org.apache.accumulo.core.client.ScannerBase) Span(org.apache.accumulo.core.trace.Span) VertexiumException(org.vertexium.VertexiumException) IOException(java.io.IOException) VertexiumException(org.vertexium.VertexiumException) org.vertexium.accumulo(org.vertexium.accumulo) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) HashMap(java.util.HashMap) Map(java.util.Map) DataTableRowKey(org.vertexium.accumulo.keys.DataTableRowKey) Key(org.apache.accumulo.core.data.Key)

Example 8 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class OverflowIntoHdfsStreamingPropertyValueStorageStrategy method saveStreamingPropertyValue.

@Override
public StreamingPropertyValueRef saveStreamingPropertyValue(ElementMutationBuilder elementMutationBuilder, String rowKey, Property property, StreamingPropertyValue streamingPropertyValue) {
    try {
        HdfsLargeDataStore largeDataStore = new HdfsLargeDataStore(this.fileSystem, this.dataDir, rowKey, property);
        LimitOutputStream out = new LimitOutputStream(largeDataStore, maxStreamingPropertyValueTableDataSize);
        try {
            IOUtils.copy(streamingPropertyValue.getInputStream(), out);
        } finally {
            out.close();
        }
        if (out.hasExceededSizeLimit()) {
            LOGGER.debug("saved large file to \"%s\" (length: %d)", largeDataStore.getFullHdfsPath(), out.getLength());
            return new StreamingPropertyValueHdfsRef(largeDataStore.getRelativeFileName(), streamingPropertyValue);
        } else {
            return saveStreamingPropertyValueSmall(elementMutationBuilder, rowKey, property, out.getSmall(), streamingPropertyValue);
        }
    } catch (IOException ex) {
        throw new VertexiumException(ex);
    }
}
Also used : IOException(java.io.IOException) VertexiumException(org.vertexium.VertexiumException)

Example 9 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class StreamingPropertyValueTable method streamingPropertyValueTableData.

public byte[] streamingPropertyValueTableData(String dataRowKey, Long timestamp) {
    try {
        List<Range> ranges = Lists.newArrayList(RangeUtils.createRangeFromString(dataRowKey));
        long timerStartTime = System.currentTimeMillis();
        ScannerBase scanner = graph.createBatchScanner(graph.getDataTableName(), ranges, new org.apache.accumulo.core.security.Authorizations());
        if (timestamp != null && !DataTableRowKey.isLegacy(dataRowKey)) {
            IteratorSetting iteratorSetting = new IteratorSetting(80, TimestampFilter.class.getSimpleName(), TimestampFilter.class);
            TimestampFilter.setStart(iteratorSetting, timestamp, true);
            TimestampFilter.setEnd(iteratorSetting, timestamp, true);
            scanner.addScanIterator(iteratorSetting);
        }
        GRAPH_LOGGER.logStartIterator(scanner);
        Span trace = Trace.start("streamingPropertyValueTableData");
        trace.data("dataRowKeyCount", Integer.toString(1));
        try {
            byte[] result = null;
            for (Map.Entry<Key, Value> col : scanner) {
                String foundKey = col.getKey().getRow().toString();
                byte[] value = col.getValue().get();
                if (foundKey.equals(dataRowKey)) {
                    result = value;
                }
            }
            if (result == null) {
                throw new VertexiumException("Could not find data with key: " + dataRowKey);
            }
            return result;
        } finally {
            scanner.close();
            trace.stop();
            GRAPH_LOGGER.logEndIterator(System.currentTimeMillis() - timerStartTime);
        }
    } catch (Exception ex) {
        throw new VertexiumException(ex);
    }
}
Also used : TimestampFilter(org.apache.accumulo.core.iterators.user.TimestampFilter) ScannerBase(org.apache.accumulo.core.client.ScannerBase) Range(org.apache.accumulo.core.data.Range) Span(org.apache.accumulo.core.trace.Span) VertexiumException(org.vertexium.VertexiumException) VertexiumException(org.vertexium.VertexiumException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) StreamingPropertyValue(org.vertexium.property.StreamingPropertyValue) Map(java.util.Map) DataTableRowKey(org.vertexium.accumulo.keys.DataTableRowKey) Key(org.apache.accumulo.core.data.Key)

Example 10 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class IdStrategy method extendedDataRowIdFromSearchHit.

public ExtendedDataRowId extendedDataRowIdFromSearchHit(SearchHit hit) {
    SearchHitField elementTypeField = hit.getFields().get(Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME);
    if (elementTypeField == null) {
        throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME);
    }
    ElementType elementType = ElasticsearchDocumentType.parse(elementTypeField.getValue().toString()).toElementType();
    SearchHitField elementIdField = hit.getFields().get(Elasticsearch5SearchIndex.ELEMENT_ID_FIELD_NAME);
    if (elementIdField == null) {
        throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.ELEMENT_ID_FIELD_NAME);
    }
    String elementId = elementIdField.getValue();
    SearchHitField tableNameField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME);
    if (tableNameField == null) {
        throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_NAME_FIELD_NAME);
    }
    String tableName = tableNameField.getValue();
    SearchHitField rowIdField = hit.getFields().get(Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
    if (rowIdField == null) {
        throw new VertexiumException("Could not find field: " + Elasticsearch5SearchIndex.EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME);
    }
    String rowId = rowIdField.getValue();
    return new ExtendedDataRowId(elementType, elementId, tableName, rowId);
}
Also used : ElementType(org.vertexium.ElementType) ExtendedDataRowId(org.vertexium.ExtendedDataRowId) SearchHitField(org.elasticsearch.search.SearchHitField) VertexiumException(org.vertexium.VertexiumException)

Aggregations

VertexiumException (org.vertexium.VertexiumException)34 Aggregation (org.elasticsearch.search.aggregations.Aggregation)6 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 Key (org.apache.accumulo.core.data.Key)3 Value (org.apache.accumulo.core.data.Value)3 DataTableRowKey (org.vertexium.accumulo.keys.DataTableRowKey)3 StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 List (java.util.List)2 ScannerBase (org.apache.accumulo.core.client.ScannerBase)2 Span (org.apache.accumulo.core.trace.Span)2 GeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)2 InternalGeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid)2 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)2 InternalDateHistogram (org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram)2 InternalHistogram (org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram)2