This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 56397d7 fix: raise error in sqllab when using reserved column name
(#9859)
56397d7 is described below
commit 56397d75cc6192eeed7ed4d353629f8144de3df5
Author: Ville Brofeldt <[email protected]>
AuthorDate: Wed Jun 10 16:32:43 2020 +0300
fix: raise error in sqllab when using reserved column name (#9859)
---
.../spec/javascripts/sqllab/ExploreResultsButton_spec.jsx | 1 +
superset-frontend/spec/javascripts/sqllab/fixtures.js | 10 ++++++++++
.../src/SqlLab/components/ExploreResultsButton.jsx | 11 ++++++-----
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git
a/superset-frontend/spec/javascripts/sqllab/ExploreResultsButton_spec.jsx
b/superset-frontend/spec/javascripts/sqllab/ExploreResultsButton_spec.jsx
index ad6639b..f2e66b8 100644
--- a/superset-frontend/spec/javascripts/sqllab/ExploreResultsButton_spec.jsx
+++ b/superset-frontend/spec/javascripts/sqllab/ExploreResultsButton_spec.jsx
@@ -101,6 +101,7 @@ describe('ExploreResultsButton', () => {
'1',
'123',
'CASE WHEN 1=1 THEN 1 ELSE 0 END',
+ '__TIMESTAMP',
]);
const msgWrapper =
shallow(wrapper.instance().renderInvalidColumnMessage());
diff --git a/superset-frontend/spec/javascripts/sqllab/fixtures.js
b/superset-frontend/spec/javascripts/sqllab/fixtures.js
index 98bd202..a88f938 100644
--- a/superset-frontend/spec/javascripts/sqllab/fixtures.js
+++ b/superset-frontend/spec/javascripts/sqllab/fixtures.js
@@ -315,6 +315,16 @@ export const queryWithBadColumns = {
name: 'CASE WHEN 1=1 THEN 1 ELSE 0 END',
type: 'STRING',
},
+ {
+ is_date: true,
+ name: '_TIMESTAMP',
+ type: 'TIMESTAMP',
+ },
+ {
+ is_date: true,
+ name: '__TIMESTAMP',
+ type: 'TIMESTAMP',
+ },
],
},
};
diff --git a/superset-frontend/src/SqlLab/components/ExploreResultsButton.jsx
b/superset-frontend/src/SqlLab/components/ExploreResultsButton.jsx
index 37a46b3..2bdcdb0 100644
--- a/superset-frontend/src/SqlLab/components/ExploreResultsButton.jsx
+++ b/superset-frontend/src/SqlLab/components/ExploreResultsButton.jsx
@@ -104,10 +104,11 @@ class ExploreResultsButton extends React.PureComponent {
getInvalidColumns() {
const re1 = /^[A-Za-z_]\w*$/; // starts with char or _, then only alphanum
const re2 = /__\d+$/; // does not finish with __ and then a number which
screams dup col name
+ const re3 = /^__/; // is not a reserved column name e.g. __timestamp
return this.props.query.results.selected_columns
.map(col => col.name)
- .filter(col => !re1.test(col) || re2.test(col));
+ .filter(col => !re1.test(col) || re2.test(col) || re3.test(col));
}
datasourceName() {
const { query } = this.props;
@@ -194,13 +195,13 @@ class ExploreResultsButton extends React.PureComponent {
</code>
{t('cannot be used as a column name. Please use aliases (as in ')}
<code>
- SELECT count(*)
+ SELECT count(*)
<strong>AS my_alias</strong>
</code>
){' '}
- {t(`limited to alphanumeric characters and underscores. Column aliases
ending with
- double underscores followed by a numeric value are not allowed for
reasons
- discussed in Github issue #5739.
+ {t(`limited to alphanumeric characters and underscores. Column aliases
starting
+ with double underscores or ending with double underscores followed
by a
+ numeric value are not allowed for reasons discussed in Github issue
#5739.
`)}
</div>
);