hello-stephen commented on code in PR #70408:
URL: https://github.com/apache/doris/pull/70408#discussion_r4734229682


##########
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:
   [P2] Resolve fresh computed VARIANT types at table creation
   
   With normal defaults, `SELECT k, parse_to_variant(s)['profile'] AS pv FROM 
src` has `Project(k, ElementAt(ParseToVariant(s), 'profile') AS pv) -> 
Scan(src)`. `ElementAt.computeSignature()` returns a fresh `VariantType(0)`, 
and subpath pruning cannot replace its scalar-function input. The CTAS output 
therefore has neither `rawType == INSTANCE` nor a nonempty subpath, so this 
guard leaves the new column at V2/count0 instead of applying the default 2048. 
For `s='{"profile":{"a":1}}'`, the target keeps `pv.a` entirely sparse and 
disables dynamic subcolumn extraction. Recognize these unbound computed return 
types at the creation boundary (also used by MVs), and cover an unpruned 
ElementAt result.



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