private ImmutableMap<ColumnIdent, IndexReferenceInfo> createIndexDefinitions() { ImmutableMap.Builder<ColumnIdent, IndexReferenceInfo> builder = ImmutableMap.builder(); for (Map.Entry<ColumnIdent, IndexReferenceInfo.Builder> entry : indicesBuilder.entrySet()) { builder.put(entry.getKey(), entry.getValue().build()); } indices = builder.build(); return indices; }
/** * Overwrite given values on the source. If the value is a map, it will not be merged but * overwritten. The keys of the changes map representing a path of the source map tree. If the * path doesn't exists, a new tree will be inserted. * * <p>TODO: detect NOOP */ @SuppressWarnings("unchecked") private void updateSourceByPaths(Map<String, Object> source, Map<String, Object> changes) { for (Map.Entry<String, Object> changesEntry : changes.entrySet()) { if (changesEntry.getKey().contains(".")) { // sub-path detected, dive recursive to the wanted tree element List<String> path = Splitter.on(".").splitToList(changesEntry.getKey()); String currentKey = path.get(0); if (!source.containsKey(currentKey)) { // insert parent tree element source.put(currentKey, new HashMap<String, Object>()); } Map<String, Object> subChanges = new HashMap<>(); subChanges.put(Joiner.on(".").join(path.subList(1, path.size())), changesEntry.getValue()); updateSourceByPaths((Map<String, Object>) source.get(currentKey), subChanges); } else { // overwrite or insert the field source.put(changesEntry.getKey(), changesEntry.getValue()); } } }
/** extracts index definitions as well */ @SuppressWarnings("unchecked") private void internalExtractColumnDefinitions( ColumnIdent columnIdent, 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()); columnProperties = furtherColumnProperties(columnProperties); ReferenceInfo.IndexType columnIndexType = getColumnIndexType(columnProperties); if (columnDataType == DataTypes.OBJECT || (columnDataType.id() == ArrayType.ID && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) { ColumnPolicy columnPolicy = ColumnPolicy.of(columnProperties.get("dynamic")); add(newIdent, columnDataType, columnPolicy, ReferenceInfo.IndexType.NO, false); 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); IndexReferenceInfo.Builder builder = getOrCreateIndexBuilder(targetIdent); builder.addColumn( newInfo(newIdent, columnDataType, ColumnPolicy.DYNAMIC, columnIndexType)); } } // is it an index? if (indicesMap.containsKey(newIdent.fqn())) { IndexReferenceInfo.Builder builder = getOrCreateIndexBuilder(newIdent); builder .indexType(columnIndexType) .ident(new ReferenceIdent(ident, newIdent)) .analyzer((String) columnProperties.get("analyzer")); } else { add(newIdent, columnDataType, columnIndexType); } } } }
private ImmutableMap<ColumnIdent, String> getAnalyzers( ColumnIdent columnIdent, Map<String, Object> propertiesMap) { ImmutableMap.Builder<ColumnIdent, String> builder = ImmutableMap.builder(); 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()); columnProperties = furtherColumnProperties(columnProperties); if (columnDataType == DataTypes.OBJECT || (columnDataType.id() == ArrayType.ID && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) { if (columnProperties.get("properties") != null) { builder.putAll( getAnalyzers(newIdent, (Map<String, Object>) columnProperties.get("properties"))); } } String analyzer = (String) columnProperties.get("analyzer"); if (analyzer != null) { builder.put(newIdent, analyzer); } } return builder.build(); }