Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[schema] Deprecating the table_columns.database_expression column #7653

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jun 5, 2019

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

As far as I can tell I believe that the database_expression field for SQLAlchemy datasources is obsolete. Why? There are currently two (independent) mechanisms for for converting a Python date-time into the appropriate data type for temporal filters (which are only used here):

  1. python_date_format: Which is used explicitly for string like or numeric types (represent Unix timestamps) and converts a Python datetime object into either a string or numeric type.
  2. database_expression: Which is used for date, date-time like types and converts a Python datatime object into the native database type using a SQL expression.

The reason the later is not required is each engine has already defined the date-time conversion (via the convert_dttm function for the various temporal types the engine supports in db_engine_specs.

This PR modifies the dttm_sql_literal method to simply deprecate the need for database_expression as the appropriate conversion will occur here.

For reference I examined our deployment where the database_expression field was defined, of the 15 records only four contained valid SQL and in all cases they were being used either i) incorrectly, i.e., the filter comparison resulted in mixed types, or ii) in an unnecessary manner. For example there was a record (associated with a Presto datasource) which contained the following fields:

  • type: VARCHAR
  • expression: FROM_UNIXTIME(CAST(timestamp as BIGINT) / 1000)
  • database_expression: DATE_PARSE('{}', '%%Y-%%m-%%d %%H:%%i:%%s')

The mistake here is that FROM_UNIXTIME returns a TIMESTAMP rather than VARCHAR and had the type been correctly defined, the PrestoEngineSpec.convert_dttm method would have correctly handled the conversion here. Note if the timestamp column was expressed as milliseconds since epoch the column could have been defined as:

  • type: BIGINT
  • python_date_format: epoch_ms

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screen Shot 2019-06-05 at 1 27 28 PM
Screen Shot 2019-06-05 at 1 27 40 PM

TEST PLAN

CI.

ADDITIONAL INFORMATION

  • 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 @michellethomas @mistercrunch @villebro

@john-bodley
Copy link
Member Author

#7656

@john-bodley john-bodley force-pushed the john-bodley--deprecate-database-expression branch from 802406b to eb87690 Compare June 16, 2019 05:06
UPDATING.md Outdated
@@ -23,6 +23,11 @@ assists people when migrating to a new version.

## Next Version

* [7653](https://github.com/apache/incubator-superset/pull/7653): a change
whcih deprecates the table_columns.database_expression column. Expressions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: whcih -> which

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small typo and needs rebase, otherwise LGTM. Kudos for achieving diff with more - than + 👍

@john-bodley john-bodley added the risk:db-migration PRs that require a DB migration label Jun 26, 2019
@john-bodley
Copy link
Member Author

@betodealmeida @mistercrunch are you onboard with this change?

@john-bodley john-bodley force-pushed the john-bodley--deprecate-database-expression branch from 6aaf4cd to 9d826ae Compare June 26, 2019 22:29
@betodealmeida
Copy link
Member

+1 from me

@john-bodley john-bodley force-pushed the john-bodley--deprecate-database-expression branch 2 times, most recently from f5fec06 to 8f72373 Compare July 3, 2019 18:17
@john-bodley john-bodley force-pushed the john-bodley--deprecate-database-expression branch from 8f72373 to 970e4c4 Compare July 3, 2019 18:23
@codecov-io
Copy link

codecov-io commented Jul 3, 2019

Codecov Report

Merging #7653 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7653      +/-   ##
==========================================
- Coverage   65.89%   65.89%   -0.01%     
==========================================
  Files         459      459              
  Lines       22016    22013       -3     
  Branches     2417     2417              
==========================================
- Hits        14507    14505       -2     
+ Misses       7388     7387       -1     
  Partials      121      121
Impacted Files Coverage Δ
superset/connectors/base/models.py 89.89% <ø> (ø) ⬆️
...uperset/assets/src/datasource/DatasourceEditor.jsx 61.84% <ø> (ø) ⬆️
superset/connectors/sqla/views.py 65.28% <ø> (ø) ⬆️
superset/connectors/sqla/models.py 82.48% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0125ba4...970e4c4. Read the comment docs.

@john-bodley john-bodley merged commit 9dac805 into apache:master Jul 3, 2019
@john-bodley john-bodley deleted the john-bodley--deprecate-database-expression branch July 3, 2019 21:06
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels risk:db-migration PRs that require a DB migration size/L 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants