github-actions[bot] commented on code in PR #70408:
URL: https://github.com/apache/doris/pull/70408#discussion_r4675035396


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java:
##########
@@ -1223,6 +1239,22 @@ private static List<Column> 
buildExpectedPhysicalSchema(MTMV mtmv,
     private static boolean isTypeLike(Type type, Type typeOther) {
         if (type.isStringType()) {
             return typeOther.isStringType();
+        } else if (type instanceof org.apache.doris.catalog.VariantType
+                && typeOther instanceof org.apache.doris.catalog.VariantType) {
+            // An MV that an older version created stored a computed or 
external VARIANT as V1 (count=0),
+            // while this version analyses it as V2 (with the default 
subcolumn limit): that storage-layout
+            // promotion is not a schema change of the base tables.
+            org.apache.doris.catalog.VariantType storedVariant = 
(org.apache.doris.catalog.VariantType) type;
+            org.apache.doris.catalog.VariantType analyzedVariant = 
(org.apache.doris.catalog.VariantType) typeOther;
+            org.apache.doris.catalog.VariantType normalized =
+                    
analyzedVariant.withSerializeType(storedVariant.getVariantSerializeType());
+            if (storedVariant.getVariantSerializeType() == 
TVariantSerializeType.V1
+                    && storedVariant.getVariantMaxSubcolumnsCount() == 0
+                    && !storedVariant.getEnableVariantDocMode()
+                    && analyzedVariant.getVariantSerializeType() == 
TVariantSerializeType.V2) {
+                normalized = normalized.withMaxSubcolumnsCount(0);
+            }
+            return storedVariant.equals(normalized);

Review Comment:
   [P1] Normalize inactive shard metadata when checking upgraded MVs
   
   An old async MV with `SELECT k, parse_to_variant(s) AS pv FROM src` persists 
`pv` as non-doc/count=0/docShardCount=64. After upgrade, reanalysis produces 
V2/count=2048/docShardCount=0; restoring only version/count here leaves `64 != 
0` in the new `VariantType.equals`. An unrelated `ALTER TABLE src ADD COLUMN 
unused INT` therefore makes `invalidateMvUnlessQueryHolds` falsely put this 
valid MV in `SCHEMA_CHANGE`, and subsequent refreshes fail 
`ensureMTMVQueryUsable` with "column type not same". Compare effective 
mode-specific properties or normalize the historical inactive field. The 
upgrade test needs actual old metadata with docShardCount=64; changing only 
version/count on a newly created MV misses this case.



##########
regression-test/suites/variant_p0/test_variant_tuning_properties.groovy:
##########
@@ -0,0 +1,143 @@
+// 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.
+
+suite("test_variant_tuning_properties") {
+    sql """ set describe_extend_variant_column = true """
+
+    // when extraction starts: a data file below 
variant_doc_materialization_min_rows keeps its dynamic paths in the
+    // sparse encoding, and compaction extracts them once it writes enough 
rows; doc mode is a separate switch
+    sql "DROP TABLE IF EXISTS test_variant_deferred_subcolumns"
+    sql """
+        CREATE TABLE test_variant_deferred_subcolumns (
+            k INT,
+            payload VARIANT<PROPERTIES(
+                "variant_max_subcolumns_count" = "128",
+                "variant_doc_materialization_min_rows" = "5",
+                "variant_doc_hash_shard_count" = "1",
+                "variant_enable_doc_mode" = "false"
+            )>
+        )
+        DUPLICATE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1
+        PROPERTIES ("replication_num" = "1", "disable_auto_compaction" = 
"true")
+    """
+    sql """INSERT INTO test_variant_deferred_subcolumns VALUES
+        (1, parse_to_variant('{"user_id": 101, "action": "click", 
"campaign_a": 7}')),
+        (2, parse_to_variant('{"user_id": 102, "action": "view", "os_name": 
"iOS"}')),
+        (3, parse_to_variant('{"user_id": 103, "action": "click", 
"source_page": "home"}'))"""
+    sql """INSERT INTO test_variant_deferred_subcolumns VALUES
+        (4, parse_to_variant('{"user_id": 104, "action": "view", "tag_a": 
"new"}')),
+        (5, parse_to_variant('{"user_id": 105, "action": "click"}')),
+        (6, parse_to_variant('{"user_id": 106, "action": "view", 
"device_flag": true}'))"""
+    qt_deferred_load "DESC test_variant_deferred_subcolumns"
+    order_qt_deferred_load_read """SELECT k, payload, payload['user_id'], 
payload['action'], payload['os_name']
+        FROM test_variant_deferred_subcolumns"""
+    trigger_and_wait_compaction("test_variant_deferred_subcolumns", "full")
+    qt_deferred_compacted "DESC test_variant_deferred_subcolumns"
+    order_qt_deferred_compacted_read """SELECT k, payload, payload['user_id'], 
payload['action'], payload['os_name']
+        FROM test_variant_deferred_subcolumns"""
+
+    // the row threshold can change: new data files follow the new one
+    sql """ALTER TABLE test_variant_deferred_subcolumns MODIFY COLUMN payload 
VARIANT<PROPERTIES(
+        "variant_max_subcolumns_count" = "128",
+        "variant_doc_materialization_min_rows" = "1000",
+        "variant_doc_hash_shard_count" = "1",
+        "variant_enable_doc_mode" = "false")>"""
+    waitForSchemaChangeDone {
+        sql """SHOW ALTER TABLE COLUMN WHERE TableName = 
'test_variant_deferred_subcolumns'
+            ORDER BY CreateTime DESC LIMIT 1"""
+        time 600
+    }
+    qt_deferred_altered "DESC test_variant_deferred_subcolumns"
+
+    // doc mode keeps the whole document and still extracts up to the count, 
the most frequent paths first
+    sql "DROP TABLE IF EXISTS test_variant_doc_mode_count"
+    sql """
+        CREATE TABLE test_variant_doc_mode_count (
+            event_id BIGINT NOT NULL,
+            payload VARIANT<PROPERTIES(
+                "variant_max_subcolumns_count" = "2",
+                "variant_doc_materialization_min_rows" = "0",
+                "variant_doc_hash_shard_count" = "1",
+                "variant_enable_doc_mode" = "true"
+            )>
+        )
+        DUPLICATE KEY(event_id) DISTRIBUTED BY HASH(event_id) BUCKETS 1
+        PROPERTIES ("replication_num" = "1", "disable_auto_compaction" = 
"true")
+    """
+    sql """INSERT INTO test_variant_doc_mode_count VALUES
+        (1, parse_to_variant('{"user_id": 101, "action": "click", 
"campaign_a": 7, "experiment_a": "A", "tag_a": "new"}')),
+        (2, parse_to_variant('{"user_id": 102, "action": "view", 
"device_flag": true, "os_name": "iOS", "tag_b": "returning"}')),
+        (3, parse_to_variant('{"user_id": 103, "action": "click", 
"experiment_b": "B", "source_page": "home", "device_model": "M1"}'))"""
+    qt_doc_mode_load "DESC test_variant_doc_mode_count"
+    order_qt_doc_mode_document "SELECT payload FROM 
test_variant_doc_mode_count WHERE CAST(payload['user_id'] AS BIGINT) = 101"
+    order_qt_doc_mode_paths """SELECT event_id, payload['action'], 
payload['os_name'], payload['tag_a']
+        FROM test_variant_doc_mode_count"""
+    trigger_and_wait_compaction("test_variant_doc_mode_count", "full")
+    qt_doc_mode_compacted "DESC test_variant_doc_mode_count"
+    order_qt_doc_mode_compacted_read "SELECT event_id, payload FROM 
test_variant_doc_mode_count"
+
+    // a count of 0 turns automatic extraction off, also when doc mode is 
stated off
+    sql "DROP TABLE IF EXISTS test_variant_no_extraction"
+    sql """
+        CREATE TABLE test_variant_no_extraction (
+            k INT,
+            payload VARIANT<PROPERTIES(
+                "variant_max_subcolumns_count" = "0",
+                "variant_doc_materialization_min_rows" = "0",
+                "variant_doc_hash_shard_count" = "2",
+                "variant_enable_doc_mode" = "false"
+            )>
+        )
+        DUPLICATE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1
+        PROPERTIES ("replication_num" = "1", "disable_auto_compaction" = 
"true")
+    """
+    sql """INSERT INTO test_variant_no_extraction VALUES
+        (1, parse_to_variant('{"source": "collector-a", "metric_0001": 1}')),
+        (2, parse_to_variant('{"source": "collector-b", "metric_0002": 2}'))"""
+    qt_no_extraction "DESC test_variant_no_extraction"
+    order_qt_no_extraction_read """SELECT k, payload['source'] FROM 
test_variant_no_extraction
+        WHERE CAST(payload['source'] AS STRING) = 'collector-a'"""
+
+    // the shard count of older versions without doc mode is accepted and 
ignored: variant_doc_hash_shard_count sets
+    // the shard count in either mode; pin the fuzzy defaults that this column 
leaves out
+    sql "SET debug_variant_enable_doc_mode = false"
+    sql "SET debug_variant_doc_materialization_min_rows = 0"
+    sql "SET debug_variant_doc_hash_shard_count = 0"
+    sql "DROP TABLE IF EXISTS test_variant_sparse_hash_shard_count"
+    sql """
+        CREATE TABLE test_variant_sparse_hash_shard_count (
+            k INT,
+            v VARIANT<PROPERTIES("variant_max_subcolumns_count" = "0", 
"variant_sparse_hash_shard_count" = "4")>
+        )
+        DUPLICATE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1
+        PROPERTIES ("replication_num" = "1")
+    """
+    qt_sparse_hash_shard_count "DESC test_variant_sparse_hash_shard_count"
+
+    // variant_enable_typed_paths_to_sparse is accepted and ignored for legacy 
DDL compatibility
+    sql "DROP TABLE IF EXISTS test_variant_typed_paths_to_sparse"
+    sql """
+        CREATE TABLE test_variant_typed_paths_to_sparse (
+            k INT,
+            v1 VARIANT<PROPERTIES("variant_enable_typed_paths_to_sparse" = 
"false")>,

Review Comment:
   [P2] Pin the count for the new compatibility golden
   
   This newly added CREATE omits `variant_max_subcolumns_count`, and no 
preceding SET pins its default. The standard p0 config enables debug points and 
fuzzy sessions, so `initFuzzyModeVariables` supplies a count in 0..9 and 
`getVariantDefaults` uses it, while the `typed_paths_to_sparse` golden expects 
2048 for both columns. This new qt check therefore fails in p0. Set 
`debug_variant_max_subcolumns_count=2048` before this case; the newly added 
inferred-column DESC checks in the count-zero CTAS and MTMV suites need the 
same pin. This is a different case from the earlier sparse-shard CREATE covered 
by discussion_r4627398636, whose mode/row/shard defaults are now pinned.



##########
regression-test/data/variant_p0/dotted_key_escape_common_type.out:
##########
@@ -13,7 +13,7 @@
 
 -- !ctas_schema --
 k      int     Yes     true    \N      
-v      variant<PROPERTIES ("variant_max_subcolumns_count" = 
"0","variant_enable_typed_paths_to_sparse" = 
"false","variant_max_sparse_column_statistics_size" = 
"10000","variant_sparse_hash_shard_count" = "1")>       Yes     false   \N      
NONE
+v      variant<PROPERTIES ("variant_max_subcolumns_count" = 
"0","variant_max_sparse_column_statistics_size" = 
"10000","variant_doc_materialization_min_rows" = 
"0","variant_doc_hash_shard_count" = "1")>      Yes     false   \N      NONE

Review Comment:
   [P2] Regenerate the common-type CTAS schema expectation
   
   The suite creates this table with `SELECT k, coalesce(v1,v2,legacy) AS v`, 
where the input limits differ (1 and 2). `Coalesce.customSignature` obtains 
`VariantType.INSTANCE` from `findCommonVariantType`, and the new CTAS 
`forNewTableColumn` resolves that unbound count to the default 2048. This 
expected row still says 0, so `qt_ctas_schema` now fails even with ordinary, 
nonfuzzy defaults. Pin the intended inference defaults in the suite and 
regenerate its output for the new inferred schema.



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