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

fix: remove unused time column when update dataset #14969

Merged
merged 3 commits into from
Jul 28, 2021

Conversation

zhaoyongjie
Copy link
Member

@zhaoyongjie zhaoyongjie commented Jun 3, 2021

SUMMARY

closes: #14683
superset-ui related PR: apache-superset/superset-ui#1148

Since the early Superset TableSource references to Druid table structure, there was always a time dimension(time partition column) in all tables(as known as, datasource or dataset). But this concept is not suitable for other data warehouses or databases.

There is a main_dttm_col field in the superset dataset, service time dimension. Now if a time column is not passed to superset backend, the main_dttm_col will be used in the time column.

This change

  • allows Superset to receive null time column
  • force user update time column value when user changed existing time column type(for instance: uncheck is_temporal)

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before

before.mp4

After

after.mp4

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

@codecov
Copy link

codecov bot commented Jun 3, 2021

Codecov Report

Merging #14969 (d55db8c) into master (7330aef) will decrease coverage by 0.23%.
The diff coverage is 20.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14969      +/-   ##
==========================================
- Coverage   77.08%   76.84%   -0.24%     
==========================================
  Files         984      984              
  Lines       51787    51796       +9     
  Branches     7036     7041       +5     
==========================================
- Hits        39920    39804     -116     
- Misses      11642    11767     +125     
  Partials      225      225              
Flag Coverage Δ
hive ?
javascript 71.71% <11.11%> (-0.03%) ⬇️
mysql 81.54% <100.00%> (-0.01%) ⬇️
postgres 81.56% <100.00%> (-0.01%) ⬇️
presto ?
python 81.65% <100.00%> (-0.44%) ⬇️
sqlite 81.19% <100.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
...re/components/controls/DatasourceControl/index.jsx 79.06% <11.11%> (-8.11%) ⬇️
superset/connectors/sqla/models.py 88.20% <100.00%> (-1.76%) ⬇️
superset/db_engines/hive.py 0.00% <0.00%> (-82.15%) ⬇️
superset/db_engine_specs/hive.py 69.44% <0.00%> (-17.07%) ⬇️
superset/db_engine_specs/presto.py 83.36% <0.00%> (-6.53%) ⬇️
superset/views/database/mixins.py 81.03% <0.00%> (-1.73%) ⬇️
superset/db_engine_specs/base.py 88.28% <0.00%> (-0.40%) ⬇️
superset/models/core.py 89.61% <0.00%> (-0.26%) ⬇️
superset/utils/core.py 88.12% <0.00%> (-0.13%) ⬇️
... and 1 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 7330aef...d55db8c. Read the comment docs.

@junlincc
Copy link
Member

junlincc commented Jun 3, 2021

Awesome PR description! thanks for the fix 🙏

@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2021

@junlincc Ephemeral environment spinning up at http://52.42.220.175:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2021

Ephemeral environment shutdown and build artifacts deleted.

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.

A few minor ideas/comments

Comment on lines 121 to 134
// remove time column in the form_data
const timeCol = this.props.form_data?.granularity_sqla; // eslint-disable-line camelcase
const { columns } = this.props.datasource;
if (
datasource.type === 'table' &&
!columns.find(({ column_name }) => column_name === timeCol)?.is_dttm // eslint-disable-line camelcase
) {
this.props.actions.setControlValue('granularity_sqla', null);
}
Copy link
Member

Choose a reason for hiding this comment

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

When the time column control is empty and a column is made is_dttm, the time column control stays empty, despite being required (not possible to remove value once set). Would it make sense to default to the first temporal column if the value is unset? Something like this:

diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx b/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx
index 873067565..44452fb0c 100644
--- a/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx
+++ b/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx
@@ -121,12 +121,20 @@ class DatasourceControl extends React.PureComponent {
     // remove time column in the form_data
     const timeCol = this.props.form_data?.granularity_sqla; // eslint-disable-line camelcase
     const { columns } = this.props.datasource;
+    const firstDttmCol = columns.find(column => column.is_dttm);
     if (
       datasource.type === 'table' &&
+      timeCol &&
       !columns.find(({ column_name }) => column_name === timeCol)?.is_dttm // eslint-disable-line camelcase
     ) {
       this.props.actions.setControlValue('granularity_sqla', null);
+    } else if (datasource.type === 'table' && !timeCol && firstDttmCol) {
+      this.props.actions.setControlValue(
+        'granularity_sqla',
+        firstDttmCol.column_name,
+      );
     }
+
     if (this.props.onDatasourceSave) {
       this.props.onDatasourceSave(datasource);
     }

Copy link
Member Author

@zhaoyongjie zhaoyongjie Jun 8, 2021

Choose a reason for hiding this comment

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

thanks for your comments! This has the side effect of leaving an unexpected column to do the filtering and grain(in other words, first datetime column depends on the order of the columns in the database.). What do you think about?

Copy link
Member Author

@zhaoyongjie zhaoyongjie Jul 26, 2021

Choose a reason for hiding this comment

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

Done this change. Thanks for the comment!

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.

LGTM

@zhaoyongjie zhaoyongjie merged commit 11b0249 into apache:master Jul 28, 2021
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
* fix: remove unused time column when update dataset

* fix lint

* set dttm to first datatime column
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
* fix: remove unused time column when update dataset

* fix lint

* set dttm to first datatime column
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
* fix: remove unused time column when update dataset

* fix lint

* set dttm to first datatime column
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
* fix: remove unused time column when update dataset

* fix lint

* set dttm to first datatime column
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.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 explore:dataset Related to the dataset of Explore size/S 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[explore]Can't remove unnecessary Datetime column from time filter
4 participants