Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ public void appendArray(List<Object>[] batch, boolean isNullable) {
}
}
}
childColumns[0].appendObjectColumn(nested, isNullable);
childColumns[0].appendObjectColumn(nested, true);
}

public ArrayList<Object> getArray(int rowId) {
Expand Down Expand Up @@ -1198,8 +1198,8 @@ public void appendMap(Map<Object, Object>[] batch, boolean isNullable) {
}
}
}
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) {
Expand Down Expand Up @@ -1260,7 +1260,7 @@ public void appendStruct(Map<String, Object>[] batch, boolean isNullable) {
appendIndex++;
}
for (int j = 0; j < childColumns.length; ++j) {
childColumns[j].appendObjectColumn(columnData[j], isNullable);
childColumns[j].appendObjectColumn(columnData[j], true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
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;

Expand Down Expand Up @@ -163,17 +167,21 @@ protected String rewriteProjectsToUserDefineAlias(String resSql) {
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 {
if (outputs.size() != simpleColumnDefinitions.size()) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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]

Original file line number Diff line number Diff line change
@@ -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;"
}