Search in sources :

Example 1 with FieldDescriptor

use of org.locationtech.geowave.core.store.adapter.FieldDescriptor in project geowave by locationtech.

the class FeatureDataAdapter method initializeFieldDescriptors.

private void initializeFieldDescriptors() {
    final List<AttributeDescriptor> attributes = featureType.getAttributeDescriptors();
    fieldDescriptors = new FieldDescriptor[attributes.size()];
    for (int i = 0; i < attributes.size(); i++) {
        final AttributeDescriptor attribute = attributes.get(i);
        if (attribute instanceof GeometryDescriptor) {
            final SpatialFieldDescriptorBuilder<?> builder = new SpatialFieldDescriptorBuilder<>(attribute.getType().getBinding());
            builder.fieldName(attribute.getName().getLocalPart());
            builder.crs(((GeometryDescriptor) attribute).getCoordinateReferenceSystem());
            if ((featureType.getGeometryDescriptor() != null) && featureType.getGeometryDescriptor().equals(attribute)) {
                builder.spatialIndexHint();
            }
            fieldDescriptors[i] = builder.build();
        } else if ((timeDescriptors != null) && attribute.equals(timeDescriptors.getTime())) {
            fieldDescriptors[i] = new TemporalFieldDescriptorBuilder<>(attribute.getType().getBinding()).fieldName(attribute.getName().getLocalPart()).timeIndexHint().build();
        } else if ((timeDescriptors != null) && attribute.equals(timeDescriptors.getStartRange())) {
            fieldDescriptors[i] = new TemporalFieldDescriptorBuilder<>(attribute.getType().getBinding()).fieldName(attribute.getName().getLocalPart()).startTimeIndexHint().build();
        } else if ((timeDescriptors != null) && attribute.equals(timeDescriptors.getEndRange())) {
            fieldDescriptors[i] = new TemporalFieldDescriptorBuilder<>(attribute.getType().getBinding()).fieldName(attribute.getName().getLocalPart()).endTimeIndexHint().build();
        } else {
            fieldDescriptors[i] = new FieldDescriptorBuilder<>(attribute.getType().getBinding()).fieldName(attribute.getName().getLocalPart()).build();
        }
    }
    // this assumes attribute names are unique, which *should* be a fair assumption
    descriptorsMap = Arrays.stream(fieldDescriptors).collect(Collectors.toMap(FieldDescriptor::fieldName, descriptor -> descriptor));
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) TemporalFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptorBuilder) SpatialFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptorBuilder) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) TemporalFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.TemporalFieldDescriptorBuilder) SpatialFieldDescriptorBuilder(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptorBuilder) FieldDescriptorBuilder(org.locationtech.geowave.core.store.adapter.FieldDescriptorBuilder) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) SpatialFieldDescriptor(org.locationtech.geowave.core.geotime.adapter.SpatialFieldDescriptor)

Example 2 with FieldDescriptor

use of org.locationtech.geowave.core.store.adapter.FieldDescriptor in project geowave by locationtech.

the class StatsCommandLineOptions method resolveMatchingStatistics.

@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Statistic<? extends StatisticValue<?>>> resolveMatchingStatistics(final DataStore dataStore, final DataStatisticsStore statsStore, final IndexStore indexStore) {
    final List<Statistic<? extends StatisticValue<?>>> matching = Lists.newArrayList();
    if ((indexName != null) && ((typeName != null) || (fieldName != null))) {
        throw new ParameterException("Unable to process index statistics for a single type. Specify either an index name or a type name.");
    }
    StatisticType statisticType = null;
    if (statType != null) {
        statisticType = StatisticsRegistry.instance().getStatisticType(statType);
        if (statisticType == null) {
            throw new ParameterException("Unrecognized statistic type: " + statType);
        }
    }
    if (statisticType != null) {
        if (statisticType instanceof IndexStatisticType) {
            if (indexName == null) {
                throw new ParameterException("An index name must be supplied when specifying an index statistic type.");
            }
            final Index index = indexStore.getIndex(indexName);
            if (index == null) {
                throw new ParameterException("Unable to find an index named: " + indexName);
            }
            try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getIndexStatistics(index, statisticType, tag)) {
                stats.forEachRemaining(stat -> matching.add(stat));
            }
        } else if (statisticType instanceof DataTypeStatisticType) {
            if (typeName == null) {
                throw new ParameterException("A type name must be supplied when specifying a data type statistic type.");
            }
            final DataTypeAdapter<?> adapter = dataStore.getType(typeName);
            if (adapter == null) {
                throw new ParameterException("Unable to find an type named: " + typeName);
            }
            try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getDataTypeStatistics(adapter, statisticType, tag)) {
                stats.forEachRemaining(stat -> matching.add(stat));
            }
        } else if (statisticType instanceof FieldStatisticType) {
            if (typeName == null) {
                throw new ParameterException("A type name must be supplied when specifying a field statistic type.");
            }
            final DataTypeAdapter<?> adapter = dataStore.getType(typeName);
            if (adapter == null) {
                throw new ParameterException("Unable to find an type named: " + typeName);
            }
            if (fieldName == null) {
                throw new ParameterException("A field name must be supplied when specifying a field statistic type.");
            }
            boolean fieldFound = false;
            final FieldDescriptor[] fields = adapter.getFieldDescriptors();
            for (int i = 0; i < fields.length; i++) {
                if (fields[i].fieldName().equals(fieldName)) {
                    fieldFound = true;
                    break;
                }
            }
            if (!fieldFound) {
                throw new ParameterException("Unable to find a field named '" + fieldName + "' on type '" + typeName + "'.");
            }
            try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getFieldStatistics(adapter, statisticType, fieldName, tag)) {
                stats.forEachRemaining(stat -> matching.add(stat));
            }
        }
    } else {
        try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getAllStatistics(null)) {
            stats.forEachRemaining(stat -> {
                // This could all be optimized to one giant check, but it's split for readability
                if ((tag != null) && !tag.equals(stat.getTag())) {
                    return;
                }
                if ((indexName != null) && (!(stat instanceof IndexStatistic) || !indexName.equals(((IndexStatistic) stat).getIndexName()))) {
                    return;
                }
                if (typeName != null) {
                    if (stat instanceof IndexStatistic) {
                        return;
                    }
                    if ((stat instanceof DataTypeStatistic) && !typeName.equals(((DataTypeStatistic) stat).getTypeName())) {
                        return;
                    }
                    if ((stat instanceof FieldStatistic) && !typeName.equals(((FieldStatistic) stat).getTypeName())) {
                        return;
                    }
                }
                if ((fieldName != null) && (!(stat instanceof FieldStatistic) || !fieldName.equals(((FieldStatistic) stat).getFieldName()))) {
                    return;
                }
                matching.add(stat);
            });
        }
    }
    return matching;
}
Also used : StatisticType(org.locationtech.geowave.core.store.statistics.StatisticType) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) ParameterException(com.beust.jcommander.ParameterException) DataStore(org.locationtech.geowave.core.store.api.DataStore) Parameter(com.beust.jcommander.Parameter) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Lists(com.clearspring.analytics.util.Lists) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) List(java.util.List) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) StatisticsRegistry(org.locationtech.geowave.core.store.statistics.StatisticsRegistry) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Statistic(org.locationtech.geowave.core.store.api.Statistic) Index(org.locationtech.geowave.core.store.api.Index) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Index(org.locationtech.geowave.core.store.api.Index) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Statistic(org.locationtech.geowave.core.store.api.Statistic) StatisticType(org.locationtech.geowave.core.store.statistics.StatisticType) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) ParameterException(com.beust.jcommander.ParameterException) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic)

Example 3 with FieldDescriptor

use of org.locationtech.geowave.core.store.adapter.FieldDescriptor in project geowave by locationtech.

the class BaseDataStore method groupAndValidateStats.

private Pair<Map<Index, List<IndexStatistic<?>>>, Map<InternalDataAdapter<?>, List<Statistic<? extends StatisticValue<?>>>>> groupAndValidateStats(final Statistic<? extends StatisticValue<?>>[] statistics, final boolean allowExisting) {
    final Map<Index, List<IndexStatistic<?>>> indexStatsToAdd = Maps.newHashMap();
    final Map<InternalDataAdapter<?>, List<Statistic<? extends StatisticValue<?>>>> otherStatsToAdd = Maps.newHashMap();
    for (final Statistic<? extends StatisticValue<?>> statistic : statistics) {
        if (!allowExisting && statisticsStore.exists(statistic)) {
            throw new IllegalArgumentException("The statistic already exists.  If adding it is still desirable, use a 'tag' to make the statistic unique.");
        }
        if (statistic instanceof IndexStatistic) {
            final IndexStatistic<?> indexStat = (IndexStatistic<?>) statistic;
            if (indexStat.getIndexName() == null) {
                throw new IllegalArgumentException("No index specified.");
            }
            final Index index = indexStore.getIndex(indexStat.getIndexName());
            if (index == null) {
                throw new IllegalArgumentException("No index named " + indexStat.getIndexName() + ".");
            }
            if (!indexStatsToAdd.containsKey(index)) {
                indexStatsToAdd.put(index, Lists.newArrayList());
            }
            indexStatsToAdd.get(index).add(indexStat);
        } else if (statistic instanceof DataTypeStatistic) {
            final DataTypeStatistic<?> adapterStat = (DataTypeStatistic<?>) statistic;
            if (adapterStat.getTypeName() == null) {
                throw new IllegalArgumentException("No type specified.");
            }
            final InternalDataAdapter<?> adapter = getInternalAdapter(adapterStat.getTypeName());
            if (adapter == null) {
                throw new IllegalArgumentException("No type named " + adapterStat.getTypeName() + ".");
            }
            if (!otherStatsToAdd.containsKey(adapter)) {
                otherStatsToAdd.put(adapter, Lists.newArrayList());
            }
            otherStatsToAdd.get(adapter).add(adapterStat);
        } else if (statistic instanceof FieldStatistic) {
            final FieldStatistic<?> fieldStat = (FieldStatistic<?>) statistic;
            if (fieldStat.getTypeName() == null) {
                throw new IllegalArgumentException("No type specified.");
            }
            final InternalDataAdapter<?> adapter = getInternalAdapter(fieldStat.getTypeName());
            if (adapter == null) {
                throw new IllegalArgumentException("No type named " + fieldStat.getTypeName() + ".");
            }
            if (fieldStat.getFieldName() == null) {
                throw new IllegalArgumentException("No field specified.");
            }
            boolean foundMatch = false;
            final FieldDescriptor<?>[] fields = adapter.getFieldDescriptors();
            for (int i = 0; i < fields.length; i++) {
                if (fieldStat.getFieldName().equals(fields[i].fieldName())) {
                    foundMatch = true;
                    break;
                }
            }
            if (!foundMatch) {
                throw new IllegalArgumentException("No field named " + fieldStat.getFieldName() + " was found on the type " + fieldStat.getTypeName() + ".");
            }
            if (!otherStatsToAdd.containsKey(adapter)) {
                otherStatsToAdd.put(adapter, Lists.newArrayList());
            }
            otherStatsToAdd.get(adapter).add(fieldStat);
        } else {
            throw new IllegalArgumentException("Unrecognized statistic type.");
        }
    }
    return Pair.of(indexStatsToAdd, otherStatsToAdd);
}
Also used : IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Index(org.locationtech.geowave.core.store.api.Index) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) IngestCallbackList(org.locationtech.geowave.core.store.callback.IngestCallbackList) DeleteCallbackList(org.locationtech.geowave.core.store.callback.DeleteCallbackList) ArrayList(java.util.ArrayList) List(java.util.List) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic)

Example 4 with FieldDescriptor

use of org.locationtech.geowave.core.store.adapter.FieldDescriptor in project geowave by locationtech.

the class BaseDataStoreUtils method mapAdapterToIndex.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static AdapterToIndexMapping mapAdapterToIndex(final InternalDataAdapter<?> adapter, final Index index) {
    // Build up a list of index field mappers
    final Map<String, IndexFieldMapper<?, ?>> mappers = Maps.newHashMap();
    // Get index model dimensions
    final NumericDimensionField<?>[] dimensions = index.getIndexModel().getDimensions();
    // Map dimensions to index fields
    final Map<String, List<NumericDimensionField>> indexFields = Arrays.stream(dimensions).collect(Collectors.groupingBy(dim -> dim.getFieldName(), Collectors.mapping(dim -> dim, Collectors.toList())));
    // Get adapter fields
    final FieldDescriptor<?>[] adapterFields = adapter.getFieldDescriptors();
    for (final Entry<String, List<NumericDimensionField>> indexField : indexFields.entrySet()) {
        // Get the hints used by all dimensions of the field
        final Set<IndexDimensionHint> dimensionHints = Sets.newHashSet();
        indexField.getValue().forEach(dim -> dimensionHints.addAll(dim.getDimensionHints()));
        final Class<?> indexFieldClass = indexField.getValue().get(0).getFieldClass();
        final String indexFieldName = indexField.getKey();
        final IndexFieldOptions indexFieldOptions = indexField.getValue().get(0).getIndexFieldOptions();
        // Get available mappers for the field class
        final List<IndexFieldMapper<?, ?>> availableMappers = IndexFieldMapperRegistry.instance().getAvailableMappers(indexFieldClass);
        if (availableMappers.size() == 0) {
            throw new IllegalArgumentException("No index field mappers were found for the type: " + indexFieldClass.getName());
        }
        final List<FieldDescriptor<?>> hintedFields;
        if (index instanceof AttributeIndex) {
            // Only check the field that is set for the attribute index
            hintedFields = Lists.newArrayList(adapter.getFieldDescriptor(((AttributeIndex) index).getAttributeName()));
        } else {
            // Get any adapter fields that have been hinted for this field
            hintedFields = Arrays.stream(adapterFields).filter(field -> dimensionHints.stream().anyMatch(field.indexHints()::contains)).collect(Collectors.toList());
        }
        if (hintedFields.size() > 0) {
            final Class<?> hintedFieldClass = hintedFields.get(0).bindingClass();
            for (int i = 1; i < hintedFields.size(); i++) {
                if (!hintedFieldClass.equals(hintedFields.get(i).bindingClass())) {
                    throw new IllegalArgumentException("All hinted fields must be of the same type.");
                }
            }
            boolean mapperFound = false;
            // Find a mapper that matches
            for (final IndexFieldMapper<?, ?> mapper : availableMappers) {
                if (mapper.isCompatibleWith(hintedFieldClass) && (mapper.adapterFieldCount() == hintedFields.size())) {
                    mapper.init(indexField.getKey(), (List) hintedFields, indexFieldOptions);
                    mappers.put(indexField.getKey(), mapper);
                    mapperFound = true;
                    break;
                }
            }
            if (!mapperFound) {
                throw new IllegalArgumentException("No registered index field mappers were found for the type: " + hintedFieldClass.getName() + "[" + hintedFields.size() + "] -> " + indexFieldClass.getName());
            }
        } else {
            // Attempt to infer the field to use
            // See if there are any suggested fields
            boolean mapperFound = false;
            for (final IndexFieldMapper<?, ?> mapper : availableMappers) {
                final Set<String> suggestedFieldNames = mapper.getLowerCaseSuggestedFieldNames();
                final List<FieldDescriptor<?>> matchingFields = Arrays.stream(adapterFields).filter(field -> mapper.isCompatibleWith(field.bindingClass()) && suggestedFieldNames.contains(field.fieldName().toLowerCase())).collect(Collectors.toList());
                if (matchingFields.size() >= mapper.adapterFieldCount()) {
                    mapperFound = true;
                    mapper.init(indexFieldName, (List) matchingFields.stream().limit(mapper.adapterFieldCount()).collect(Collectors.toList()), indexFieldOptions);
                    mappers.put(indexFieldName, mapper);
                    break;
                }
            }
            // See if a direct mapper is available
            if (!mapperFound) {
                for (final FieldDescriptor<?> fieldDescriptor : adapterFields) {
                    if (fieldDescriptor.bindingClass().equals(indexFieldClass)) {
                        final Optional<IndexFieldMapper<?, ?>> matchingMapper = availableMappers.stream().filter(mapper -> mapper.isCompatibleWith(fieldDescriptor.bindingClass()) && (mapper.adapterFieldCount() == 1)).findFirst();
                        if (matchingMapper.isPresent()) {
                            final IndexFieldMapper<?, ?> mapper = matchingMapper.get();
                            mapperFound = true;
                            mapper.init(indexFieldName, (List) Lists.newArrayList(fieldDescriptor), indexFieldOptions);
                            mappers.put(indexFieldName, mapper);
                            break;
                        }
                    }
                }
            }
            // Check other mappers
            if (!mapperFound) {
                for (final IndexFieldMapper<?, ?> mapper : availableMappers) {
                    final List<FieldDescriptor<?>> matchingFields = Arrays.stream(adapterFields).filter(field -> mapper.isCompatibleWith(field.bindingClass())).collect(Collectors.toList());
                    if (matchingFields.size() >= mapper.adapterFieldCount()) {
                        mapperFound = true;
                        mapper.init(indexFieldName, (List) matchingFields.stream().limit(mapper.adapterFieldCount()).collect(Collectors.toList()), indexFieldOptions);
                        mappers.put(indexFieldName, mapper);
                        break;
                    }
                }
            }
            if (!mapperFound) {
                throw new IllegalArgumentException("No suitable index field mapper could be found for the index field " + indexFieldName);
            }
        }
    }
    return new AdapterToIndexMapping(adapter.getAdapterId(), index.getName(), mappers.values().stream().collect(Collectors.toList()));
}
Also used : Arrays(java.util.Arrays) ParameterException(com.beust.jcommander.ParameterException) SortedSet(java.util.SortedSet) DataWriter(org.locationtech.geowave.core.store.data.DataWriter) Maps(com.beust.jcommander.internal.Maps) BiFunction(java.util.function.BiFunction) CommonIndexAggregation(org.locationtech.geowave.core.store.query.aggregate.CommonIndexAggregation) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) LoggerFactory(org.slf4j.LoggerFactory) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) LazyReadPersistenceEncoding(org.locationtech.geowave.core.store.adapter.LazyReadPersistenceEncoding) Aggregation(org.locationtech.geowave.core.store.api.Aggregation) Collections2(com.google.common.collect.Collections2) ByteBuffer(java.nio.ByteBuffer) MetadataQuery(org.locationtech.geowave.core.store.operations.MetadataQuery) NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) PartialAsyncPersistenceEncoding(org.locationtech.geowave.core.store.adapter.PartialAsyncPersistenceEncoding) TransientAdapterStore(org.locationtech.geowave.core.store.adapter.TransientAdapterStore) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) FieldInfo(org.locationtech.geowave.core.store.base.IntermediaryWriteEntryInfo.FieldInfo) GeoWaveMetadata(org.locationtech.geowave.core.store.entities.GeoWaveMetadata) Wrapper(org.locationtech.geowave.core.store.CloseableIterator.Wrapper) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) VisibilityComposer(org.locationtech.geowave.core.store.data.visibility.VisibilityComposer) BitmaskedPairComparator(org.locationtech.geowave.core.store.flatten.BitmaskedPairComparator) Collection(java.util.Collection) Set(java.util.Set) IndexedAdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.IndexedAdapterPersistenceEncoding) Collectors(java.util.stream.Collectors) IndexUtils(org.locationtech.geowave.core.index.IndexUtils) ScanCallback(org.locationtech.geowave.core.store.callback.ScanCallback) Sets(com.google.common.collect.Sets) List(java.util.List) VisibilityHandler(org.locationtech.geowave.core.store.api.VisibilityHandler) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) BitmaskUtils(org.locationtech.geowave.core.store.flatten.BitmaskUtils) Entry(java.util.Map.Entry) Optional(java.util.Optional) FieldWriter(org.locationtech.geowave.core.store.data.field.FieldWriter) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) IndexFieldMapperRegistry(org.locationtech.geowave.core.store.index.IndexFieldMapperRegistry) DataStoreProperty(org.locationtech.geowave.core.store.DataStoreProperty) StringUtils(org.locationtech.geowave.core.index.StringUtils) DataIndexUtils(org.locationtech.geowave.core.store.base.dataidx.DataIndexUtils) GeoWaveValueImpl(org.locationtech.geowave.core.store.entities.GeoWaveValueImpl) AdapterPersistenceEncoding(org.locationtech.geowave.core.store.adapter.AdapterPersistenceEncoding) IndexFieldMapper(org.locationtech.geowave.core.store.api.IndexFieldMapper) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) IndexDimensionHint(org.locationtech.geowave.core.index.IndexDimensionHint) DataIndexRetrieval(org.locationtech.geowave.core.store.base.dataidx.DataIndexRetrieval) Function(java.util.function.Function) TreeSet(java.util.TreeSet) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) FullAsyncPersistenceEncoding(org.locationtech.geowave.core.store.adapter.FullAsyncPersistenceEncoding) LinkedHashMap(java.util.LinkedHashMap) MetadataType(org.locationtech.geowave.core.store.operations.MetadataType) Lists(com.google.common.collect.Lists) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Suppliers(com.google.common.base.Suppliers) VarintUtils(org.locationtech.geowave.core.index.VarintUtils) AsyncPersistenceEncoding(org.locationtech.geowave.core.store.adapter.AsyncPersistenceEncoding) IndexFieldOptions(org.locationtech.geowave.core.store.api.IndexFieldMapper.IndexFieldOptions) PropertyStore(org.locationtech.geowave.core.store.PropertyStore) LinkedList(java.util.LinkedList) BatchDataIndexRetrieval(org.locationtech.geowave.core.store.base.dataidx.BatchDataIndexRetrieval) Index(org.locationtech.geowave.core.store.api.Index) Nullable(javax.annotation.Nullable) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) DataStoreOperations(org.locationtech.geowave.core.store.operations.DataStoreOperations) Logger(org.slf4j.Logger) CommonIndexModel(org.locationtech.geowave.core.store.index.CommonIndexModel) MetadataReader(org.locationtech.geowave.core.store.operations.MetadataReader) IOException(java.io.IOException) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) AttributeIndex(org.locationtech.geowave.core.store.api.AttributeIndex) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) AdapterException(org.locationtech.geowave.core.store.adapter.exceptions.AdapterException) RowMergingDataAdapter(org.locationtech.geowave.core.store.adapter.RowMergingDataAdapter) CustomIndexStrategy(org.locationtech.geowave.core.index.CustomIndexStrategy) AdapterAndIndexBasedQueryConstraints(org.locationtech.geowave.core.store.query.constraints.AdapterAndIndexBasedQueryConstraints) Comparator(java.util.Comparator) Collections(java.util.Collections) NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) IndexFieldMapper(org.locationtech.geowave.core.store.api.IndexFieldMapper) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) IndexDimensionHint(org.locationtech.geowave.core.index.IndexDimensionHint) AttributeIndex(org.locationtech.geowave.core.store.api.AttributeIndex) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IndexDimensionHint(org.locationtech.geowave.core.index.IndexDimensionHint) IndexFieldOptions(org.locationtech.geowave.core.store.api.IndexFieldMapper.IndexFieldOptions)

Example 5 with FieldDescriptor

use of org.locationtech.geowave.core.store.adapter.FieldDescriptor in project geowave by locationtech.

the class DescribeTypeCommand method computeResults.

@Override
public Void computeResults(final OperationParams params) {
    // Ensure we have all the required arguments
    if (parameters.size() != 2) {
        throw new ParameterException("Requires arguments: <store name> <type name>");
    }
    final String inputStoreName = parameters.get(0);
    final String typeName = parameters.get(1);
    // Attempt to load store.
    inputStoreOptions = CLIUtils.loadStore(inputStoreName, getGeoWaveConfigFile(params), params.getConsole());
    LOGGER.info("Describing everything in store: " + inputStoreName + " with type name: " + typeName);
    final PersistentAdapterStore adapterStore = inputStoreOptions.createAdapterStore();
    final InternalAdapterStore internalAdapterStore = inputStoreOptions.createInternalAdapterStore();
    final DataTypeAdapter<?> type = adapterStore.getAdapter(internalAdapterStore.getAdapterId(typeName)).getAdapter();
    final FieldDescriptor<?>[] typeFields = type.getFieldDescriptors();
    final List<List<Object>> rows = new ArrayList<>();
    for (final FieldDescriptor<?> field : typeFields) {
        final List<Object> row = new ArrayList<>();
        row.add(field.fieldName());
        row.add(field.bindingClass().getName());
        rows.add(row);
    }
    final List<String> headers = new ArrayList<>();
    headers.add("Field");
    headers.add("Class");
    params.getConsole().println("Data type class: " + type.getDataClass().getName());
    params.getConsole().println("\nFields:");
    final ConsoleTablePrinter cp = new ConsoleTablePrinter(params.getConsole());
    cp.print(headers, rows);
    final Map<String, String> additionalProperties = type.describe();
    if (additionalProperties.size() > 0) {
        rows.clear();
        headers.clear();
        headers.add("Property");
        headers.add("Value");
        params.getConsole().println("\nAdditional Properties:");
        for (final Entry<String, String> property : additionalProperties.entrySet()) {
            final List<Object> row = new ArrayList<>();
            row.add(property.getKey());
            row.add(property.getValue());
            rows.add(row);
        }
        cp.print(headers, rows);
    }
    return null;
}
Also used : InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) ArrayList(java.util.ArrayList) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) ParameterException(com.beust.jcommander.ParameterException) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleTablePrinter(org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter)

Aggregations

FieldDescriptor (org.locationtech.geowave.core.store.adapter.FieldDescriptor)5 List (java.util.List)4 ParameterException (com.beust.jcommander.ParameterException)3 ArrayList (java.util.ArrayList)3 Index (org.locationtech.geowave.core.store.api.Index)3 InternalAdapterStore (org.locationtech.geowave.core.store.adapter.InternalAdapterStore)2 InternalDataAdapter (org.locationtech.geowave.core.store.adapter.InternalDataAdapter)2 PersistentAdapterStore (org.locationtech.geowave.core.store.adapter.PersistentAdapterStore)2 Parameter (com.beust.jcommander.Parameter)1 Maps (com.beust.jcommander.internal.Maps)1 Lists (com.clearspring.analytics.util.Lists)1 Suppliers (com.google.common.base.Suppliers)1 Collections2 (com.google.common.collect.Collections2)1 Iterators (com.google.common.collect.Iterators)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1