From edb8a514148f1b72acfbdfc84881f09ed71369da Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 19 May 2025 15:11:32 +0800 Subject: [PATCH] branch-2.1: [fix](nereids) fix create view use null literal #49881 (#51006) Cherry-picked from #49881 Co-authored-by: feiniaofeiafei --- .../doris/common/jni/vec/VectorColumn.java | 8 +-- .../plans/commands/info/BaseViewInfo.java | 14 ++++- .../create_view_nereids_fix_null.out | 7 +++ .../create_view_nereids_fix_null.groovy | 57 +++++++++++++++++++ 4 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 regression-test/data/ddl_p0/create_view_nereids/create_view_nereids_fix_null.out create mode 100644 regression-test/suites/ddl_p0/create_view_nereids/create_view_nereids_fix_null.groovy diff --git a/fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/vec/VectorColumn.java b/fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/vec/VectorColumn.java index 0fbd6c8da3..596f3a1547 100644 --- a/fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/vec/VectorColumn.java +++ b/fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/vec/VectorColumn.java @@ -1136,7 +1136,7 @@ public class VectorColumn { } } } - childColumns[0].appendObjectColumn(nested, isNullable); + childColumns[0].appendObjectColumn(nested, true); } public ArrayList getArray(int rowId) { @@ -1198,8 +1198,8 @@ public class VectorColumn { } } } - childColumns[0].appendObjectColumn(keys, isNullable); - childColumns[1].appendObjectColumn(values, isNullable); + childColumns[0].appendObjectColumn(keys, true); + childColumns[1].appendObjectColumn(values, true); } public HashMap getMap(int rowId) { @@ -1260,7 +1260,7 @@ public class VectorColumn { appendIndex++; } for (int j = 0; j < childColumns.length; ++j) { - childColumns[j].appendObjectColumn(columnData[j], isNullable); + childColumns[j].appendObjectColumn(columnData[j], true); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java index ad8870fb36..56a97ac5f6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/BaseViewInfo.java @@ -64,6 +64,10 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalTopN; import org.apache.doris.nereids.trees.plans.logical.LogicalView; import org.apache.doris.nereids.trees.plans.logical.LogicalWindow; import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanVisitor; +import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.NullType; +import org.apache.doris.nereids.types.TinyIntType; +import org.apache.doris.nereids.util.TypeCoercionUtils; import org.apache.doris.nereids.util.Utils; import org.apache.doris.qe.ConnectContext; @@ -163,8 +167,9 @@ public class BaseViewInfo { protected void createFinalCols(List outputs) throws org.apache.doris.common.AnalysisException { if (simpleColumnDefinitions.isEmpty()) { for (Slot output : outputs) { - Column column = new Column(output.getName(), output.getDataType().toCatalogDataType(), - output.nullable()); + DataType dataType = TypeCoercionUtils.replaceSpecifiedType(output.getDataType(), NullType.class, + TinyIntType.INSTANCE); + Column column = new Column(output.getName(), dataType.toCatalogDataType(), output.nullable()); finalCols.add(column); } } else { @@ -172,8 +177,11 @@ public class BaseViewInfo { ErrorReport.reportAnalysisException(ErrorCode.ERR_VIEW_WRONG_LIST); } for (int i = 0; i < simpleColumnDefinitions.size(); ++i) { + Slot output = outputs.get(i); + DataType dataType = TypeCoercionUtils.replaceSpecifiedType(output.getDataType(), NullType.class, + TinyIntType.INSTANCE); Column column = new Column(simpleColumnDefinitions.get(i).getName(), - outputs.get(i).getDataType().toCatalogDataType(), outputs.get(i).nullable()); + dataType.toCatalogDataType(), output.nullable()); column.setComment(simpleColumnDefinitions.get(i).getComment()); finalCols.add(column); } diff --git a/regression-test/data/ddl_p0/create_view_nereids/create_view_nereids_fix_null.out b/regression-test/data/ddl_p0/create_view_nereids/create_view_nereids_fix_null.out new file mode 100644 index 0000000000..6269811749 --- /dev/null +++ b/regression-test/data/ddl_p0/create_view_nereids/create_view_nereids_fix_null.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test_null -- +\N + +-- !test_null_array -- +[null, null] + diff --git a/regression-test/suites/ddl_p0/create_view_nereids/create_view_nereids_fix_null.groovy b/regression-test/suites/ddl_p0/create_view_nereids/create_view_nereids_fix_null.groovy new file mode 100644 index 0000000000..4ea07083be --- /dev/null +++ b/regression-test/suites/ddl_p0/create_view_nereids/create_view_nereids_fix_null.groovy @@ -0,0 +1,57 @@ +// 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("create_view_nereids_fix_null") { + sql "drop view if exists test_null" + sql "CREATE VIEW test_null COMMENT '测试null类型' AS SELECT NULL AS `col1`; " + def res = sql "desc test_null" + mustContain(res[0][1], "tinyint") + + sql "drop view if exists test_null_array" + sql "CREATE VIEW test_null_array COMMENT '测试null类型' AS SELECT [NULL, NULL] AS `col1`; " + def res2 = sql "desc test_null_array" + mustContain(res2[0][1], "array") + mustContain(res2[0][2], "No") + + String s3_endpoint = getS3Endpoint() + logger.info("s3_endpoint: " + s3_endpoint) + String bucket = getS3BucketName() + logger.info("bucket: " + bucket) + String driver_url = "https://${bucket}.${s3_endpoint}/regression/jdbc_driver/mysql-connector-java-8.0.25.jar" + String dbname = context.config.getDbNameByFile(context.file) + String jdbcUrl = context.config.jdbcUrl + String jdbcUser = context.config.jdbcUser + logger.info("jdbcUser: " + jdbcUser) + String jdbcPassword = context.config.jdbcPassword + logger.info("jdbcPassword: " + jdbcPassword) + sql "drop catalog if exists create_view_nereids_fix_null_catalog" + sql """ + CREATE CATALOG create_view_nereids_fix_null_catalog PROPERTIES ( + "type"="jdbc", + "user"="${jdbcUser}", + "password"="${jdbcPassword}", + "jdbc_url"="${jdbcUrl}", + "driver_url"="${driver_url}", + "driver_class"="com.mysql.cj.jdbc.Driver" + ); + """ + sql "switch create_view_nereids_fix_null_catalog" + sql "use ${dbname}" + qt_test_null "select * from test_null" + qt_test_null_array "select * from test_null_array" + sql "drop catalog create_view_nereids_fix_null_catalog;" +} \ No newline at end of file