FrankChen021 commented on code in PR #19410:
URL: https://github.com/apache/druid/pull/19410#discussion_r3195620253


##########
processing/src/main/java/org/apache/druid/segment/column/StringDictionaryEncodedColumnFormat.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.column;
+
+import org.apache.druid.data.input.impl.DimensionSchema;
+import org.apache.druid.data.input.impl.DimensionSchema.MultiValueHandling;
+import org.apache.druid.data.input.impl.NewSpatialDimensionSchema;
+import org.apache.druid.data.input.impl.StringDimensionSchema;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.segment.DimensionHandler;
+import org.apache.druid.segment.StringColumnFormatSpec;
+import org.apache.druid.segment.StringDimensionHandler;
+
+import javax.annotation.Nullable;
+import java.util.Collections;
+
+public class StringDictionaryEncodedColumnFormat implements ColumnFormat
+{
+  private final boolean hasMultipleValues;
+  private final boolean hasNulls;
+  private final boolean hasBitmapIndexes;
+  private final boolean hasSpatialIndexes;
+  @Nullable
+  private final StringColumnFormatSpec columnFormatSpec;
+
+  public StringDictionaryEncodedColumnFormat(
+      boolean hasMultipleValues,
+      boolean hasNulls,
+      boolean hasBitmapIndexes,
+      boolean hasSpatialIndexes,
+      @Nullable StringColumnFormatSpec columnFormatSpec
+  )
+  {
+    this.hasMultipleValues = hasMultipleValues;
+    this.hasNulls = hasNulls;
+    this.hasBitmapIndexes = hasBitmapIndexes;
+    this.hasSpatialIndexes = hasSpatialIndexes;
+    this.columnFormatSpec = columnFormatSpec;
+  }
+
+  @Override
+  public ColumnType getLogicalType()
+  {
+    return ColumnType.STRING;
+  }
+
+  @Override
+  public ColumnCapabilities toColumnCapabilities()
+  {
+    return ColumnCapabilitiesImpl.createDefault()
+                                 .setType(ColumnType.STRING)
+                                 .setDictionaryEncoded(true)
+                                 .setDictionaryValuesSorted(true)
+                                 .setDictionaryValuesUnique(true)
+                                 .setHasMultipleValues(hasMultipleValues)
+                                 .setHasNulls(hasNulls)
+                                 .setHasBitmapIndexes(hasBitmapIndexes)
+                                 .setHasSpatialIndexes(hasSpatialIndexes);
+  }
+
+  @Override
+  public DimensionHandler getColumnHandler(String columnName)
+  {
+    Integer maxStringLength = columnFormatSpec != null ? 
columnFormatSpec.getMaxStringLength() : null;
+    return new StringDimensionHandler(
+        columnName,
+        MultiValueHandling.ofDefault(),

Review Comment:
   [P1] Persisted string format drops multi-value handling when rebuilding 
handlers
   
   getColumnHandler reconstructs the StringDimensionHandler with 
MultiValueHandling.ofDefault() even when columnFormatSpec contains an explicit 
multiValueHandling. IndexMergerBase and IncrementalIndex.loadDimensionIterable 
call getColumnHandler directly, so compacting or loading persisted string 
columns with ARRAY or SORTED_SET can silently switch back to the default 
behavior and reorder or deduplicate multi-value strings. Derive the handler's 
multiValueHandling from columnFormatSpec when present, matching 
StringDimensionSchema.getDimensionHandler.



##########
processing/src/main/java/org/apache/druid/segment/column/CapabilitiesBasedFormat.java:
##########
@@ -102,6 +102,10 @@ public ColumnFormat merge(@Nullable ColumnFormat 
otherFormat)
       return this;
     }
 
+    if (otherFormat instanceof StringDictionaryEncodedColumnFormat) {

Review Comment:
   [P1] String format merge bypasses type compatibility checks
   
   This delegation happens before CapabilitiesBasedFormat's existing type 
checks, and StringDictionaryEncodedColumnFormat.merge accepts any 
CapabilitiesBasedFormat without validating its logical type. If one segment has 
a string-specific format for a column and another legacy segment reports the 
same column as LONG, DOUBLE, COMPLEX, etc., the merge now produces a STRING 
format instead of rejecting the incompatible schemas. Restrict delegation to 
compatible string capabilities or perform the same logical/element/complex type 
validation in StringDictionaryEncodedColumnFormat.merge before merging.



-- 
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]

Reply via email to