clintropolis commented on code in PR #19258: URL: https://github.com/apache/druid/pull/19258#discussion_r3029928169
########## processing/src/main/java/org/apache/druid/segment/StringColumnFormatSpec.java: ########## @@ -0,0 +1,205 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.segment; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.druid.data.input.impl.DimensionSchema; + +import javax.annotation.Nullable; +import java.util.Objects; + +public class StringColumnFormatSpec +{ + private static final StringColumnFormatSpec DEFAULT = + builder() + .setCreateBitmapIndex(true) + .setMultiValueHandling(DimensionSchema.MultiValueHandling.SORTED_ARRAY) + .build(); + + public static Builder builder() + { + return new Builder(); + } + + public static Builder builder(StringColumnFormatSpec spec) + { + return new Builder(spec); + } + + public static StringColumnFormatSpec getEffectiveFormatSpec( + @Nullable StringColumnFormatSpec columnFormatSpec, + IndexSpec indexSpec + ) + { + final Builder builder = columnFormatSpec == null ? builder() : builder(columnFormatSpec); + + final StringColumnFormatSpec defaultSpec; + if (indexSpec.getStringColumnFormatSpec() != null) { + defaultSpec = indexSpec.getStringColumnFormatSpec(); + } else { + defaultSpec = DEFAULT; + } + + if (builder.createBitmapIndex == null) { + if (defaultSpec.getCreateBitmapIndex() != null) { + builder.setCreateBitmapIndex(defaultSpec.getCreateBitmapIndex()); + } else { + builder.setCreateBitmapIndex(DEFAULT.getCreateBitmapIndex()); + } + } + + if (builder.multiValueHandling == null) { + if (defaultSpec.getMultiValueHandling() != null) { + builder.setMultiValueHandling(defaultSpec.getMultiValueHandling()); + } else { + builder.setMultiValueHandling(DEFAULT.getMultiValueHandling()); + } + } + + if (builder.maxStringLength == null) { + // No DEFAULT fallback needed: null means "no truncation" + builder.setMaxStringLength(defaultSpec.getMaxStringLength()); + } + + return builder.build(); + } + + @Nullable + private final Boolean createBitmapIndex; + + @Nullable + private final DimensionSchema.MultiValueHandling multiValueHandling; + + @Nullable + private final Integer maxStringLength; + + @JsonCreator + public StringColumnFormatSpec( + @JsonProperty("createBitmapIndex") @Nullable Boolean createBitmapIndex, Review Comment: I was thinking we would switch this to using something like `BitmapIndexType` we have for `NestedCommonFormatColumnFormatSpec` used to control which indexes we build for long and double json fields, since ideally we can introduce some flexibility here so that we can more easily support different kinds of indexes on string columns that specifying with a bunch of booleans would be tedious. I think this implementation can be a lot simpler than `BitmapIndexType` for now, we can worry about how index building can be abstracted for strings in the dimension indexer/mergers/serializers later when we actually introduce such a thing. I think there are 2 options we need to add to model the current state, `dictionaryEncodedValueIndex` and `none`, so we could make an abstract `StringIndexType` or `StringBitmapIndexType` and have basically empty implementations for `NoIndex` and `DictionaryEncodedValueIndex` (only needs like equals/hashcode implemented i think and maybe a static final instantiation to share) to use as a placeholder for future enhancement. Then we can wire this `indexType` with those values up to the existing boolean all the stuff uses. Can you look into making this change? ########## processing/src/main/java/org/apache/druid/data/input/impl/StringDimensionSchema.java: ########## @@ -66,11 +72,23 @@ public StringDimensionSchema( @JsonProperty("name") String name, @JsonProperty("multiValueHandling") MultiValueHandling multiValueHandling, @JsonProperty("createBitmapIndex") Boolean createBitmapIndex, - @JsonProperty("maxStringLength") @Nullable Integer maxStringLength + @JsonProperty("maxStringLength") @Nullable Integer maxStringLength, Review Comment: since `maxStringLength` hasn't been released, should we just remove this in favor of the `columnFormatSpec`? ########## server/src/main/java/org/apache/druid/segment/realtime/sink/Sink.java: ########## @@ -306,11 +315,12 @@ public List<SinkSegmentReference> acquireSegmentReferences( private FireHydrant makeNewCurrIndex(long minTimestamp, DataSchema schema) { + final DimensionsSpec dimensionsSpec = resolveEffectiveDimensionsSpec(schema.getDimensionsSpec()); Review Comment: ah, i guess we have to do this here now because we need to know stuff up front when making the column indexers, seems worth leaving a comment explaining why we do this ########## server/src/main/java/org/apache/druid/segment/realtime/sink/Sink.java: ########## @@ -386,6 +396,20 @@ private FireHydrant makeNewCurrIndex(long minTimestamp, DataSchema schema) return old; } + private DimensionsSpec resolveEffectiveDimensionsSpec(DimensionsSpec dimensionsSpec) + { + if (indexSpec == null) { + return dimensionsSpec; + } + final List<DimensionSchema> effectiveDimensions = dimensionsSpec.getDimensions() + .stream() + .map(dim -> dim.getEffectiveSchema(indexSpec)) + .collect(Collectors.toList()); + return DimensionsSpec.builder(dimensionsSpec) + .setDimensions(effectiveDimensions) + .build(); + } + Review Comment: i think in the constructor we should call `getEffectiveSpec` on the `indexSpec` so that it is filled in with system defaults. We should also probably set it to `IndexSpec.default()` if it is null, so then we always resolve the effective schemas to fill in system default values -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
