fix: raise error in sqllab when using reserved column name (#9859)

This commit is contained in:
Ville Brofeldt
2020-06-10 16:32:43 +03:00
committed by GitHub
parent a8db78b069
commit 56397d75cc
3 changed files with 17 additions and 5 deletions

View File

@@ -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(*)&nbsp;
<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>
);