From 0f8b15b902eab4908a70052b867e38cf505e7bea Mon Sep 17 00:00:00 2001 From: Kikyou1997 <33112463+Kikyou1997@users.noreply.github.com> Date: Wed, 28 Dec 2022 17:26:48 +0800 Subject: [PATCH] [feature](nereids) support string alias in select list (#15369) support such syntax: select '' as 'b', col1 from select_with_const --- .../org/apache/doris/nereids/DorisParser.g4 | 1 + .../nereids/parser/LogicalPlanBuilder.java | 3 ++ .../data/nereids_syntax_p0/select_const.out | 10 ++++ .../nereids_syntax_p0/select_const.groovy | 50 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 regression-test/data/nereids_syntax_p0/select_const.out create mode 100644 regression-test/suites/nereids_syntax_p0/select_const.groovy diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 8dbd7dd23b..e4b28a0069 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -226,6 +226,7 @@ multipartIdentifier // -----------------Expression----------------- namedExpression : expression (AS? name=errorCapturingIdentifier)? + | expression (AS? strName=STRING+)? ; namedExpressionSeq diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index 269704fe15..ee32a2a9ae 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -500,6 +500,9 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { Expression expression = getExpression(ctx.expression()); if (ctx.name != null) { return new UnboundAlias(expression, ctx.name.getText()); + } else if (ctx.strName != null) { + return new UnboundAlias(expression, ctx.strName.getText() + .substring(1, ctx.strName.getText().length() - 1)); } else { return expression; } diff --git a/regression-test/data/nereids_syntax_p0/select_const.out b/regression-test/data/nereids_syntax_p0/select_const.out new file mode 100644 index 0000000000..90b14f899b --- /dev/null +++ b/regression-test/data/nereids_syntax_p0/select_const.out @@ -0,0 +1,10 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- + 1994 + +-- !select -- + + +-- !select -- +1994 + diff --git a/regression-test/suites/nereids_syntax_p0/select_const.groovy b/regression-test/suites/nereids_syntax_p0/select_const.groovy new file mode 100644 index 0000000000..fff8831c03 --- /dev/null +++ b/regression-test/suites/nereids_syntax_p0/select_const.groovy @@ -0,0 +1,50 @@ +// 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("select_with_const") { + sql "SET enable_nereids_planner=true" + + sql """ + DROP TABLE IF EXISTS select_with_const + """ + + sql """CREATE TABLE IF NOT EXISTS select_with_const (col1 int not null, col2 int not null, col3 int not null) + DISTRIBUTED BY HASH(col3) + BUCKETS 1 + PROPERTIES( + "replication_num"="1" + ) + """ + + sql """ + insert into select_with_const values(1994, 1994, 1995) + """ + + sql "SET enable_fallback_to_original_planner=false" + + qt_select """ + select '' as 'b', col1 from select_with_const + """ + + qt_select """ + select '' as 'b' from select_with_const + """ + + qt_select """ + SELECT col1 AS 'str' FROM select_with_const + """ +}