From 072c388ca385448f7ecdd113abf643b547a44620 Mon Sep 17 00:00:00 2001 From: "tongyang.hty" Date: Thu, 24 Nov 2022 11:31:48 +0800 Subject: [PATCH] test(grouping sets) add regression test case for grouping sets --- .../grouping_sets/test_grouping_sets1.out | 31 +++++ .../grouping_sets/test_grouping_sets1.groovy | 112 ++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 regression-test/data/query_p0/grouping_sets/test_grouping_sets1.out create mode 100644 regression-test/suites/query_p0/grouping_sets/test_grouping_sets1.groovy diff --git a/regression-test/data/query_p0/grouping_sets/test_grouping_sets1.out b/regression-test/data/query_p0/grouping_sets/test_grouping_sets1.out new file mode 100644 index 00000000000000..a717f57bf4c079 --- /dev/null +++ b/regression-test/data/query_p0/grouping_sets/test_grouping_sets1.out @@ -0,0 +1,31 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +\N all 0 0 1 +a a 0 0 1 +\N all 1 1 2 + +-- !select1 -- +\N 1 all 1 0 0 0 0 0 1 +a \N a -1 0 0 0 0 0 1 +\N \N all -1 0 1 0 1 1 1 +a \N a -1 0 1 0 1 1 1 +\N \N all -1 1 0 1 0 2 1 +\N 1 all 1 1 0 1 0 2 1 +\N \N all -1 1 1 1 1 3 2 + +-- !select2 -- +\N 1 all 1 0 0 0 0 0 1 +a \N a -1 0 0 0 0 0 1 +\N \N all -1 0 1 0 1 1 1 +a \N a -1 0 1 0 1 1 1 +\N \N all -1 1 0 1 0 2 1 +\N 1 all 1 1 0 1 0 2 1 +\N \N all -1 1 1 1 1 3 2 + +-- !select3 -- +\N 1 all 1 0 0 0 0 0 1 +a \N a -1 0 0 0 0 0 1 +\N \N all -1 0 1 0 1 1 1 +a \N a -1 0 1 0 1 1 1 +\N \N all -1 1 1 1 1 3 2 + diff --git a/regression-test/suites/query_p0/grouping_sets/test_grouping_sets1.groovy b/regression-test/suites/query_p0/grouping_sets/test_grouping_sets1.groovy new file mode 100644 index 00000000000000..477f607a76c7e0 --- /dev/null +++ b/regression-test/suites/query_p0/grouping_sets/test_grouping_sets1.groovy @@ -0,0 +1,112 @@ +// 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_grouping_sets1") { + qt_select """ + select + col1 + ,coalesce( col1, "all" ) as coalesce_col1 + ,grouping(col1) as grouping_col1 + ,grouping_id(col1) as grp_id_col1 + ,count(*) as cnt + from + ( select null as col1 union all select "a" as col1 ) t + group by + grouping sets ( ( col1 ),() ) + order by + grouping_col1,col1 + ; + """ + qt_select1 """ + select + col1 + ,col2 + ,coalesce(col1, "all") as coalesce_col1 + ,coalesce(col2, "-1") as coalesc_col2 + ,grouping(col1) as grouping_col1 + ,grouping(col2) as grouping_col2 + ,grouping_id(col1) as grp_id_col1 + ,grouping_id(col2) as grp_id_col2 + ,grouping_id(col1,col2) as grp_id_col1_col2 + ,count(*) as cnt + from + ( + select null as col1 , 1 as col2 + union all + select "a" as col1 , null as col2 + ) t + group by + cube(col1,col2) + order by + grouping_col1,grouping_col2,col1,col2 + ; + """ + qt_select2 """ + select + col1 + ,col2 + ,coalesce(col1, "all") as coalesce_col1 + ,coalesce(col2, "-1") as coalesc_col2 + ,grouping(col1) as grouping_col1 + ,grouping(col2) as grouping_col2 + ,grouping_id(col1) as grp_id_col1 + ,grouping_id(col2) as grp_id_col2 + ,grouping_id(col1,col2) as grp_id_col1_col2 + ,count(*) as cnt + from + ( + select null as col1 , 1 as col2 + union all + select "a" as col1 , null as col2 + ) t + group by + grouping sets + ( + (col1,col2) + ,(col1) + ,(col2) + ,() + ) + order by + grouping_col1,grouping_col2,col1,col2 + ; + """ + qt_select3 """ + select + col1 + ,col2 + ,coalesce(col1, "all") as coalesce_col1 + ,coalesce(col2, "-1") as coalesc_col2 + ,grouping(col1) as grouping_col1 + ,grouping(col2) as grouping_col2 + ,grouping_id(col1) as grp_id_col1 + ,grouping_id(col2) as grp_id_col2 + ,grouping_id(col1,col2) as grp_id_col1_col2 + ,count(*) as cnt + from + ( + select null as col1 , 1 as col2 + union all + select "a" as col1 , null as col2 + ) t + group by + rollup(col1,col2) + order by + grouping_col1,grouping_col2,col1,col2 + ; + """ +}