sgrebnov opened a new pull request, #12282:
URL: https://github.com/apache/datafusion/pull/12282

   ## Which issue does this PR close?
   
   PR improves unparser to produce valid CAST SQL for SQLite and Date32
   
   ## Rationale for this change
   
   SQLite does not have dedicated DATE type and prefers a text string that is 
an [ISO 8601 date/time](https://www.sqlite.org/lang_datefunc.html) value:
   
   ```sql
   SELECT CAST('1995-03-15' AS DATE), DATE('1995-03-15'), CAST('1995-03-15' AS 
TEXT)
   ```
   
   
![image](https://github.com/user-attachments/assets/a4a69235-0bbb-48af-ad5f-1ef238e93813)
   
   Test query (native)
   ```sql
   SELECT count(o_orderdate) FROM orders 
   WHERE `orders`.`o_orderdate`< '1995-03-15'
   
   7286 rows
   ```
   
   Existing  unparser behavior, producing `'1995-03-15' AS DATE` SQL for SQLite
   ```sql
   SELECT count(o_orderdate) FROM orders 
   WHERE `orders`.`o_orderdate`< CAST('1995-03-15' AS DATE)
   
   0 rows
   ```
   
   Fixed unparser behavior, producing valid `'1995-03-15' AS TEXT` SQL for 
SQLite
   ```sql
   select count(o_orderdate) from orders 
   where `orders`.`o_orderdate` < CAST('1995-03-15' AS TEXT)
   
   7286 rows
   ```
   
   
   ## What changes are included in this PR?
   
   PR introduces configurable `date32_cast_dtype` dialect parameter that 
controls whether DATE vs TEXT is used for Date32 unparsing.
   
   ## Are these changes tested?
   
   Yes, added unit tests + manual testing
   
   ## Are there any user-facing changes?
   
   `CustomDialectBuilder` now supports `with_date32_cast_dtype` that can be 
used to specify desired type that should be used for Date32 unparsing.
   


-- 
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

Reply via email to