Search in sources :

Example 1 with GeoWaveValueImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveValueImpl in project geowave by locationtech.

the class AccumuloRow method setFieldValues.

private void setFieldValues(final List<Map<Key, Value>> fieldValueMapList) {
    final List<GeoWaveValue> fieldValueList = new ArrayList();
    for (final Map<Key, Value> kvMap : fieldValueMapList) {
        for (final Entry<Key, Value> kv : kvMap.entrySet()) {
            fieldValueList.add(new GeoWaveValueImpl(kv.getKey().getColumnQualifier().getBytes(), kv.getKey().getColumnVisibility().getBytes(), kv.getValue().get()));
        }
    }
    fieldValues = new GeoWaveValue[fieldValueList.size()];
    int i = 0;
    for (final GeoWaveValue gwValue : fieldValueList) {
        fieldValues[i++] = gwValue;
    }
}
Also used : GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) ArrayList(java.util.ArrayList) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) Value(org.apache.accumulo.core.data.Value) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) Key(org.apache.accumulo.core.data.Key) GeoWaveKey(org.locationtech.geowave.core.store.entities.GeoWaveKey)

Example 2 with GeoWaveValueImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveValueImpl in project geowave by locationtech.

the class CassandraRow method getFieldValues.

private static GeoWaveValue[] getFieldValues(final Row row) {
    final byte[] fieldMask = row.getByteBuffer(CassandraField.GW_FIELD_MASK_KEY.getFieldName()).array();
    final byte[] value = row.getByteBuffer(CassandraField.GW_VALUE_KEY.getFieldName()).array();
    final byte[] visibility = row.getByteBuffer(CassandraField.GW_FIELD_VISIBILITY_KEY.getFieldName()).array();
    final GeoWaveValue[] fieldValues = new GeoWaveValueImpl[1];
    fieldValues[0] = new GeoWaveValueImpl(fieldMask, visibility, value);
    return fieldValues;
}
Also used : GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue)

Example 3 with GeoWaveValueImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveValueImpl in project geowave by locationtech.

the class BaseDataStoreUtils method composeFlattenedFields.

/**
 * This method combines all FieldInfos that share a common visibility into a single FieldInfo
 *
 * @param originalList
 * @return a new list of composite FieldInfos
 */
private static <T> GeoWaveValue[] composeFlattenedFields(final List<FieldInfo<?>> originalList, final CommonIndexModel model, final InternalDataAdapter<?> writableAdapter, final VisibilityComposer commonIndexVisibility, final boolean dataIdIndex) {
    if (originalList.isEmpty()) {
        return new GeoWaveValue[0];
    }
    final Map<String, List<Pair<Integer, FieldInfo<?>>>> vizToFieldMap = new LinkedHashMap<>();
    // organize FieldInfos by unique visibility
    if (dataIdIndex) {
        final List<Pair<Integer, FieldInfo<?>>> fieldsWithPositions = (List) originalList.stream().map(fieldInfo -> {
            final int fieldPosition = writableAdapter.getPositionOfOrderedField(model, fieldInfo.getFieldId());
            return (Pair) Pair.of(fieldPosition, fieldInfo);
        }).collect(Collectors.toList());
        final VisibilityComposer combinedVisibility = new VisibilityComposer();
        for (final FieldInfo<?> fieldValue : originalList) {
            combinedVisibility.addVisibility(fieldValue.getVisibility());
        }
        vizToFieldMap.put(combinedVisibility.composeVisibility(), fieldsWithPositions);
    } else {
        boolean sharedVisibility = false;
        for (final FieldInfo<?> fieldInfo : originalList) {
            int fieldPosition = writableAdapter.getPositionOfOrderedField(model, fieldInfo.getFieldId());
            if (fieldPosition == -1) {
                // this is just a fallback for unexpected failures
                fieldPosition = writableAdapter.getPositionOfOrderedField(model, fieldInfo.getFieldId());
            }
            final VisibilityComposer currentComposer = new VisibilityComposer(commonIndexVisibility);
            currentComposer.addVisibility(fieldInfo.getVisibility());
            final String currViz = currentComposer.composeVisibility();
            if (vizToFieldMap.containsKey(currViz)) {
                sharedVisibility = true;
                final List<Pair<Integer, FieldInfo<?>>> listForViz = vizToFieldMap.get(currViz);
                listForViz.add(new ImmutablePair<Integer, FieldInfo<?>>(fieldPosition, fieldInfo));
            } else {
                final List<Pair<Integer, FieldInfo<?>>> listForViz = new LinkedList<>();
                listForViz.add(new ImmutablePair<Integer, FieldInfo<?>>(fieldPosition, fieldInfo));
                vizToFieldMap.put(currViz, listForViz);
            }
        }
        if (!sharedVisibility) {
            // at a minimum, must return transformed (bitmasked) fieldInfos
            final GeoWaveValue[] bitmaskedValues = new GeoWaveValue[vizToFieldMap.size()];
            int i = 0;
            for (final List<Pair<Integer, FieldInfo<?>>> list : vizToFieldMap.values()) {
                // every list must have exactly one element
                final Pair<Integer, FieldInfo<?>> fieldInfo = list.get(0);
                bitmaskedValues[i++] = new GeoWaveValueImpl(BitmaskUtils.generateCompositeBitmask(fieldInfo.getLeft()), StringUtils.stringToBinary(fieldInfo.getRight().getVisibility()), fieldInfo.getRight().getWrittenValue());
            }
            return bitmaskedValues;
        }
    }
    if (vizToFieldMap.size() == 1) {
        return new GeoWaveValue[] { entryToValue(vizToFieldMap.entrySet().iterator().next()) };
    } else {
        final List<GeoWaveValue> retVal = new ArrayList<>(vizToFieldMap.size());
        for (final Entry<String, List<Pair<Integer, FieldInfo<?>>>> entry : vizToFieldMap.entrySet()) {
            retVal.add(entryToValue(entry));
        }
        return retVal.toArray(new GeoWaveValue[0]);
    }
}
Also used : ArrayList(java.util.ArrayList) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) VisibilityComposer(org.locationtech.geowave.core.store.data.visibility.VisibilityComposer) IndexDimensionHint(org.locationtech.geowave.core.index.IndexDimensionHint) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) FieldInfo(org.locationtech.geowave.core.store.base.IntermediaryWriteEntryInfo.FieldInfo) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 4 with GeoWaveValueImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveValueImpl in project geowave by locationtech.

the class BaseDataStoreUtils method getWriteInfo.

protected static <T> IntermediaryWriteEntryInfo getWriteInfo(final T entry, final InternalDataAdapter<T> adapter, final AdapterToIndexMapping indexMapping, final Index index, final VisibilityHandler visibilityHandler, final boolean secondaryIndex, final boolean dataIdIndex, final boolean visibilityEnabled) {
    final CommonIndexModel indexModel = index.getIndexModel();
    final short internalAdapterId = adapter.getAdapterId();
    final byte[] dataId = adapter.getDataId(entry);
    final AdapterPersistenceEncoding encodedData = adapter.encode(entry, indexMapping, index);
    if (encodedData == null) {
        // The entry could not be encoded to the index, but this could be due to a null value in one
        // of the index fields, which is possible in attribute indices
        LOGGER.info("Indexing failed to produce insertion ids; entry [" + StringUtils.stringFromBinary(adapter.getDataId(entry)) + "] not saved for index '" + index.getName() + "'.");
        return new IntermediaryWriteEntryInfo(dataId, internalAdapterId, new InsertionIds(), new GeoWaveValueImpl[0]);
    }
    final InsertionIds insertionIds;
    if (index instanceof CustomIndexStrategy) {
        insertionIds = ((CustomIndexStrategy) index).getInsertionIds(entry);
    } else {
        insertionIds = dataIdIndex ? null : encodedData.getInsertionIds(index);
    }
    if (dataIdIndex) {
        return getWriteInfoDataIDIndex(entry, dataId, encodedData, adapter, indexMapping, index, visibilityHandler, visibilityEnabled);
    }
    if (insertionIds.isEmpty()) {
        // we can allow some entries to not be indexed within every index for flexibility, and
        // therefore this should just be info level
        LOGGER.info("Indexing failed to produce insertion ids; entry [" + StringUtils.stringFromBinary(adapter.getDataId(entry)) + "] not saved for index '" + index.getName() + "'.");
        return new IntermediaryWriteEntryInfo(dataId, internalAdapterId, insertionIds, new GeoWaveValueImpl[0]);
    }
    final VisibilityComposer commonIndexVisibility = new VisibilityComposer();
    if (visibilityEnabled && (visibilityHandler != null)) {
        for (final Entry<String, Object> fieldValue : encodedData.getCommonData().getValues().entrySet()) {
            addIndexFieldVisibility(entry, adapter, indexMapping, visibilityHandler, fieldValue.getKey(), commonIndexVisibility);
        }
    }
    if (secondaryIndex && DataIndexUtils.adapterSupportsDataIndex(adapter)) {
        return new IntermediaryWriteEntryInfo(dataId, internalAdapterId, insertionIds, new GeoWaveValue[] { new GeoWaveValueImpl(new byte[0], StringUtils.stringToBinary(commonIndexVisibility.composeVisibility()), new byte[0]) });
    }
    final List<FieldInfo<?>> fieldInfoList = new ArrayList<>();
    addCommonFields(adapter, indexMapping, entry, index, indexModel, visibilityHandler, encodedData, visibilityEnabled, fieldInfoList);
    for (final Entry<String, Object> fieldValue : encodedData.getAdapterExtendedData().getValues().entrySet()) {
        if (fieldValue.getValue() != null) {
            final FieldInfo<?> fieldInfo = getFieldInfo(adapter, adapter, indexMapping, fieldValue.getKey(), fieldValue.getValue(), entry, visibilityHandler, visibilityEnabled, false);
            if (fieldInfo != null) {
                fieldInfoList.add(fieldInfo);
            }
        }
    }
    return new IntermediaryWriteEntryInfo(dataId, internalAdapterId, insertionIds, BaseDataStoreUtils.composeFlattenedFields(fieldInfoList, indexModel, adapter, commonIndexVisibility, dataIdIndex));
}
Also used : IndexedAdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.IndexedAdapterPersistenceEncoding) AdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding) CustomIndexStrategy(org.locationtech.geowave.core.index.CustomIndexStrategy) ArrayList(java.util.ArrayList) VisibilityComposer(org.locationtech.geowave.core.store.data.visibility.VisibilityComposer) CommonIndexModel(org.locationtech.geowave.core.store.index.CommonIndexModel) GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) FieldInfo(org.locationtech.geowave.core.store.base.IntermediaryWriteEntryInfo.FieldInfo)

Example 5 with GeoWaveValueImpl

use of org.locationtech.geowave.core.store.entities.GeoWaveValueImpl in project geowave by locationtech.

the class DataIndexUtils method deserializeDataIndexValue.

public static GeoWaveValue deserializeDataIndexValue(final byte[] serializedValue, final byte[] visibilityInput, final boolean visibilityEnabled) {
    final ByteBuffer buf = ByteBuffer.wrap(serializedValue);
    int lengthBytes = 1;
    final byte[] fieldMask = new byte[serializedValue[serializedValue.length - 1]];
    buf.get(fieldMask);
    final byte[] visibility;
    if (visibilityInput != null) {
        visibility = visibilityInput;
    } else if (visibilityEnabled) {
        lengthBytes++;
        visibility = new byte[serializedValue[serializedValue.length - 2]];
        buf.get(visibility);
    } else {
        visibility = new byte[0];
    }
    final byte[] value = new byte[buf.remaining() - lengthBytes];
    buf.get(value);
    return new GeoWaveValueImpl(fieldMask, visibility, value);
}
Also used : GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) ByteBuffer(java.nio.ByteBuffer)

Aggregations

GeoWaveValueImpl (org.locationtech.geowave.core.store.entities.GeoWaveValueImpl)10 GeoWaveValue (org.locationtech.geowave.core.store.entities.GeoWaveValue)8 ArrayList (java.util.ArrayList)4 GeoWaveKey (org.locationtech.geowave.core.store.entities.GeoWaveKey)3 Key (org.apache.accumulo.core.data.Key)2 Value (org.apache.accumulo.core.data.Value)2 FieldInfo (org.locationtech.geowave.core.store.base.IntermediaryWriteEntryInfo.FieldInfo)2 VisibilityComposer (org.locationtech.geowave.core.store.data.visibility.VisibilityComposer)2 GeoWaveKeyImpl (org.locationtech.geowave.core.store.entities.GeoWaveKeyImpl)2 GeoWaveRowImpl (org.locationtech.geowave.core.store.entities.GeoWaveRowImpl)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 SortedMap (java.util.SortedMap)1