john-bodley opened a new pull request #8464: [sql] Fixing datetime SQL literal URL: https://github.com/apache/incubator-superset/pull/8464 ### CATEGORY Choose one - [x] Bug Fix - [ ] Enhancement (new features, refinement) - [ ] Refactor - [x] Add tests - [ ] Build / Development Environment - [ ] Documentation ### SUMMARY This PR updates a number of aspects related to the datetime SQL literal logic which is used for the RHS of the time filter comparisons. Specifically: 1. Make `DbEngineSpec.convert_dttm` optionally return `None` if a type conversion does not exist. 2. Updates the logic in `dttm_sql_literal` to first try to convert a `datetime` object to a SQL expression (1) prior to converting either a string on numerical type based on the python-date-format. The reason for this change is we should handle known types before falling back to using the python-date-format, as in theory these could be defined incorrectly for non-string/float types. 3. Updates the `convert_dttm` logic for a number of database engines. There were a handful of examples where this was simply returning a string representation of the `datetime` object rather than the necessary SQL expression for casting from a string to the native temporal type. Note I'm not familiar with a number of these database engines and thus the updated conversions were the result of Googling. This logic should probably be validated. 4. Adds unit tests for the database engine specific `convert_dttm` function. 5. Uses f-strings rather than `str.format(...)`. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF <!--- Skip this if not applicable --> ### TEST PLAN CI and additional unit tests. ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [ ] Has associated issue: - [ ] Changes UI - [ ] Requires DB Migration. - [ ] Confirm DB Migration upgrade and downgrade tested. - [ ] Introduces new feature or API - [ ] Removes existing feature or API ### REVIEWERS to: @betodealmeida @dpgaspar @etr2460 @michellethomas @mistercrunch @villebro
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
