924060929 commented on code in PR #70408:
URL: https://github.com/apache/doris/pull/70408#discussion_r4747957775
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/types/VariantType.java:
##########
@@ -130,14 +136,43 @@ public DataType conversion() {
.collect(Collectors.toList()),
variantMaxSubcolumnsCount, enableTypedPathsToSparse,
variantMaxSparseColumnStatisticsSize,
variantSparseHashShardCount,
enableVariantDocMode,
variantDocMaterializationMinRows,
- variantDocShardCount, enableNestedGroup);
+ variantDocShardCount, enableNestedGroup,
variantSerializeType);
+ }
+
+ /** This type with the given serialize type, as a new instance. */
+ public VariantType withSerializeType(TVariantSerializeType serializeType) {
+ return new VariantType(predefinedFields, variantMaxSubcolumnsCount,
enableTypedPathsToSparse,
+ variantMaxSparseColumnStatisticsSize,
variantSparseHashShardCount, enableVariantDocMode,
+ variantDocMaterializationMinRows, variantDocShardCount,
enableNestedGroup, serializeType);
+ }
+
+ /** This type with the given max subcolumns count, as a new instance. */
+ public VariantType withMaxSubcolumnsCount(int maxSubcolumnsCount) {
+ return new VariantType(predefinedFields, maxSubcolumnsCount,
enableTypedPathsToSparse,
+ variantMaxSparseColumnStatisticsSize,
variantSparseHashShardCount, enableVariantDocMode,
+ variantDocMaterializationMinRows, variantDocShardCount,
enableNestedGroup, variantSerializeType);
+ }
+
+ /**
+ * Resolves a VARIANT type for a newly created table/MV column. Unbound
compute placeholders
+ * ({@link #INSTANCE} or {@link ConnectorComputeVariantType}) and pruned
sub-paths carry no
+ * independent subcolumn limit, so they adopt the default limit alongside
V2, except when
+ * nested group is enabled (which requires max subcolumns count to stay 0).
+ */
+ public VariantType forNewTableColumn(DataType rawType, boolean isSubPath,
int defaultMaxSubcolumnsCount) {
+ VariantType result = this.withSerializeType(TVariantSerializeType.V2);
+ if (!result.enableNestedGroup
+ && (isSubPath || rawType == INSTANCE || rawType instanceof
ConnectorComputeVariantType)) {
Review Comment:
[P1] Identifying unbound computed `VariantType` via `rawType == INSTANCE ||
isSubPath` is inconsistent across CTAS, MTMV, Sync MV, and TVF:
1. `MTMVPlanUtil.generateColumnsBySql` and
`CreateMaterializedViewCommand.analyzeLogicalPlan` run only up to
`ExplainLevel.ANALYZED_PLAN` (before RBO `VariantSubPathPruning`), so `SELECT
k, v['a'] AS va FROM src` remains `ElementAt(v, 'a')` with `isSubPath == false`
and `rawType = new VariantType(v.count)` (`!= INSTANCE`). The same query in
CTAS runs `VariantSubPathPruning` (`isSubPath == true`) and produces `count =
2048` (while still leaking the parent column's `docMode`/`shardCount` onto the
subpath column), whereas MTMV/Sync MV produce `v.count` (e.g., `0` in
`testMvStoresComputedVariantAsV2`).
2. Unpruned `ElementAt` in CTAS (`parse_to_variant(s)['a']`, `coalesce(a,
b)['a']`, external `ext_v['a']`) and `ExternalFileTableValuedFunction`
(`DataType.fromCatalogType` creates a new `VariantType` with `count=0, V1` `!=
INSTANCE`) also bypass this check and land on `V2` with `count = 0`.
3. MTMV (`MTMVPlanUtil.java:536`) and Sync MV
(`CreateMaterializedViewCommand.java:539, 668`) do not strip
`withoutPredefinedFields()` like CTAS does.
Instead of checking `rawType == INSTANCE`, have `ElementAt` return
`VariantType.INSTANCE` (or carry an explicit unbound-compute flag on
`VariantType`), reset pruned subpaths (`isSubPath == true`) to fresh default
storage properties rather than keeping parent `docMode`/`shardCount`, and share
one helper across CTAS, MTMV, and Sync MV.
##########
fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java:
##########
@@ -2391,19 +2393,19 @@ public static int
analyzeVariantMaxSubcolumnsCount(Map<String, String> propertie
return maxSubcoumnsCount;
}
+ // variant_enable_typed_paths_to_sparse is internal now: accepted and
ignored so that DDL printed by
+ // older versions (which emitted "variant_enable_typed_paths_to_sparse" =
"false") and persisted SQL
+ // still parse, while new columns take the value from
debug_variant_enable_typed_paths_to_sparse.
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`");
+ String value =
properties.get(PROPERTIES_VARIANT_ENABLE_TYPED_PATHS_TO_SPARSE);
+ if (!"true".equalsIgnoreCase(value) &&
!"false".equalsIgnoreCase(value)) {
+ throw new
AnalysisException("variant_enable_typed_paths_to_sparse must be or ");
Review Comment:
[P1] Two issues here:
1. Broken error message: `"variant_enable_typed_paths_to_sparse must be or
"` lost `` `true` `` and `` `false` `` (likely stripped by shell backtick
expansion).
2. Silently ignoring `"true"` is unsafe and contradicts the doc PR: if a DDL
sets `"variant_enable_typed_paths_to_sparse" = "true"` alongside a wildcard
Schema Template (e.g. `MATCH_NAME_GLOB`), silently treating it as `false`
materializes every matching path as an independent subcolumn without respecting
`variant_max_subcolumns_count`. Accept `"false"` for legacy `SHOW CREATE TABLE`
compatibility, and explicitly reject `"true"`.
##########
fe/fe-type/src/main/java/org/apache/doris/catalog/VariantField.java:
##########
@@ -118,6 +120,11 @@ public boolean equals(Object other) {
return otherFiled.pattern.equals(pattern) &&
otherFiled.type.equals(type);
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(pattern, type);
Review Comment:
[P3] Pre-existing issue (non-blocking for this PR): `VariantField.equals`
and `hashCode` (both here and in `nereids.types.VariantField`) compare
`pattern` and `type` but omit `patternType` (`MATCH_NAME` vs
`MATCH_NAME_GLOB`). Matching the existing `equals` here is right for the hash
contract; noting so it can be fixed separately.
--
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]