Search in sources :

Example 1 with DOC_VALUES

use of org.elasticsearch.index.mapper.TypeParsers.DOC_VALUES in project crate by crate.

the class DocIndexMetadata method internalExtractColumnDefinitions.

/**
 * extracts index definitions as well
 */
@SuppressWarnings("unchecked")
private void internalExtractColumnDefinitions(@Nullable ColumnIdent columnIdent, @Nullable Map<String, Object> propertiesMap) {
    if (propertiesMap == null) {
        return;
    }
    var columns = propertiesMap.entrySet().stream().sorted(SORT_BY_POSITION_THEN_NAME).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
    for (Map.Entry<String, Object> columnEntry : columns.entrySet()) {
        Map<String, Object> columnProperties = (Map) columnEntry.getValue();
        DataType columnDataType = getColumnDataType(columnProperties);
        ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());
        boolean nullable = !notNullColumns.contains(newIdent);
        columnProperties = furtherColumnProperties(columnProperties);
        int position = columnPosition((int) columnProperties.getOrDefault("position", 0));
        String defaultExpression = (String) columnProperties.getOrDefault("default_expr", null);
        Reference.IndexType columnIndexType = getColumnIndexType(columnProperties);
        StorageSupport storageSupport = columnDataType.storageSupport();
        assert storageSupport != null : "DataType used in table definition must have storage support: " + columnDataType;
        boolean docValuesDefault = storageSupport.getComputedDocValuesDefault(columnIndexType);
        boolean hasDocValues = Booleans.parseBoolean(columnProperties.getOrDefault(DOC_VALUES, docValuesDefault).toString());
        if (columnDataType == DataTypes.GEO_SHAPE) {
            String geoTree = (String) columnProperties.get("tree");
            String precision = (String) columnProperties.get("precision");
            Integer treeLevels = (Integer) columnProperties.get("tree_levels");
            Double distanceErrorPct = (Double) columnProperties.get("distance_error_pct");
            addGeoReference(position, newIdent, geoTree, precision, treeLevels, distanceErrorPct);
        } else if (columnDataType.id() == ObjectType.ID || (columnDataType.id() == ArrayType.ID && ((ArrayType) columnDataType).innerType().id() == ObjectType.ID)) {
            ColumnPolicy columnPolicy = ColumnPolicies.decodeMappingValue(columnProperties.get("dynamic"));
            add(position, newIdent, columnDataType, defaultExpression, columnPolicy, Reference.IndexType.NONE, nullable, hasDocValues);
            if (columnProperties.get("properties") != null) {
                // walk nested
                internalExtractColumnDefinitions(newIdent, (Map<String, Object>) columnProperties.get("properties"));
            }
        } else if (columnDataType != DataTypes.NOT_SUPPORTED) {
            List<String> copyToColumns = Maps.get(columnProperties, "copy_to");
            // extract columns this column is copied to, needed for indices
            if (copyToColumns != null) {
                for (String copyToColumn : copyToColumns) {
                    ColumnIdent targetIdent = ColumnIdent.fromPath(copyToColumn);
                    IndexReference.Builder builder = getOrCreateIndexBuilder(targetIdent);
                    builder.addColumn(newInfo(position, newIdent, columnDataType, defaultExpression, ColumnPolicy.DYNAMIC, columnIndexType, false, hasDocValues));
                }
            }
            // is it an index?
            if (indicesMap.containsKey(newIdent.fqn())) {
                IndexReference.Builder builder = getOrCreateIndexBuilder(newIdent);
                builder.indexType(columnIndexType).analyzer((String) columnProperties.get("analyzer"));
            } else {
                add(position, newIdent, columnDataType, defaultExpression, ColumnPolicy.DYNAMIC, columnIndexType, nullable, hasDocValues);
            }
        }
    }
}
Also used : ParamTypeHints(io.crate.analyze.ParamTypeHints) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) FieldProvider(io.crate.analyze.relations.FieldProvider) TableReferenceResolver(io.crate.analyze.expressions.TableReferenceResolver) ArrayType(io.crate.types.ArrayType) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) Map(java.util.Map) StorageSupport(io.crate.types.StorageSupport) MapBuilder(io.crate.common.collections.MapBuilder) NodeContext(io.crate.metadata.NodeContext) GeneratedReference(io.crate.metadata.GeneratedReference) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Lists2(io.crate.common.collections.Lists2) CheckConstraint(io.crate.sql.tree.CheckConstraint) Booleans(io.crate.common.Booleans) Objects(java.util.Objects) List(java.util.List) Version(org.elasticsearch.Version) MappingMetadata(org.elasticsearch.cluster.metadata.MappingMetadata) Symbol(io.crate.expression.symbol.Symbol) KeywordFieldMapper(org.elasticsearch.index.mapper.KeywordFieldMapper) DataTypes(io.crate.types.DataTypes) ReferenceIdent(io.crate.metadata.ReferenceIdent) GeoReference(io.crate.metadata.GeoReference) Expression(io.crate.sql.tree.Expression) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) NumberOfReplicas(io.crate.analyze.NumberOfReplicas) HashMap(java.util.HashMap) ObjectType(io.crate.types.ObjectType) Operation(io.crate.metadata.table.Operation) IndexReference(io.crate.metadata.IndexReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ColumnPolicy(io.crate.sql.tree.ColumnPolicy) SqlParser(io.crate.sql.parser.SqlParser) Nullable(javax.annotation.Nullable) ColumnPolicies(io.crate.metadata.table.ColumnPolicies) StringType(io.crate.types.StringType) ExpressionAnalysisContext(io.crate.analyze.expressions.ExpressionAnalysisContext) Maps(io.crate.common.collections.Maps) DateFieldMapper(org.elasticsearch.index.mapper.DateFieldMapper) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) BitStringFieldMapper(org.elasticsearch.index.mapper.BitStringFieldMapper) IOException(java.io.IOException) DOC_VALUES(org.elasticsearch.index.mapper.TypeParsers.DOC_VALUES) RowGranularity(io.crate.metadata.RowGranularity) BitStringType(io.crate.types.BitStringType) Comparator(java.util.Comparator) Collections(java.util.Collections) ColumnPolicy(io.crate.sql.tree.ColumnPolicy) GeneratedReference(io.crate.metadata.GeneratedReference) GeoReference(io.crate.metadata.GeoReference) IndexReference(io.crate.metadata.IndexReference) Reference(io.crate.metadata.Reference) CheckConstraint(io.crate.sql.tree.CheckConstraint) ArrayType(io.crate.types.ArrayType) ColumnIdent(io.crate.metadata.ColumnIdent) StorageSupport(io.crate.types.StorageSupport) DataType(io.crate.types.DataType) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IndexReference(io.crate.metadata.IndexReference)

Aggregations

NumberOfReplicas (io.crate.analyze.NumberOfReplicas)1 ParamTypeHints (io.crate.analyze.ParamTypeHints)1 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 TableReferenceResolver (io.crate.analyze.expressions.TableReferenceResolver)1 FieldProvider (io.crate.analyze.relations.FieldProvider)1 Booleans (io.crate.common.Booleans)1 Lists2 (io.crate.common.collections.Lists2)1 MapBuilder (io.crate.common.collections.MapBuilder)1 Maps (io.crate.common.collections.Maps)1 Symbol (io.crate.expression.symbol.Symbol)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)1 GeneratedReference (io.crate.metadata.GeneratedReference)1 GeoReference (io.crate.metadata.GeoReference)1 IndexReference (io.crate.metadata.IndexReference)1 NodeContext (io.crate.metadata.NodeContext)1 Reference (io.crate.metadata.Reference)1 ReferenceIdent (io.crate.metadata.ReferenceIdent)1 RelationName (io.crate.metadata.RelationName)1