englefly commented on code in PR #64440: URL: https://github.com/apache/doris/pull/64440#discussion_r3421361202
########## regression-test/suites/nereids_rules_p0/column_pruning/map_contains_arg_pruning.groovy: ########## @@ -0,0 +1,125 @@ +// 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 tests for map_contains_key / map_contains_value / map_contains_entry +// when the key/value/entry argument references nested sub-columns. +// +// Bug: visitMapContainsKey/Value/Entry only visited the map argument and skipped +// the key/value/entry argument. When the key is a nested sub-column expression +// (e.g. element_at(s, 'a')) whose data path was not registered, and the same +// sub-column also appears in IS NULL, NestedColumnPruning would prune it to +// null-only metadata access, causing wrong results. + +suite("map_contains_arg_pruning") { + sql """ DROP TABLE IF EXISTS map_contains_arg_pruning_tbl """ + sql """ + CREATE TABLE map_contains_arg_pruning_tbl ( + id INT, + s STRUCT<a: STRING, b: INT> NULL, + m MAP<STRING, INT> NULL, + v VARIANT NULL + ) ENGINE = OLAP + DUPLICATE KEY(id) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES ("replication_allocation" = "tag.location.default: 1") + """ + sql """ + INSERT INTO map_contains_arg_pruning_tbl VALUES + (1, named_struct('a', 'hello', 'b', 100), {'hello': 1, 'world': 2}, '{"k": 42}'), + (2, named_struct('a', 'doris', 'b', 200), {'doris': 3}, NULL), + (3, named_struct('a', null, 'b', 300), NULL, '{"x": 1}'), + (4, NULL, {}, '{}') + """ + + // ================================================================ + // Case 1: map_contains_key + element_at IS NULL (original bug) + // map_contains_key(m, element_at(s, 'a')) needs full access to s.a + // as the key lookup value. Without fix, only [s.a.NULL] from + // element_at(s, 'a') IS NULL is registered. + // ================================================================ + explain { + sql """ + SELECT id, + element_at(s, 'a') IS NULL, + map_contains_key(m, element_at(s, 'a')) + FROM map_contains_arg_pruning_tbl ORDER BY id + """ + contains "nested columns" + contains "s.a" // s.a should appear in access paths + notContains "s.a.NULL" // should NOT be null-only + contains "m.KEYS" // map_contains_key needs KEYS path + } + + order_qt_case1 """ Review Comment: done -- 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]
