findepi commented on code in PR #16539: URL: https://github.com/apache/datafusion/pull/16539#discussion_r2164433469
########## datafusion/common/src/scalar/mod.rs: ########## @@ -3069,7 +3069,7 @@ impl ScalarValue { ScalarValue::Decimal128(Some(decimal_value), _, scale), DataType::Timestamp(time_unit, None), ) => { - let scale_factor = 10_i128.pow(*scale as u32); + let scale_factor = 10_i128.pow(*scale as u32 + 3); Review Comment: Does this depend on the timestamp precision (time unit)? Can you please add tests for other units? Do we need this special casing at all for casting decimal to timestamp? or can we end up calling `cast_with_options`, just like we do for virtually all other type pairs? ########## datafusion/sqllogictest/test_files/timestamps.slt: ########## @@ -3420,3 +3420,8 @@ select to_timestamp('-1'); query error DataFusion error: Arrow error: Parser error: Error parsing timestamp from '\-1': timestamp must contain at least 10 characters select to_timestamp(arrow_cast('-1', 'Utf8')); + +query B +SELECT CAST(CAST(x AS decimal(17,2)) AS timestamp(3)) = CAST(CAST(1 AS decimal(17,2)) AS timestamp(3)) from (values (1)) t(x); +---- Review Comment: Formatting like this will help see why these should be equal. Also it's enough to project the values. (They should be equal, but also they should be particular values). ``` SELECT CAST(CAST(1 AS decimal(17,2)) AS timestamp(3)) AS a UNION ALL SELECT CAST(CAST(one AS decimal(17,2)) AS timestamp(3)) AS a FROM (VALUES (1)) t(one); ``` -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org