apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
6.17k stars 1.16k forks source link

Support type coercion between timestamp and unixtime #12891

Open niebayes opened 1 week ago

niebayes commented 1 week ago

Is your feature request related to a problem or challenge?

Say there's a table consisting of a timestamp column with the precision seconds. If we can support type coercion between timestamp and unixtime, a query SELECT * FROM tbl WHERE ts > 1723527660 would be regarded legal and there's no need to wrap the unixtime with the function from_unixtime.

Describe the solution you'd like

Add a cast path between timestamp and unixtime, and try to cast a integer to a certain timestamp type when building a plan. Reports an error when such a cast fails.

Describe alternatives you've considered

No response

Additional context

No response

Omega359 commented 1 week ago

related: https://github.com/apache/datafusion/pull/11040 tangential (date & int64): https://github.com/apache/datafusion/issues/12342