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 81a7b69b1fa72cd09bbd366bf1af437438f76003 Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Thu Sep 14 15:59:20 2023 +0800 [fix](planner)cast string to float like type should return NULL literal if it fails (#24222) --- .../org/apache/doris/analysis/StringLiteral.java | 6 +-- .../data/correctness_p0/test_cast_null.out | 4 ++ .../suites/correctness_p0/test_cast_null.groovy | 46 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java index 1804730663d..743b074f909 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java @@ -24,8 +24,6 @@ import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.Type; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.DdlException; -import org.apache.doris.common.ErrorCode; -import org.apache.doris.common.ErrorReport; import org.apache.doris.common.io.Text; import org.apache.doris.qe.VariableVarConverters; import org.apache.doris.thrift.TExprNode; @@ -249,9 +247,9 @@ public class StringLiteral extends LiteralExpr { try { return new FloatLiteral(Double.valueOf(value), targetType); } catch (NumberFormatException e) { - ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_NUMBER, value); + // consistent with CastExpr's getResultValue() method + return new NullLiteral(); } - break; case DECIMALV2: case DECIMAL32: case DECIMAL64: diff --git a/regression-test/data/correctness_p0/test_cast_null.out b/regression-test/data/correctness_p0/test_cast_null.out new file mode 100644 index 00000000000..aca783cc93d --- /dev/null +++ b/regression-test/data/correctness_p0/test_cast_null.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql5 -- +\N + diff --git a/regression-test/suites/correctness_p0/test_cast_null.groovy b/regression-test/suites/correctness_p0/test_cast_null.groovy new file mode 100644 index 00000000000..f6761c8b90b --- /dev/null +++ b/regression-test/suites/correctness_p0/test_cast_null.groovy @@ -0,0 +1,46 @@ +// 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_cast_null") { + sql """ + drop table if exists test_table_t1; + """ + + sql """ + CREATE TABLE `test_table_t1` ( + `k1` DECIMAL(12, 5) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`k1`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`k1`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "is_being_synced" = "false", + "storage_format" = "V2", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false" + ); + """ + sql """insert into test_table_t1 values(1.0);""" + + qt_sql5 """select k1 <> '' from test_table_t1;""" + + sql """ + drop table if exists test_table_t1; + """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org