This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 82a0d918eb9706c815c5d9582ce7f03527e681b0 Author: TengJianPing <[email protected]> AuthorDate: Thu Jun 8 20:05:23 2023 +0800 [fix](case expr) fix coredump of case for null value (#20564) be coredump when when expr is null: --- be/src/vec/functions/function_case.h | 8 +- .../sql_functions/case_function/case_null0.csv | 3 + .../sql_functions/case_function/case_null1.csv | 11 ++ .../case_function/test_case_function_null.out | 6 + .../case_function/test_case_function_null.groovy | 176 +++++++++++++++++++++ 5 files changed, 200 insertions(+), 4 deletions(-) diff --git a/be/src/vec/functions/function_case.h b/be/src/vec/functions/function_case.h index 5c2b39d7f8..a4049f7840 100644 --- a/be/src/vec/functions/function_case.h +++ b/be/src/vec/functions/function_case.h @@ -301,13 +301,13 @@ public: bool then_null = false; for (int i = 1 + has_case; i < arguments.size() - has_else; i += 2) { auto then_column_ptr = block.get_by_position(arguments[i]).column; - if (then_column_ptr->is_nullable()) { + if (then_column_ptr->is_nullable() || then_column_ptr->only_null()) { then_null = true; } } if constexpr (has_else) { auto else_column_ptr = block.get_by_position(arguments[arguments.size() - 1]).column; - if (else_column_ptr->is_nullable()) { + if (else_column_ptr->is_nullable() || else_column_ptr->only_null()) { then_null = true; } } else { @@ -333,13 +333,13 @@ public: bool when_null = false; if constexpr (has_case) { auto case_column_ptr = block.get_by_position(arguments[0]).column; - if (case_column_ptr->is_nullable()) { + if (case_column_ptr->is_nullable() || case_column_ptr->only_null()) { when_null = true; } } for (int i = has_case; i < arguments.size() - has_else; i += 2) { auto when_column_ptr = block.get_by_position(arguments[i]).column; - if (when_column_ptr->is_nullable()) { + if (when_column_ptr->is_nullable() || when_column_ptr->only_null()) { when_null = true; } } diff --git a/regression-test/data/query_p0/sql_functions/case_function/case_null0.csv b/regression-test/data/query_p0/sql_functions/case_function/case_null0.csv new file mode 100644 index 0000000000..5275e77971 --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/case_function/case_null0.csv @@ -0,0 +1,3 @@ +1.0 1 1970-11-13 +0.7 0 1970-01-04 +\N 0 1970-10-29 diff --git a/regression-test/data/query_p0/sql_functions/case_function/case_null1.csv b/regression-test/data/query_p0/sql_functions/case_function/case_null1.csv new file mode 100644 index 0000000000..3b211b2d1f --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/case_function/case_null1.csv @@ -0,0 +1,11 @@ + +kejc8^H + + + + +)ꪁ + + + +kꪁNhR diff --git a/regression-test/data/query_p0/sql_functions/case_function/test_case_function_null.out b/regression-test/data/query_p0/sql_functions/case_function/test_case_function_null.out new file mode 100644 index 0000000000..e671ae0ee4 --- /dev/null +++ b/regression-test/data/query_p0/sql_functions/case_function/test_case_function_null.out @@ -0,0 +1,6 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql_case0 -- +1970-01-04 false +1970-10-29 false +1970-11-13 true + diff --git a/regression-test/suites/query_p0/sql_functions/case_function/test_case_function_null.groovy b/regression-test/suites/query_p0/sql_functions/case_function/test_case_function_null.groovy new file mode 100644 index 0000000000..e625023525 --- /dev/null +++ b/regression-test/suites/query_p0/sql_functions/case_function/test_case_function_null.groovy @@ -0,0 +1,176 @@ +// 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_case_function_null", "query,p0") { + sql """ drop table if exists case_null0 """ + sql """ create table case_null0 ( + `c0` decimalv3(17, 1) NULL, + `c1` boolean NOT NULL, + `c2` date NOT NULL + ) ENGINE=OLAP + DUPLICATE KEY(`c0`, `c1`, `c2`) + DISTRIBUTED BY RANDOM BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ drop table if exists `case_null1` """ + sql """ + CREATE TABLE `case_null1` ( + `c0` varchar(7) NOT NULL DEFAULT "" + ) ENGINE=OLAP + AGGREGATE KEY(`c0`) + DISTRIBUTED BY RANDOM BUCKETS 24 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + def tables = ["case_null0", "case_null1"] + + for (String tableName in tables) { + streamLoad { + // a default db 'regression_test' is specified in + // ${DORIS_HOME}/conf/regression-conf.groovy + table tableName + + // default label is UUID: + // set 'label' UUID.randomUUID().toString() + + // default column_separator is specify in doris fe config, usually is '\t'. + // this line change to ',' + set 'column_separator', '\t' + // relate to ${DORIS_HOME}/regression-test/data/demo/streamload_input.csv. + // also, you can stream load a http stream, e.g. http://xxx/some.csv + file """${tableName}.csv""" + + time 10000 // limit inflight 10s + + // stream load action will check result, include Success status, and NumberTotalRows == NumberLoadedRows + + // if declared a check callback, the default check condition will ignore. + // So you must check all condition + check { result, exception, startTime, endTime -> + if (exception != null) { + throw exception + } + log.info("Stream load result: ${result}".toString()) + def json = parseJson(result) + assertEquals("success", json.Status.toLowerCase()) + assertEquals(json.NumberTotalRows, json.NumberLoadedRows) + } + } + } + + qt_sql_case0 """ + SELECT * FROM ( + SELECT + case_null0.c2 c2, + case_null0.c1 c1 + FROM + case_null0, + case_null1 + WHERE + CASE + ( + CAST(TIMESTAMP '1970-10-27 14:44:27' AS DATE) BETWEEN DATE '1970-08-05' + AND DATE '1970-07-12' + ) + WHEN CAST(NULL AS BOOLEAN) THEN (NULL IN (NULL)) + WHEN (('쬊o') !=('Sf^M7mir')) THEN ( + ('0.24865') LIKE ( + CASE + false + WHEN case_null0.c1 THEN case_null1.c0 + WHEN case_null0.c1 THEN case_null1.c0 + END + ) + ) + END + GROUP BY + case_null0.c2, + case_null0.c1, + case_null1.c0 + UNION + SELECT + case_null0.c2 c2, + case_null0.c1 c1 + FROM + case_null0, + case_null1 + WHERE + ( + NOT CASE + ( + CAST(TIMESTAMP '1970-10-27 14:44:27' AS DATE) BETWEEN DATE '1970-08-05' + AND DATE '1970-07-12' + ) + WHEN CAST(NULL AS BOOLEAN) THEN (NULL IN (NULL)) + WHEN (('쬊o') !=('Sf^M7mir')) THEN ( + ('0.24865') LIKE ( + CASE + false + WHEN case_null0.c1 THEN case_null1.c0 + WHEN case_null0.c1 THEN case_null1.c0 + END + ) + ) + END + ) + GROUP BY + case_null0.c2, + case_null0.c1, + case_null1.c0 + UNION + SELECT + case_null0.c2 c2, + case_null0.c1 c1 + FROM + case_null0, + case_null1 + WHERE + ( + ( + CASE + ( + CAST(TIMESTAMP '1970-10-27 14:44:27' AS DATE) BETWEEN DATE '1970-08-05' + AND DATE '1970-07-12' + ) + WHEN CAST(NULL AS BOOLEAN) THEN (NULL IN (NULL)) + WHEN (('쬊o') !=('Sf^M7mir')) THEN ( + ('0.24865') like ( + CASE + false + WHEN case_null0.c1 THEN case_null1.c0 + WHEN case_null0.c1 THEN case_null1.c0 + END + ) + ) + END + ) IS NULL + ) + GROUP BY + case_null0.c2, + case_null0.c1, + case_null1.c0 + ) a + order BY + c2, + c1; + """ +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
