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

feat(native-filters): add temporal support to select filter #13622

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

villebro
Copy link
Member

SUMMARY

Add support for temporal and boolean options to native filters. To facilitate this, a custom SQLAlchemy type is introduced to handle literal binds using datetime objects. In addition, the select Select filter component implements a formatter to show only the relevant digits of the timestamp - YYYY-MM-DD for dates, and YYY-MM-DD HH:MM:SS for hours-seconds and full YYY-MM-DD HH:MM:SS.MMMMMM for sub-second timestamps.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Dropdown options for filter on date column:
image

Dropdown options for filter on datetime column. Notice how the format adapts to only show the date if there are no hours, minutes or seconds:
image

Dropdown options on boolean column:
image

A bunch of filters enabled at the same time:
image

The rendered query:
image

TEST PLAN

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

@codecov
Copy link

codecov bot commented Mar 15, 2021

Codecov Report

Merging #13622 (95cba35) into master (64785c2) will increase coverage by 4.63%.
The diff coverage is 89.88%.

❗ Current head 95cba35 differs from pull request most recent head 6c1899b. Consider uploading reports for the commit 6c1899b to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13622      +/-   ##
==========================================
+ Coverage   72.77%   77.41%   +4.63%     
==========================================
  Files         923      924       +1     
  Lines       46824    46923      +99     
  Branches     5746     5758      +12     
==========================================
+ Hits        34077    36326    +2249     
+ Misses      12531    10461    -2070     
+ Partials      216      136      -80     
Flag Coverage Δ
cypress 56.57% <65.11%> (?)
hive 80.25% <89.74%> (+<0.01%) ⬆️
javascript 63.17% <52.00%> (+0.01%) ⬆️
mysql 80.55% <89.74%> (+<0.01%) ⬆️
postgres 80.59% <89.74%> (-0.01%) ⬇️
presto 80.25% <71.79%> (-0.03%) ⬇️
python 81.10% <89.74%> (+<0.01%) ⬆️
sqlite 80.15% <74.35%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...et-frontend/src/filters/components/Select/types.ts 100.00% <ø> (+100.00%) ⬆️
superset/connectors/druid/models.py 81.99% <ø> (ø)
superset/utils/core.py 88.67% <ø> (ø)
...nd/src/filters/components/Select/transformProps.ts 81.81% <71.42%> (+81.81%) ⬆️
...c/filters/components/Select/SelectFilterPlugin.tsx 80.95% <75.00%> (+80.95%) ⬆️
superset/connectors/sqla/models.py 90.48% <80.00%> (-0.07%) ⬇️
superset/models/sql_types/base.py 84.21% <84.21%> (ø)
...ontend/src/filters/components/Select/buildQuery.ts 77.77% <100.00%> (+77.77%) ⬆️
superset-frontend/src/filters/utils.ts 95.23% <100.00%> (+6.34%) ⬆️
superset-frontend/src/utils/common.js 87.71% <100.00%> (+0.44%) ⬆️
... and 224 more

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 64785c2...6c1899b. Read the comment docs.

@junlincc junlincc added the dashboard:native-filters Related to the native filters of the Dashboard label Mar 17, 2021
@villebro villebro force-pushed the villebro/native-select-format branch from 7a44dc1 to 0c86e5d Compare March 18, 2021 07:58
@@ -145,7 +145,7 @@ def convert_dttm(cls, target_type: str, dttm: datetime) -> Optional[str]:
tt = target_type.upper()
if tt == utils.TemporalType.DATE:
return f"TO_DATE('{dttm.date().isoformat()}', 'YYYY-MM-DD')"
if tt == utils.TemporalType.TIMESTAMP:
if "TIMESTAMP" in tt or "DATETIME" in tt:
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously "TIMESTAMP WITH TIMEZONE" was not being picked up, nor was "DATETIME" (utils.TemporalType needs a good refactor, too, but will leave that to a follow-up PR)

@villebro villebro force-pushed the villebro/native-select-format branch from 0c86e5d to 6c1899b Compare March 18, 2021 08:05
Copy link
Member

@amitmiran137 amitmiran137 left a comment

Choose a reason for hiding this comment

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

LGTM ! I've tested out this locally and tests seems to be covering all changes

@amitmiran137 amitmiran137 merged commit 13f7e0d into apache:master Mar 18, 2021
@villebro villebro deleted the villebro/native-select-format branch March 18, 2021 14:18
allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 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 dashboard:native-filters Related to the native filters of the Dashboard preset-io size/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants