fix: remove unused time column when update dataset (#14969)

* fix: remove unused time column when update dataset

* fix lint

* set dttm to first datatime column
This commit is contained in:
Yongjie Zhao 2021-07-28 14:40:16 +01:00 committed by GitHub
parent eda38a758e
commit 11b0249803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable camelcase */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -35,6 +36,7 @@ const propTypes = {
onChange: PropTypes.func,
value: PropTypes.string,
datasource: PropTypes.object.isRequired,
form_data: PropTypes.object.isRequired,
isEditable: PropTypes.bool,
onDatasourceSave: PropTypes.func,
};
@ -122,6 +124,19 @@ class DatasourceControl extends React.PureComponent {
onDatasourceSave(datasource) {
this.props.actions.setDatasource(datasource);
const timeCol = this.props.form_data?.granularity_sqla;
const { columns } = this.props.datasource;
const firstDttmCol = columns.find(column => column.is_dttm);
if (
datasource.type === 'table' &&
!columns.find(({ column_name }) => column_name === timeCol)?.is_dttm
) {
// set `granularity_sqla` to first datatime column name or null
this.props.actions.setControlValue(
'granularity_sqla',
firstDttmCol ? firstDttmCol.column_name : null,
);
}
if (this.props.onDatasourceSave) {
this.props.onDatasourceSave(datasource);
}
@ -211,9 +226,9 @@ class DatasourceControl extends React.PureComponent {
<Icons.AlertSolid iconColor={supersetTheme.colors.warning.base} />
</Tooltip>
)}
{extra?.warning_markdown && ( // eslint-disable-line camelcase
{extra?.warning_markdown && (
<WarningIconWithTooltip
warningMarkdown={extra.warning_markdown} // eslint-disable-line camelcase
warningMarkdown={extra.warning_markdown}
size={30}
/>
)}

View File

@ -1032,7 +1032,7 @@ class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-at
metrics = metrics or []
# For backward compatibility
if granularity not in self.dttm_cols:
if granularity not in self.dttm_cols and granularity is not None:
granularity = self.main_dttm_col
# Database spec supports join-free timeslot grouping