From 956fb96dcd4f43ec8254ec399c6859601ba7b423 Mon Sep 17 00:00:00 2001 From: lw112 <131352377+felixwluo@users.noreply.github.com> Date: Fri, 20 Jun 2025 14:03:04 +0800 Subject: [PATCH] branch-2.1: [bugfix](query) Fix for incorrect query results of variant type #51651 (#51707) ### What problem does this PR solve? Cherry-picked from #51651 ### Release note None ### Check List (For Author) - Test - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason - Behavior changed: - [ ] No. - [ ] Yes. - Does this need documentation? - [ ] No. - [ ] Yes. ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label --- ...calResultSinkToShortCircuitPointQuery.java | 3 ++ .../data/point_query_p0/test_point_query.out | 2 ++ .../point_query_p0/test_point_query.groovy | 32 +++++++++++++++---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/LogicalResultSinkToShortCircuitPointQuery.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/LogicalResultSinkToShortCircuitPointQuery.java index a63c9ce4ad..0aa05abeec 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/LogicalResultSinkToShortCircuitPointQuery.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/LogicalResultSinkToShortCircuitPointQuery.java @@ -65,6 +65,9 @@ public class LogicalResultSinkToShortCircuitPointQuery implements RewriteRuleFac return false; } OlapTable olapTable = olapScan.getTable(); + if (olapTable.hasVariantColumns()) { + return false; + } return olapTable.getEnableLightSchemaChange() && olapTable.getEnableUniqueKeyMergeOnWrite() && olapTable.storeRowColumn(); } diff --git a/regression-test/data/point_query_p0/test_point_query.out b/regression-test/data/point_query_p0/test_point_query.out index 292ce49cde..738f133d12 100644 --- a/regression-test/data/point_query_p0/test_point_query.out +++ b/regression-test/data/point_query_p0/test_point_query.out @@ -199,3 +199,5 @@ user_guid feature sk feature_value 2021-01-01T00:00 -- !point_select -- +-- !sql -- +v1 \ No newline at end of file diff --git a/regression-test/suites/point_query_p0/test_point_query.groovy b/regression-test/suites/point_query_p0/test_point_query.groovy index 17a2d3e203..3962d76c51 100644 --- a/regression-test/suites/point_query_p0/test_point_query.groovy +++ b/regression-test/suites/point_query_p0/test_point_query.groovy @@ -279,8 +279,8 @@ suite("test_point_query", "nonConcurrent") { PROPERTIES ( "replication_allocation" = "tag.location.default: 1", "store_row_column" = "true" - ); - """ + ); + """ sql "insert into test_ODS_EBA_LLREPORT(RPTNO) values('567890')" sql "select /*+ SET_VAR(enable_nereids_planner=true) */ substr(RPTNO,2,5) from test_ODS_EBA_LLREPORT where RPTNO = '567890'" @@ -297,14 +297,14 @@ suite("test_point_query", "nonConcurrent") { "enable_unique_key_merge_on_write" = "true", "store_row_column" = "true" ); - """ + """ sql """insert into `test_cc_aaaid2` values('1111111')""" qt_sql """SELECT `__DORIS_DELETE_SIGN__`, aaaid FROM - `test_cc_aaaid2` + `test_cc_aaaid2` WHERE aaaid = '1111111'""" } finally { @@ -333,7 +333,7 @@ suite("test_point_query", "nonConcurrent") { explain { sql("select * from table_3821461 where col1 = -10 and col2 = 20 and loc3 = 'aabc'") contains "SHORT-CIRCUIT" - } + } qt_sql "select * from table_3821461 where col1 = 10 and col2 = 20 and loc3 = 'aabc';" sql "delete from table_3821461 where col1 = 10 and col2 = 20 and loc3 = 'aabc';" qt_sql "select * from table_3821461 where col1 = 10 and col2 = 20 and loc3 = 'aabc';" @@ -419,4 +419,24 @@ suite("test_point_query", "nonConcurrent") { assertNotEquals(result1, result2) } } -} + + // test variant type + sql "DROP TABLE IF EXISTS test_with_variant" + sql """ + CREATE TABLE `test_with_variant` ( + `col1` bigint NULL, + `col2` variant NULL + ) ENGINE=OLAP + UNIQUE KEY(`col1`) + DISTRIBUTED BY HASH(`col1`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "enable_unique_key_merge_on_write" = "true", + "store_row_column" = "true" + ); + """ + sql """ + INSERT INTO test_with_variant VALUES(1, '{"k1":"v1", "k2": 200}'); + """ + qt_sql "select col2['k1'] from test_with_variant where col1=1" +}