924060929 commented on code in PR #70408:
URL: https://github.com/apache/doris/pull/70408#discussion_r4663426970
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java:
##########
@@ -221,7 +235,10 @@ public boolean equals(Object o) {
&& this.enableTypedPathsToSparse ==
other.enableTypedPathsToSparse
&& this.enableVariantDocMode == other.enableVariantDocMode
&& this.variantDocMaterializationMinRows ==
other.variantDocMaterializationMinRows
- && Objects.equals(predefinedFields,
other.predefinedFields);
+ && Objects.equals(predefinedFields, other.predefinedFields)
+ // the serialize type only changes what a max subcolumns
count of 0 means
+ && (variantMaxSubcolumnsCount != 0 || enableNestedGroup
+ || this.variantSerializeType ==
other.variantSerializeType);
Review Comment:
Two issues in `equals` / `hashCode`:
1. `equals` misses `this.enableNestedGroup == other.enableNestedGroup`,
which breaks symmetry: for `A` (`count=0, enableNestedGroup=true, V2`) and `B`
(`count=0, enableNestedGroup=false, V1`), `A.equals(B)` is `true` while
`B.equals(A)` is `false`; for `C` (`count=0, enableNestedGroup=false, V2`),
`A.equals(C)` is `true`. In `TypeCoercionUtils.findWiderTypeForTwo` (`if
(left.equals(right)) return Optional.of(left)`) and `SimplifyCastRule`, this
leaks `enableNestedGroup=true` across `UNION ALL` / `CAST`.
2. `hashCode()` hashes `variantMaxSparseColumnStatisticsSize`,
`variantSparseHashShardCount`, and `variantDocShardCount` (e.g., `new
VariantType(2048)` has `docShard=64` while parsed types have `0`), whereas
`equals()` ignores them. `equals()` should compare all effective storage
fields, and `hashCode()` must match (normalizing `variantSerializeType` when
`variantMaxSubcolumnsCount != 0 || enableNestedGroup`).
##########
fe/fe-type/src/main/java/org/apache/doris/catalog/VariantType.java:
##########
@@ -235,7 +262,10 @@ public boolean equals(Object other) {
&& enableTypedPathsToSparse ==
otherVariantType.enableTypedPathsToSparse
&& enableVariantDocMode ==
otherVariantType.enableVariantDocMode
&& variantDocMaterializationMinRows ==
otherVariantType.variantDocMaterializationMinRows
- && enableNestedGroup == otherVariantType.enableNestedGroup;
+ && enableNestedGroup == otherVariantType.enableNestedGroup
+ // the serialize type only changes what a max subcolumns count
of 0 means
+ && (variantMaxSubcolumnsCount != 0 || enableNestedGroup
+ || variantSerializeType ==
otherVariantType.variantSerializeType);
Review Comment:
`equals` omits `variantMaxSparseColumnStatisticsSize`,
`variantSparseHashShardCount`, and `variantDocShardCount`, and `VariantType`
does not override `hashCode()`. `Column.equals` (used by `SchemaChangeHandler`
and `MTMVPlanUtil.isTypeLike`) therefore treats columns with different shard
counts or sparse stats sizes as equal. Compare all storage properties here and
override `hashCode()` consistently.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java:
##########
@@ -184,7 +185,9 @@ public void validateCreateTableAsSelect(ConnectContext ctx,
LogicalPlan query) {
Slot s = slots.get(i);
DataType dataType = s.getDataType().conversion();
if (dataType instanceof VariantType) {
- dataType = ((VariantType) dataType).withoutPredefinedFields();
+ // the created column is new, even when the query reads an old
V1 or an external column
+ dataType = ((VariantType) dataType).withoutPredefinedFields()
+ .withSerializeType(TVariantSerializeType.V2);
Review Comment:
1. Computed expressions (`parse_to_variant`, `coalesce`/`union` via
`TypeCoercionUtils.findCommonVariantType()`, and external connector columns via
`ConnectorComputeVariantType`) use `VariantType.INSTANCE = new VariantType(0)`
as a compute placeholder without table storage properties (`0` previously meant
unlimited). Promoting that `0` directly to `V2` turns off all dynamic subcolumn
extraction for CTAS/MTMV over computed expressions, `UNION ALL` of two
`2048`-limit tables, or external tables—unlike `CREATE TABLE (v VARIANT)` which
defaults to `2048`. Distinguish unbound compute `VariantType` from
storage-configured `VariantType`, and apply session defaults (`2048`) at
table-creation boundaries.
2. Parallel path missed: synchronous materialized views
(`CreateMaterializedViewCommand` -> `MVColumnItem`) translate computed
`VARIANT` expressions directly via `toCatalogDataType()`, leaving newly created
sync MV columns as `V1`.
##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java:
##########
@@ -519,6 +521,13 @@ public static List<ColumnDefinition> generateColumns(Plan
plan, ConnectContext c
public static DataType getDataType(Slot s, int i, ConnectContext ctx,
String partitionCol,
Set<String> distributionColumnNames) {
DataType dataType = s.getDataType().conversion();
+ boolean tableColumn = s instanceof SlotReference && ((SlotReference)
s).getOriginalColumn().isPresent()
+ && ((SlotReference) s).getSubPath().isEmpty();
Review Comment:
`tableColumn` is also `true` for external catalog scans
(`ConnectorComputeVariantType` after `conversion()`) and
`ExternalFileTableValuedFunction` slots, since both produce a `SlotReference`
with `originalColumn` present and empty `subPath`. That skips
`.withSerializeType(V2)` and stores newly created MTMV columns over external
tables/TVFs as `V1`. Check
`getOriginalTable().filter(TableIf::isManagedTable).isPresent()` (matching line
538 below).
##########
fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java:
##########
@@ -1008,6 +1009,13 @@ private boolean processModifyColumn(ModifyColumnOp
modifyColumnOp, OlapTable ola
if (col.getName().equalsIgnoreCase(newColName)) {
modColIndex = i;
found = true;
+ // A restated definition parses as V2 and cannot state
variant_enable_typed_paths_to_sparse, but the
+ // column keeps the layout its data is stored with.
+ if (col.getType().isVariantType() &&
modColumn.getType().isVariantType()) {
+ modColumn.setType(((VariantType) modColumn.getType())
+ .withSerializeType(col.getVariantSerializeType())
+
.withEnableTypedPathsToSparse(col.getVariantEnableTypedPathsToSparse()));
+ }
Review Comment:
Inheriting `variantSerializeType` and `enableTypedPathsToSparse` only here
happens after `ModifyColumnOp.validate()`, which already translates `columnDef`
(as `V2`, `typedPathsToSparse=false`) and calls
`originalColumn.checkSchemaChangeAllowed(column)`. Removing the
`enableTypedPathsToSparse` check from `Column.checkSchemaChangeAllowed`
(`Column.java:819`) to get past `ModifyColumnOp.validate()` weakens `Column`'s
invariant check. Apply this inheritance in `ModifyColumnOp.validate()` via a
shared helper (keep it idempotent here), and check both
`enableTypedPathsToSparse` and `variantSerializeType` in
`Column.checkSchemaChangeAllowed`.
##########
fe/fe-catalog/src/main/java/org/apache/doris/catalog/Column.java:
##########
@@ -928,6 +933,12 @@ public String toSql(boolean isUniqueTable, boolean
isCompatible, boolean useGene
} else {
sb.append(typeStr);
}
+ if (isCompatible && type.isVariantType()) {
+ // The DDL of an internal table shows the serialize type in a
comment, which the parser skips: a column
+ // the DDL creates is new (V2) whatever it says.
+ sb.append(" /* variant_serialize_type = ")
+ .append(getVariantSerializeType() ==
TVariantSerializeType.V2 ? "v2" : "v1").append(" */");
+ }
Review Comment:
Emitting `variant_serialize_type` only as a SQL comment breaks CCR binlog
sync (`CreateTableRecord` -> `Env.getSyncedDdlStmt` -> `Column.toSql`). When
syncing an upgraded `V1` (`count=0`) table to a 4.2 target cluster, the target
parses this DDL into a `V2` (`count=0`) table and then physically ingests `V1`
rowset segments containing extracted dynamic subcolumns, causing target reads
(`check_variant_serialize_type_layout`) and compaction to fail with
`InternalError`.
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -3819,14 +3809,15 @@ public void
checkAnnIndexCandidateRowsPercentThreshold(String value) {
)
public long defaultVariantDocMaterializationMinRows = 0L;
+ // the shard count with and without doc mode
@VarAttrDef.VarAttr(
name = DEBUG_VARIANT_DOC_HASH_SHARD_COUNT,
flag = VarAttrDef.INVISIBLE,
needForward = true,
checker = "checkDefaultVariantSettable",
fuzzy = true
)
- public int defaultVariantDocHashShardCount = 64;
+ public int defaultVariantDocHashShardCount = 0;
Review Comment:
Changing `defaultVariantDocHashShardCount` from `64` to `0` (1 shard)
changes the default shard count for new DOC-mode columns, and requires `MODIFY
COLUMN` on 4.1 DOC-mode tables (stored with `max_subcolumns_count=0,
doc_shard=64` by default) to explicitly restate both old defaults. Document
this default change in the PR Release Note, and align the hardcoded
`this.variantDocShardCount = 64` in `VariantType` constructors
(`catalog/VariantType.java:85`, `nereids/types/VariantType.java:78`).
##########
fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java:
##########
@@ -2391,19 +2393,15 @@ public static int
analyzeVariantMaxSubcolumnsCount(Map<String, String> propertie
return maxSubcoumnsCount;
}
+ // variant_enable_typed_paths_to_sparse is internal now: a column of an
older version keeps its value, and a new one
+ // takes it from the session variable
debug_variant_enable_typed_paths_to_sparse, which only tests set. The
+ // property is refused whatever its value.
public static boolean analyzeEnableTypedPathsToSparse(Map<String, String>
properties,
boolean defaultValue) throws AnalysisException {
- boolean enableTypedPathsToSparse = defaultValue;
if (properties != null &&
properties.containsKey(PROPERTIES_VARIANT_ENABLE_TYPED_PATHS_TO_SPARSE)) {
- String enableTypedPathsToSparseStr =
properties.get(PROPERTIES_VARIANT_ENABLE_TYPED_PATHS_TO_SPARSE);
- try {
- enableTypedPathsToSparse =
Boolean.parseBoolean(enableTypedPathsToSparseStr);
- } catch (Exception e) {
- throw new
AnalysisException("variant_enable_typed_paths_to_sparse must be `true` or
`false`");
- }
- properties.remove(PROPERTIES_VARIANT_ENABLE_TYPED_PATHS_TO_SPARSE);
+ throw new AnalysisException("variant_enable_typed_paths_to_sparse
is not supported");
Review Comment:
Rejecting `"variant_enable_typed_paths_to_sparse" = "false"` contradicts the
compatibility goal of keeping `variant_sparse_hash_shard_count` parseable:
before 4.2, `SHOW CREATE TABLE` (and pre-upgrade binlog DDL records) printed
`"variant_enable_typed_paths_to_sparse" = "false"` on every non-DOC `VARIANT`
column. Since `false` matches 4.2 semantics, accept `"false"` and only reject
`"true"` (or non-boolean values).
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -5473,8 +5475,9 @@ public DataType
visitVariantPredefinedFields(VariantPredefinedFieldsContext ctx)
.analyzeEnableTypedPathsToSparse(properties, enableTypedPathsToSparse);
variantMaxSparseColumnStatisticsSize =
PropertyAnalyzer.analyzeVariantMaxSparseColumnStatisticsSize(
properties,
variantMaxSparseColumnStatisticsSize);
- variantSparseHashShardCount =
-
PropertyAnalyzer.analyzeVariantSparseHashShardCount(properties,
variantSparseHashShardCount);
+ // The DDL of older versions sets the shard count without doc mode
with it; variant_doc_hash_shard_count
+ // sets the shard count in either mode now, so the value is
ignored.
+ PropertyAnalyzer.analyzeVariantSparseHashShardCount(properties, 0);
Review Comment:
Validating `variant_sparse_hash_shard_count` and silently dropping its value
causes two issues:
1. `CREATE TABLE ... ("variant_sparse_hash_shard_count" = "64")` succeeds
without warning while silently creating 1 shard instead of 64.
2. `ALTER TABLE old_t MODIFY COLUMN v
VARIANT<PROPERTIES("variant_sparse_hash_shard_count" = "64")> COMMENT '...'` on
an upgraded `shard=64` table resets the shard count to `0` and fails with `"Can
not change variant sparse bucket num"`.
Use the parsed `variant_sparse_hash_shard_count` as fallback when
`variant_doc_hash_shard_count` is not specified (and reject conflicting values
if both are set).
--
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]