morrySnow commented on code in PR #50425: URL: https://github.com/apache/doris/pull/50425#discussion_r2065271938
########## regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_string_arithmatic.groovy: ########## @@ -1724,5 +1726,98 @@ suite("fold_constant_string_arithmatic") { testFoldConst("select split_by_string('a😁a😁a', '')") testFoldConst("select character_length('a😁a😁a')") testFoldConst("select replace_empty('a😁a😁a', '', '2')") + + // cast double to string like + testFoldConst("select cast(cast(0 as double) as varchar(65533))") + testFoldConst("select cast(cast(0 as double) as string)") + testFoldConst("select cast(cast(0.0 as double) as varchar(65533))") + testFoldConst("select cast(cast(0.0 as double) as string)") + testFoldConst("select cast(cast(1 as double) as varchar(65533))") + testFoldConst("select cast(cast(1 as double) as string)") + testFoldConst("select cast(cast(1.0 as double) as varchar(65533))") + testFoldConst("select cast(cast(1.0 as double) as string)") + testFoldConst("select cast(cast(0.1 as double) as varchar(65533))") + testFoldConst("select cast(cast(0.1 as double) as string)") + testFoldConst("select cast(cast(1.1 as double) as varchar(65533))") + testFoldConst("select cast(cast(1.1 as double) as string)") + testFoldConst("select cast(cast(100000 as double) as string)") + testFoldConst("select cast(cast(1000000000000000 as double) as string)") Review Comment: test `10000000000000001 (1.0{15}1)`, `10000000000000010 (1.0{14}1e16)`, `10000000000000100 (1.0{13}1e16)` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FoldConstantRuleOnFE.java: ########## @@ -515,6 +519,22 @@ public Expression visitCast(Cast cast, ExpressionRewriteContext context) { } } + // Check if the given literal value is safe to cast to the targetType. + // We need to guarantee FE cast result is identical with BE cast result. + // Otherwise, it's not safe. + protected boolean safeToCast(Cast cast) { + if (cast == null || cast.child() == null || cast.getDataType() == null) { + return true; + } + // Check double type. + if (cast.child() instanceof DoubleLiteral && cast.getDataType().isStringLikeType()) { + Double value = ((DoubleLiteral) cast.child()).getValue(); + return -1E16 < value && value < 1E16; Review Comment: if value is nan or inf, this function will return false? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org