Search in sources :

Example 1 with ColumnPolicy

use of io.crate.metadata.table.ColumnPolicy 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;
    }
    for (Map.Entry<String, Object> columnEntry : propertiesMap.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);
        Reference.IndexType columnIndexType = getColumnIndexType(columnProperties);
        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(newIdent, geoTree, precision, treeLevels, distanceErrorPct);
        } else if (columnDataType == DataTypes.OBJECT || (columnDataType.id() == ArrayType.ID && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) {
            ColumnPolicy columnPolicy = ColumnPolicy.of(columnProperties.get("dynamic"));
            add(newIdent, columnDataType, columnPolicy, Reference.IndexType.NO, false, nullable);
            if (columnProperties.get("properties") != null) {
                // walk nested
                internalExtractColumnDefinitions(newIdent, (Map<String, Object>) columnProperties.get("properties"));
            }
        } else if (columnDataType != DataTypes.NOT_SUPPORTED) {
            List<String> copyToColumns = getNested(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(newIdent, columnDataType, ColumnPolicy.DYNAMIC, columnIndexType, false));
                }
            }
            // is it an index?
            if (indicesMap.containsKey(newIdent.fqn())) {
                IndexReference.Builder builder = getOrCreateIndexBuilder(newIdent);
                builder.indexType(columnIndexType).analyzer((String) columnProperties.get("analyzer"));
            } else {
                add(newIdent, columnDataType, columnIndexType, nullable);
            }
        }
    }
}
Also used : ColumnPolicy(io.crate.metadata.table.ColumnPolicy) DataType(io.crate.types.DataType)

Aggregations

ColumnPolicy (io.crate.metadata.table.ColumnPolicy)1 DataType (io.crate.types.DataType)1