datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

In some circumstances cast expression is not working

Open mpurins-coralogix opened this issue 3 years ago • 0 comments

Describe the bug When executing following query field in results has integer datatype instead of string. SELECT cast(c as varchar) FROM (SELECT 1 as c)

To Reproduce Pickup this commit -- https://github.com/coralogix/arrow-datafusion/commit/f5c0fc0ffa56ea9ea02fba60171031bb20a5e7f4 Run cast_failure test.

Expected behavior I would expect that such test is passing, but currently it fails with following error

thread 'sql::cast::cast_failure' panicked at 'assertion failed: `(left == right)`
  left: `Utf8`,
 right: `Int64`', datafusion/core/tests/sql/cast.rs:32:5

Additional context I think this is happening because cast expression is replaced with column expression in columnize_expr (https://github.com/apache/arrow-datafusion/blob/5621e3bbd050eeb79646240ec0a09426badfa162/datafusion/expr/src/utils.rs#L638) and I suspect that it started happening for such queries after following change -- https://github.com/apache/arrow-datafusion/pull/3222/files#diff-204cfc4f999c3d12dc065f323cb952fb0ecb33c5570eed8dc1fb52b806e87004L926

mpurins-coralogix avatar Sep 15 '22 15:09 mpurins-coralogix