branch-2.1: [fix](nereids) fix create view use null literal #49881 (#51006)

Cherry-picked from #49881

Co-authored-by: feiniaofeiafei <moailing@selectdb.com>
This commit is contained in:
github-actions[bot]
2025-05-19 15:11:32 +08:00
committed by GitHub
parent 51b39d0992
commit edb8a51414
4 changed files with 79 additions and 7 deletions

View File

@ -1136,7 +1136,7 @@ public class VectorColumn {
}
}
}
childColumns[0].appendObjectColumn(nested, isNullable);
childColumns[0].appendObjectColumn(nested, true);
}
public ArrayList<Object> 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<Object, Object> 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);
}
}

View File

@ -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<Slot> 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);
}

View File

@ -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]

View File

@ -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<tinyint>")
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;"
}