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: Add week time grain for Elasticsearch datasets #25683

Merged

Conversation

mikelv92
Copy link
Contributor

@mikelv92 mikelv92 commented Oct 17, 2023

SUMMARY

This PR adds the week time grain for the Elasticsearch database engine. This is needed if the user wants to see a week granularity in a time series chart.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

before:
before

after:
after
chart

TESTING INSTRUCTIONS

To verify the changes:

  • Create a database connection to an Elasticsearch cluster
  • Create an index in the Elasticsearch cluster. The index documents should have a date field and at least another field to be used in a metric
  • Create a dataset using the Elasticsearch database, and the choose the index created previously as the table
  • Create a time series chart and use the date field in the x axis
  • Choose the Week Time Grain from the drop down menu

ADDITIONAL INFORMATION

  • Has associated issue: Fixes ElasticSearch's dataset has not "week" option in chart TIME GRAIN #23271
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

@@ -46,6 +46,7 @@ class ElasticSearchEngineSpec(BaseEngineSpec): # pylint: disable=abstract-metho
TimeGrain.MINUTE: "HISTOGRAM({col}, INTERVAL 1 MINUTE)",
TimeGrain.HOUR: "HISTOGRAM({col}, INTERVAL 1 HOUR)",
TimeGrain.DAY: "HISTOGRAM({col}, INTERVAL 1 DAY)",
TimeGrain.WEEK: "DATE_TRUNC('week', {col})",
Copy link
Member

Choose a reason for hiding this comment

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

Why are we using DATE_TRUNC and not HISTOGRAM? Ideally it would be great if these were consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The HISTOGRAM groups the data by INTERVAL but there is no "week" interval in Elasticsearch.

Perhaps there is a refactor needed to use DATE_TRUNC for the other time grains as well? I could do it, but as I am new to this community, could you let me know if I should do it in this PR or open a separate one for refactoring? 😄

Copy link
Member

Choose a reason for hiding this comment

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

@mikelv92 thanks for the explanation. I think it's ok to merge this PR as is, but if you're interested in doing a fast follow to change all the existing time grains to use DATE_TRUNC—which seems to be the blessed option—that would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@john-bodley Here is the follow-up PR: #25717

@@ -0,0 +1,53 @@
# Licensed to the Apache Software Foundation (ASF) under one
Copy link
Member

Choose a reason for hiding this comment

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

Woot! Thanks for adding a test.

@john-bodley john-bodley changed the title feat: Add week time grain for elasticsearch datasets feat: Add week time grain for Elasticsearch datasets Oct 19, 2023
@john-bodley john-bodley merged commit e7cdfee into apache:master Oct 19, 2023
31 checks passed
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
Co-authored-by: Mikel Vuka <mikel.vuka@zalando.de>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 2024
sfirke pushed a commit to sfirke/superset that referenced this pull request Mar 22, 2024
Co-authored-by: Mikel Vuka <mikel.vuka@zalando.de>
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 2024
Co-authored-by: Mikel Vuka <mikel.vuka@zalando.de>
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 size/M 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ElasticSearch's dataset has not "week" option in chart TIME GRAIN
3 participants