From dbcdbd0001343d7243fdf08abf7133b63b13a9cf Mon Sep 17 00:00:00 2001 From: yujun Date: Fri, 15 Aug 2025 17:26:59 +0800 Subject: [PATCH 1/3] add test --- .../test_physical_translator.out | 23 +++++++++ .../test_physical_translator.groovy | 51 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 regression-test/data/nereids_p0/physical_translator/test_physical_translator.out create mode 100644 regression-test/suites/nereids_p0/physical_translator/test_physical_translator.groovy diff --git a/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out b/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out new file mode 100644 index 00000000000000..00591d38ef4040 --- /dev/null +++ b/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out @@ -0,0 +1,23 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !continue_project_shape -- +PhysicalResultSink +--PhysicalProject[t.a, x AS `k1`, x AS `k2`] +----PhysicalProject[random(100) AS `x`, t.a] +------PhysicalOlapScan[tbl_test_physical_translator] + +-- !continue_project_result -- +1 0.9616644308453555 0.9616644308453555 +2 0.32358402105146866 0.32358402105146866 + +-- !continue_filter_shape -- +PhysicalResultSink +--PhysicalProject[(a + 2) AS `x`] +----filter((cast(a as BIGINT) < 98) and (cast(a as BIGINT) > 3)) +------PhysicalLimit[GLOBAL] +--------PhysicalLimit[LOCAL] +----------PhysicalProject[tbl_test_physical_translator.a] +------------filter((tbl_test_physical_translator.a > 5)) +--------------PhysicalOlapScan[tbl_test_physical_translator] + +-- !continue_filter_result -- + diff --git a/regression-test/suites/nereids_p0/physical_translator/test_physical_translator.groovy b/regression-test/suites/nereids_p0/physical_translator/test_physical_translator.groovy new file mode 100644 index 00000000000000..78f2ac32524d16 --- /dev/null +++ b/regression-test/suites/nereids_p0/physical_translator/test_physical_translator.groovy @@ -0,0 +1,51 @@ +// 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_physical_translator") { + def tbl = "tbl_test_physical_translator" + sql 'SET enable_nereids_planner=true' + sql 'SET runtime_filter_mode=OFF' + sql 'SET enable_fallback_to_original_planner=false' + sql "SET ignore_shape_nodes='PhysicalDistribute'" + sql "SET detail_shape_nodes='PhysicalProject'" + sql 'SET disable_nereids_rules=PRUNE_EMPTY_PARTITION' + sql "drop table if exists ${tbl} force" + sql "create table ${tbl} (a int, b int) properties('replication_num' = '1')" + sql "insert into ${tbl} values(1, 10), (2, 20)" + + def sql1 = """ + SELECT a, x as k1, x as k2 FROM (SELECT a, random(100) as x FROM ${tbl}) t + """ + + explainAndOrderResult "continue_project", sql1 + explain { + sql sql1 + contains "VSELECT" + } + + def sql2 = """ + select * from (select a + 2 as x from ${tbl} where a > 5 limit 1)s where x > 5 and x < 100 + """ + + explainAndOrderResult "continue_filter", sql2 + explain { + sql sql2 + contains "VSELECT" + } + + sql "drop table if exists ${tbl} force" +} From 676e51db812b34c79d2ce108a37d00ea9ffaa15b Mon Sep 17 00:00:00 2001 From: yujun Date: Fri, 15 Aug 2025 18:21:23 +0800 Subject: [PATCH 2/3] update test --- .../physical_translator/test_physical_translator.out | 7 ++++--- .../physical_translator/test_physical_translator.groovy | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out b/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out index 00591d38ef4040..d5166d53ce7031 100644 --- a/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out +++ b/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out @@ -7,17 +7,18 @@ PhysicalResultSink -- !continue_project_result -- 1 0.9616644308453555 0.9616644308453555 -2 0.32358402105146866 0.32358402105146866 +200 0.32358402105146866 0.32358402105146866 -- !continue_filter_shape -- PhysicalResultSink --PhysicalProject[(a + 2) AS `x`] -----filter((cast(a as BIGINT) < 98) and (cast(a as BIGINT) > 3)) +----filter((cast(a as BIGINT) < 9998) and (cast(a as BIGINT) > 3)) ------PhysicalLimit[GLOBAL] --------PhysicalLimit[LOCAL] ----------PhysicalProject[tbl_test_physical_translator.a] -------------filter((tbl_test_physical_translator.a > 5)) +------------filter((tbl_test_physical_translator.b > 10)) --------------PhysicalOlapScan[tbl_test_physical_translator] -- !continue_filter_result -- +202 diff --git a/regression-test/suites/nereids_p0/physical_translator/test_physical_translator.groovy b/regression-test/suites/nereids_p0/physical_translator/test_physical_translator.groovy index 78f2ac32524d16..3e5001a5ea3fdf 100644 --- a/regression-test/suites/nereids_p0/physical_translator/test_physical_translator.groovy +++ b/regression-test/suites/nereids_p0/physical_translator/test_physical_translator.groovy @@ -25,7 +25,7 @@ suite("test_physical_translator") { sql 'SET disable_nereids_rules=PRUNE_EMPTY_PARTITION' sql "drop table if exists ${tbl} force" sql "create table ${tbl} (a int, b int) properties('replication_num' = '1')" - sql "insert into ${tbl} values(1, 10), (2, 20)" + sql "insert into ${tbl} values(1, 10), (200, 300)" def sql1 = """ SELECT a, x as k1, x as k2 FROM (SELECT a, random(100) as x FROM ${tbl}) t @@ -38,7 +38,7 @@ suite("test_physical_translator") { } def sql2 = """ - select * from (select a + 2 as x from ${tbl} where a > 5 limit 1)s where x > 5 and x < 100 + select * from (select a + 2 as x from ${tbl} where b > 10 limit 100)s where x > 5 and x < 10000 """ explainAndOrderResult "continue_filter", sql2 From 2a3d9ecb7bcde201540778833557a68125d8cdfa Mon Sep 17 00:00:00 2001 From: yujun Date: Fri, 15 Aug 2025 20:44:47 +0800 Subject: [PATCH 3/3] update test --- .../physical_translator/test_physical_translator.out | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out b/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out index d5166d53ce7031..1bc6c15f7a4d35 100644 --- a/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out +++ b/regression-test/data/nereids_p0/physical_translator/test_physical_translator.out @@ -2,7 +2,7 @@ -- !continue_project_shape -- PhysicalResultSink --PhysicalProject[t.a, x AS `k1`, x AS `k2`] -----PhysicalProject[random(100) AS `x`, t.a] +----PhysicalProject[random(100) AS `x`, tbl_test_physical_translator.a] ------PhysicalOlapScan[tbl_test_physical_translator] -- !continue_project_result -- @@ -11,8 +11,8 @@ PhysicalResultSink -- !continue_filter_shape -- PhysicalResultSink ---PhysicalProject[(a + 2) AS `x`] -----filter((cast(a as BIGINT) < 9998) and (cast(a as BIGINT) > 3)) +--PhysicalProject[(cast(a as BIGINT) + 2) AS `x`] +----filter((tbl_test_physical_translator.a < 9998) and (tbl_test_physical_translator.a > 3)) ------PhysicalLimit[GLOBAL] --------PhysicalLimit[LOCAL] ----------PhysicalProject[tbl_test_physical_translator.a]