This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new ccba5a729a [fix](planner)cast string to float like type should return
NULL literal if it fails (#24222)
ccba5a729a is described below
commit ccba5a729aec3b7c1faf2880e189d6649c7264d1
Author: starocean999 <[email protected]>
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 | 3 +++
.../suites/correctness_p0/test_cast_null.groovy | 28 ++++++++++++++++++++++
3 files changed, 33 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 2e552824d6..66747e0002 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;
@@ -240,9 +238,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
index 1a685b0c3a..2cba0e599d 100644
--- a/regression-test/data/correctness_p0/test_cast_null.out
+++ b/regression-test/data/correctness_p0/test_cast_null.out
@@ -11,3 +11,6 @@
-- !sql4 --
\N
+-- !sql5 --
+\N
+
diff --git a/regression-test/suites/correctness_p0/test_cast_null.groovy
b/regression-test/suites/correctness_p0/test_cast_null.groovy
index 4bf78a30c8..c7acdddb18 100644
--- a/regression-test/suites/correctness_p0/test_cast_null.groovy
+++ b/regression-test/suites/correctness_p0/test_cast_null.groovy
@@ -84,4 +84,32 @@ suite("test_cast_null") {
qt_sql4 """
select 'abc' like 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: [email protected]
For additional commands, e-mail: [email protected]