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


##########
regression-test/suites/fault_injection_p0/test_topn_pruned_struct_overlapping_segments.groovy:
##########
@@ -0,0 +1,200 @@
+// 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.
+
+// Regression case for the pruned-struct read misalignment on the inline topn 
scan path.
+//
+// Root cause: when a topn ordered read (order by key limit N) hits a rowset 
with
+// multiple OVERLAPPING segments, BetaRowsetReader picks VMergeIterator, whose
+// VMergeIteratorContext::init() eagerly loads the first block of every 
segment.
+// That block is created from the storage Schema (FULL struct type, all 
children),
+// while the struct sub-column iterators have been filtered down to the pruned
+// subset by set_access_paths()/remove_pruned_sub_iterators(). The pairing 
loop in
+// StructFileColumnIterator::next_batch() indexes _sub_column_iterators[i] by 
the
+// dst tuple position, so the two ordinal spaces disagree:
+//   - text/dict child data decoded into a TINYINT child column
+//       -> [E-3110] insert_many_dict_data is not supported for TINYINT
+//   - same-typed children shift silently, and the loop runs past the pruned
+//     iterator vector -> out-of-bounds -> BE SIGSEGV
+//
+// The FE TopN lazy materialization (VMaterializeNode) usually shields this 
path
+// on master; setting topn_lazy_materialization_threshold=-1 (or any state 
where
+// the rule bails, e.g. light_schema_change=false tables) exposes it.
+//
+// Layout construction: MemTable.need_flush debug point forces one segment per
+// inserted block (batch_size=500, 2000 rows -> 4 segments, below the
+// segcompaction_batch_size=10 threshold so segcompaction never merges them), 
and
+// the NULL k1 rows in every block make every segment's key lower bound NULL, 
so
+// the segments overlap and the rowset is marked OVERLAPPING.
+suite("test_topn_pruned_struct_overlapping_segments", "nonConcurrent") {
+    def dictTable = "test_topn_pruned_struct_ovlp_dict"
+    def intTable = "test_topn_pruned_struct_ovlp_int"
+    def aggTable = "test_topn_pruned_struct_ovlp_agg"
+
+    sql "DROP TABLE IF EXISTS ${dictTable}"
+    sql "DROP TABLE IF EXISTS ${intTable}"
+    sql "DROP TABLE IF EXISTS ${aggTable}"
+    sql """
+        CREATE TABLE ${dictTable} (
+            k1 BIGINT,
+            c ARRAY<ARRAY<STRUCT<col1:INT, col2:TINYINT, col17:TEXT>>>
+        ) DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES('replication_num' = '1')
+    """
+    sql """
+        CREATE TABLE ${intTable} (
+            k1 BIGINT,
+            c ARRAY<ARRAY<STRUCT<col1:INT, col2:INT, col3:INT>>>
+        ) DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES('replication_num' = '1')
+    """
+
+    try {
+        GetDebugPoint().enableDebugPointForAllBEs("MemTable.need_flush")
+        // 4 blocks of 500 rows -> 4 segments per tablet; k1 NULL every 20 
rows so
+        // every segment starts at NULL -> overlapping key ranges -> 
OVERLAPPING rowset.
+        sql "SET batch_size = 500"
+        sql """
+            INSERT INTO ${dictTable}
+            SELECT if(number % 20 = 0, NULL, number),
+                   array(array(named_struct(
+                       'col1', CAST(number AS INT),
+                       'col2', CAST(number % 127 AS TINYINT),
+                       'col17', concat('s', number))))
+            FROM numbers('number' = '2000')
+        """
+        sql """
+            INSERT INTO ${intTable}
+            SELECT if(number % 20 = 0, NULL, number),
+                   array(array(named_struct(
+                       'col1', CAST(number + 1000000 AS INT),
+                       'col2', CAST(number + 2000000 AS INT),
+                       'col3', CAST(number + 3000000 AS INT))))
+            FROM numbers('number' = '2000')
+        """
+    } finally {
+        GetDebugPoint().disableDebugPointForAllBEs("MemTable.need_flush")
+    }
+
+    // Self-check the storage layout: the test is void unless the rowset 
really is
+    // a multi-segment OVERLAPPING one (that is what selects VMergeIterator).
+    for (def tbl : [dictTable, intTable]) {
+        def tablets = sql_return_maparray("SHOW TABLETS FROM ${tbl}")
+        def (code, out, err) = curl("GET", tablets[0].MetaUrl)
+        assertEquals(0, code)
+        assertTrue(out.contains('"segments_overlap_pb": "OVERLAPPING"'),
+                "expected an OVERLAPPING multi-segment rowset in ${tbl}, 
tablet meta: check MemTable.need_flush debug point")
+    }
+
+    // AGG-table variant: the same ordinal-space mismatch also hits the 
aggregate
+    // merge path (BlockReader::_init_agg_state used to build the 
reader_replace
+    // argument type from the full TabletColumn while the stored block uses the
+    // pruned type). It needs no debug point, no topn and no special session 
vars:
+    // two ordinary inserts (two rowsets) + a pruned read used to fail with
+    // "Aggregate function reader_replace argument 0 type check failed".
+    sql """
+        CREATE TABLE ${aggTable} (
+            k1 BIGINT,
+            c ARRAY<ARRAY<STRUCT<col1:INT, col2:TINYINT, col17:TEXT>>> REPLACE
+        ) AGGREGATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES('replication_num' = '1')
+    """
+    sql """
+        INSERT INTO ${aggTable}
+        SELECT number, array(array(named_struct(
+            'col1', CAST(number AS INT),
+            'col2', CAST(number % 127 AS TINYINT),
+            'col17', concat('s', number))))
+        FROM numbers('number' = '1000')
+    """
+    sql """
+        INSERT INTO ${aggTable}
+        SELECT number + 1000, array(array(named_struct(
+            'col1', CAST(number + 1000 AS INT),
+            'col2', CAST(number % 127 AS TINYINT),
+            'col17', concat('s', number + 1000))))
+        FROM numbers('number' = '1000')
+    """
+
+    def expectedTwoCols = (1..10).collect { [String.valueOf(it), "s" + it] }
+    def expectedOneCol = (1..10).collect { ["s" + it] }
+    def expectedIntCol = (1..10).collect { [String.valueOf(3000000 + it)] }
+
+    def assertRows = { List<List<Object>> actual, List<List<String>> expected, 
String tag ->

Review Comment:
   These deterministic SQL result checks should use the regression output 
mechanism instead of hand-coded `assertRows` expectations. The repository test 
rules require determined expected results to be generated with 
`qt_sql`/`order_qt_*` and the corresponding `.out`, rather than manual Groovy 
assertions. The tablet-meta self-checks are fine as direct assertions, but the 
ordered SELECTs below should become `qt_*` cases so the expected rows are 
maintained by the normal regression baseline flow.



##########
regression-test/suites/fault_injection_p0/test_topn_pruned_struct_overlapping_segments.groovy:
##########
@@ -0,0 +1,200 @@
+// 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.
+
+// Regression case for the pruned-struct read misalignment on the inline topn 
scan path.
+//
+// Root cause: when a topn ordered read (order by key limit N) hits a rowset 
with
+// multiple OVERLAPPING segments, BetaRowsetReader picks VMergeIterator, whose
+// VMergeIteratorContext::init() eagerly loads the first block of every 
segment.
+// That block is created from the storage Schema (FULL struct type, all 
children),
+// while the struct sub-column iterators have been filtered down to the pruned
+// subset by set_access_paths()/remove_pruned_sub_iterators(). The pairing 
loop in
+// StructFileColumnIterator::next_batch() indexes _sub_column_iterators[i] by 
the
+// dst tuple position, so the two ordinal spaces disagree:
+//   - text/dict child data decoded into a TINYINT child column
+//       -> [E-3110] insert_many_dict_data is not supported for TINYINT
+//   - same-typed children shift silently, and the loop runs past the pruned
+//     iterator vector -> out-of-bounds -> BE SIGSEGV
+//
+// The FE TopN lazy materialization (VMaterializeNode) usually shields this 
path
+// on master; setting topn_lazy_materialization_threshold=-1 (or any state 
where
+// the rule bails, e.g. light_schema_change=false tables) exposes it.
+//
+// Layout construction: MemTable.need_flush debug point forces one segment per
+// inserted block (batch_size=500, 2000 rows -> 4 segments, below the
+// segcompaction_batch_size=10 threshold so segcompaction never merges them), 
and
+// the NULL k1 rows in every block make every segment's key lower bound NULL, 
so
+// the segments overlap and the rowset is marked OVERLAPPING.
+suite("test_topn_pruned_struct_overlapping_segments", "nonConcurrent") {
+    def dictTable = "test_topn_pruned_struct_ovlp_dict"
+    def intTable = "test_topn_pruned_struct_ovlp_int"
+    def aggTable = "test_topn_pruned_struct_ovlp_agg"
+
+    sql "DROP TABLE IF EXISTS ${dictTable}"
+    sql "DROP TABLE IF EXISTS ${intTable}"
+    sql "DROP TABLE IF EXISTS ${aggTable}"
+    sql """
+        CREATE TABLE ${dictTable} (
+            k1 BIGINT,
+            c ARRAY<ARRAY<STRUCT<col1:INT, col2:TINYINT, col17:TEXT>>>
+        ) DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES('replication_num' = '1')
+    """
+    sql """
+        CREATE TABLE ${intTable} (
+            k1 BIGINT,
+            c ARRAY<ARRAY<STRUCT<col1:INT, col2:INT, col3:INT>>>
+        ) DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES('replication_num' = '1')
+    """
+
+    try {
+        GetDebugPoint().enableDebugPointForAllBEs("MemTable.need_flush")
+        // 4 blocks of 500 rows -> 4 segments per tablet; k1 NULL every 20 
rows so
+        // every segment starts at NULL -> overlapping key ranges -> 
OVERLAPPING rowset.
+        sql "SET batch_size = 500"
+        sql """
+            INSERT INTO ${dictTable}
+            SELECT if(number % 20 = 0, NULL, number),
+                   array(array(named_struct(
+                       'col1', CAST(number AS INT),
+                       'col2', CAST(number % 127 AS TINYINT),
+                       'col17', concat('s', number))))
+            FROM numbers('number' = '2000')
+        """
+        sql """
+            INSERT INTO ${intTable}
+            SELECT if(number % 20 = 0, NULL, number),
+                   array(array(named_struct(
+                       'col1', CAST(number + 1000000 AS INT),
+                       'col2', CAST(number + 2000000 AS INT),
+                       'col3', CAST(number + 3000000 AS INT))))
+            FROM numbers('number' = '2000')
+        """
+    } finally {
+        GetDebugPoint().disableDebugPointForAllBEs("MemTable.need_flush")
+    }
+
+    // Self-check the storage layout: the test is void unless the rowset 
really is
+    // a multi-segment OVERLAPPING one (that is what selects VMergeIterator).
+    for (def tbl : [dictTable, intTable]) {
+        def tablets = sql_return_maparray("SHOW TABLETS FROM ${tbl}")
+        def (code, out, err) = curl("GET", tablets[0].MetaUrl)
+        assertEquals(0, code)
+        assertTrue(out.contains('"segments_overlap_pb": "OVERLAPPING"'),
+                "expected an OVERLAPPING multi-segment rowset in ${tbl}, 
tablet meta: check MemTable.need_flush debug point")
+    }
+
+    // AGG-table variant: the same ordinal-space mismatch also hits the 
aggregate
+    // merge path (BlockReader::_init_agg_state used to build the 
reader_replace
+    // argument type from the full TabletColumn while the stored block uses the
+    // pruned type). It needs no debug point, no topn and no special session 
vars:
+    // two ordinary inserts (two rowsets) + a pruned read used to fail with
+    // "Aggregate function reader_replace argument 0 type check failed".
+    sql """
+        CREATE TABLE ${aggTable} (
+            k1 BIGINT,
+            c ARRAY<ARRAY<STRUCT<col1:INT, col2:TINYINT, col17:TEXT>>> REPLACE
+        ) AGGREGATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES('replication_num' = '1')
+    """
+    sql """
+        INSERT INTO ${aggTable}
+        SELECT number, array(array(named_struct(
+            'col1', CAST(number AS INT),
+            'col2', CAST(number % 127 AS TINYINT),
+            'col17', concat('s', number))))
+        FROM numbers('number' = '1000')
+    """
+    sql """
+        INSERT INTO ${aggTable}
+        SELECT number + 1000, array(array(named_struct(
+            'col1', CAST(number + 1000 AS INT),
+            'col2', CAST(number % 127 AS TINYINT),
+            'col17', concat('s', number + 1000))))
+        FROM numbers('number' = '1000')
+    """
+
+    def expectedTwoCols = (1..10).collect { [String.valueOf(it), "s" + it] }
+    def expectedOneCol = (1..10).collect { ["s" + it] }
+    def expectedIntCol = (1..10).collect { [String.valueOf(3000000 + it)] }
+
+    def assertRows = { List<List<Object>> actual, List<List<String>> expected, 
String tag ->
+        assertEquals(expected.size(), actual.size(), "row count mismatch for 
${tag}")
+        for (int i = 0; i < expected.size(); i++) {
+            for (int j = 0; j < expected[i].size(); j++) {
+                assertEquals(expected[i][j], String.valueOf(actual[i][j]),
+                        "value mismatch for ${tag} at row ${i} col ${j}")
+            }
+        }
+    }
+
+    // 1. Default session: on master this plans VMaterializeNode (TopN lazy
+    //    materialization + rowid fetch); guards that path stays correct too.
+    assertRows(sql("""
+        SELECT element_at(c[1][1], 1), element_at(c[1][1], 'col17')
+        FROM ${dictTable} WHERE k1 IS NOT NULL ORDER BY k1 LIMIT 10
+    """), expectedTwoCols, "dict table, default session")
+
+    // AGG merge path, pure default session (no topn involved at all).
+    assertRows(sql("""
+        SELECT element_at(c[1][1], 1), element_at(c[1][1], 'col17')
+        FROM ${aggTable} WHERE k1 >= 1 AND k1 <= 10 ORDER BY k1
+    """), expectedTwoCols, "agg table, default session")
+    // Rows from the second rowset must merge and read correctly too.
+    assertRows(sql("""
+        SELECT element_at(c[1][1], 'col17')
+        FROM ${aggTable} WHERE k1 >= 1501 AND k1 <= 1510 ORDER BY k1
+    """), (1501..1510).collect { ["s" + it] }, "agg table second rowset, 
default session")
+
+    // 2. Force the inline topn scan path (no VMaterializeNode). This is the 
exact
+    //    path that used to fail with
+    //    "[E-3110] Method insert_many_dict_data is not supported for TINYINT".
+    sql "SET topn_lazy_materialization_threshold = -1"
+    // The storage ordered-key read (read_orderby_key -> need_ordered_result ->
+    // VMergeIterator) is additionally gated by enable_segment_limit_pushdown 
in
+    // OlapScanner. The variable is randomized in fuzzy regression runs; pin 
it so
+    // this section always exercises the merge path this fix targets.
+    sql "SET enable_segment_limit_pushdown = true"
+
+    assertRows(sql("""
+        SELECT element_at(c[1][1], 1), element_at(c[1][1], 'col17')
+        FROM ${dictTable} WHERE k1 IS NOT NULL ORDER BY k1 LIMIT 10
+    """), expectedTwoCols, "dict table, inline topn path")
+
+    // Single pruned child: the misalignment shifts col17 data onto col1 (INT),
+    // which used to fail with "... is not supported for INT".
+    assertRows(sql("""
+        SELECT element_at(c[1][1], 'col17')
+        FROM ${dictTable} WHERE k1 IS NOT NULL ORDER BY k1 LIMIT 10
+    """), expectedOneCol, "dict table single child, inline topn path")
+
+    // Same-typed children: the shifted decode does not error out, so the 
pairing
+    // loop used to run past the pruned iterator vector and SIGSEGV the BE; a
+    // partial regression could also return col1's values (1000001..) here.
+    assertRows(sql("""
+        SELECT element_at(c[1][1], 'col3')
+        FROM ${intTable} WHERE k1 IS NOT NULL ORDER BY k1 LIMIT 10
+    """), expectedIntCol, "int table last child, inline topn path")
+
+    sql "DROP TABLE IF EXISTS ${dictTable}"

Review Comment:
   Please remove these final table drops. The Doris regression-test rule is to 
drop tables before use, not after the test finishes, so a failed run leaves the 
tables available for debugging. The pre-test drops at the top already provide 
the cleanup needed for repeatable reruns.



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