scsmithr opened a new issue, #15161:
URL: https://github.com/apache/datafusion/issues/15161
### Describe the bug
A comparison like `column1 < '10'` (where `column1` is an int64) will cast
`column1` to utf8 instead of casting the utf8 constant to an integer.
Typically string constants in a sql query are treated as unknown, and
preference should be on casting the "unknown" value to a target type.
### To Reproduce
```
DataFusion CLI v46.0.0
> create table t1 as (values (1), (2), (3));
0 row(s) fetched.
Elapsed 0.026 seconds.
> select * from t1 where column1 < '10';
+---------+
| column1 |
+---------+
| 1 |
+---------+
1 row(s) fetched.
Elapsed 0.015 seconds.
> select * from t1 where column1 < 'hello';
+---------+
| column1 |
+---------+
| 1 |
| 2 |
| 3 |
+---------+
3 row(s) fetched.
Elapsed 0.007 seconds.
> select arrow_typeof(column1) from t1 limit 1;
+--------------------------+
| arrow_typeof(t1.column1) |
+--------------------------+
| Int64 |
+--------------------------+
1 row(s) fetched.
Elapsed 0.010 seconds.
> explain select * from t1 where column1 < '10';
+---------------+-------------------------------------------------------+
| plan_type | plan |
+---------------+-------------------------------------------------------+
| logical_plan | Filter: CAST(t1.column1 AS Utf8) < Utf8("10") |
| | TableScan: t1 projection=[column1] |
| physical_plan | CoalesceBatchesExec: target_batch_size=8192 |
| | FilterExec: CAST(column1@0 AS Utf8) < 10 |
| | DataSourceExec: partitions=1, partition_sizes=[1] |
| | |
+---------------+-------------------------------------------------------+
2 row(s) fetched.
Elapsed 0.009 seconds.
```
### Expected behavior
`column1` not to be cast to a string.
### Additional context
_No response_
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]