use of io.crate.types.StorageSupport 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);
}
}
}
}
Aggregations