Search in sources :

Example 1 with FlattenedDataSet

use of org.locationtech.geowave.core.store.flatten.FlattenedDataSet in project geowave by locationtech.

the class DataStoreUtils method decomposeFlattenedFields.

/**
 * Takes a byte array representing a serialized composite group of FieldInfos sharing a common
 * visibility and returns a List of the individual FieldInfos
 *
 * @param bitmask the composite bitmask representing the fields contained within the
 *        flattenedValue
 * @param flattenedValue the serialized composite FieldInfo
 * @param commonVisibility the shared visibility
 * @param maxFieldPosition can short-circuit read and defer decomposition of fields after a given
 *        position
 * @return the dataset that has been read
 */
public static <T> FlattenedDataSet decomposeFlattenedFields(final byte[] bitmask, final byte[] flattenedValue, final byte[] commonVisibility, final int maxFieldPosition) {
    final List<FlattenedFieldInfo> fieldInfoList = new LinkedList<>();
    if ((flattenedValue != null) && (flattenedValue.length > 0)) {
        if ((bitmask != null) && (bitmask.length > 0)) {
            final List<Integer> fieldPositions = BitmaskUtils.getFieldPositions(bitmask);
            final boolean sharedVisibility = fieldPositions.size() > 1;
            if (sharedVisibility) {
                final ByteBuffer input = ByteBuffer.wrap(flattenedValue);
                for (int i = 0; i < fieldPositions.size(); i++) {
                    final Integer fieldPosition = fieldPositions.get(i);
                    if ((maxFieldPosition > -2) && (fieldPosition > maxFieldPosition)) {
                        return new FlattenedDataSet(fieldInfoList, new FlattenedUnreadDataSingleRow(input, i, fieldPositions));
                    }
                    final int fieldLength = VarintUtils.readUnsignedInt(input);
                    final byte[] fieldValueBytes = ByteArrayUtils.safeRead(input, fieldLength);
                    fieldInfoList.add(new FlattenedFieldInfo(fieldPosition, fieldValueBytes));
                }
            } else {
                fieldInfoList.add(new FlattenedFieldInfo(fieldPositions.get(0), flattenedValue));
            }
        } else {
            // assume fields are in positional order
            final ByteBuffer input = ByteBuffer.wrap(flattenedValue);
            for (int i = 0; input.hasRemaining(); i++) {
                final Integer fieldPosition = i;
                final int fieldLength = VarintUtils.readUnsignedInt(input);
                final byte[] fieldValueBytes = ByteArrayUtils.safeRead(input, fieldLength);
                fieldInfoList.add(new FlattenedFieldInfo(fieldPosition, fieldValueBytes));
            }
        }
    }
    return new FlattenedDataSet(fieldInfoList, null);
}
Also used : FlattenedFieldInfo(org.locationtech.geowave.core.store.flatten.FlattenedFieldInfo) FlattenedDataSet(org.locationtech.geowave.core.store.flatten.FlattenedDataSet) ByteBuffer(java.nio.ByteBuffer) FlattenedUnreadDataSingleRow(org.locationtech.geowave.core.store.flatten.FlattenedUnreadDataSingleRow) LinkedList(java.util.LinkedList)

Example 2 with FlattenedDataSet

use of org.locationtech.geowave.core.store.flatten.FlattenedDataSet in project geowave by locationtech.

the class HBaseDistributableFilter method aggregateFieldData.

protected FlattenedUnreadData aggregateFieldData(final Cell cell, final PersistentDataset<Object> commonData) throws IOException {
    final byte[] qualBuf = CellUtil.cloneQualifier(cell);
    final byte[] valBuf = CellUtil.cloneValue(cell);
    final FlattenedDataSet dataSet = DataStoreUtils.decomposeFlattenedFields(qualBuf, valBuf, null, commonIndexFieldIds.size() - 1);
    final List<FlattenedFieldInfo> fieldInfos = dataSet.getFieldsRead();
    for (final FlattenedFieldInfo fieldInfo : fieldInfos) {
        final int ordinal = fieldInfo.getFieldPosition();
        if (ordinal < commonIndexFieldIds.size()) {
            final String commonIndexFieldName = commonIndexFieldIds.get(ordinal);
            final FieldReader<?> reader = model.getReader(commonIndexFieldName);
            if (reader != null) {
                final Object fieldValue = reader.readField(fieldInfo.getValue());
                commonData.addValue(commonIndexFieldName, fieldValue);
            } else {
                LOGGER.error("Could not find reader for common index field: " + commonIndexFieldName);
            }
        }
    }
    return dataSet.getFieldsDeferred();
}
Also used : FlattenedFieldInfo(org.locationtech.geowave.core.store.flatten.FlattenedFieldInfo) FlattenedDataSet(org.locationtech.geowave.core.store.flatten.FlattenedDataSet)

Example 3 with FlattenedDataSet

use of org.locationtech.geowave.core.store.flatten.FlattenedDataSet in project geowave by locationtech.

the class DataStoreUtils method aggregateFieldData.

public static FlattenedUnreadData aggregateFieldData(final GeoWaveKey key, final GeoWaveValue value, final PersistentDataset<Object> commonData, final CommonIndexModel model, final List<String> commonIndexFieldIds) {
    final byte[] fieldMask = value.getFieldMask();
    final byte[] valueBytes = value.getValue();
    final FlattenedDataSet dataSet = DataStoreUtils.decomposeFlattenedFields(fieldMask, valueBytes, value.getVisibility(), commonIndexFieldIds.size() - 1);
    final List<FlattenedFieldInfo> fieldInfos = dataSet.getFieldsRead();
    for (final FlattenedFieldInfo fieldInfo : fieldInfos) {
        final int ordinal = fieldInfo.getFieldPosition();
        if (ordinal < commonIndexFieldIds.size()) {
            final String commonIndexFieldName = commonIndexFieldIds.get(ordinal);
            final FieldReader<?> reader = model.getReader(commonIndexFieldName);
            if (reader != null) {
                final Object fieldValue = reader.readField(fieldInfo.getValue());
                commonData.addValue(commonIndexFieldName, fieldValue);
            } else {
                LOGGER.error("Could not find reader for common index field: " + commonIndexFieldName);
            }
        }
    }
    return dataSet.getFieldsDeferred();
}
Also used : FlattenedFieldInfo(org.locationtech.geowave.core.store.flatten.FlattenedFieldInfo) FlattenedDataSet(org.locationtech.geowave.core.store.flatten.FlattenedDataSet)

Aggregations

FlattenedDataSet (org.locationtech.geowave.core.store.flatten.FlattenedDataSet)3 FlattenedFieldInfo (org.locationtech.geowave.core.store.flatten.FlattenedFieldInfo)3 ByteBuffer (java.nio.ByteBuffer)1 LinkedList (java.util.LinkedList)1 FlattenedUnreadDataSingleRow (org.locationtech.geowave.core.store.flatten.FlattenedUnreadDataSingleRow)1