fix: raise error in sqllab when using reserved column name (#9859)
This commit is contained in:
parent
a8db78b069
commit
56397d75cc
|
|
@ -101,6 +101,7 @@ describe('ExploreResultsButton', () => {
|
||||||
'1',
|
'1',
|
||||||
'123',
|
'123',
|
||||||
'CASE WHEN 1=1 THEN 1 ELSE 0 END',
|
'CASE WHEN 1=1 THEN 1 ELSE 0 END',
|
||||||
|
'__TIMESTAMP',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const msgWrapper = shallow(wrapper.instance().renderInvalidColumnMessage());
|
const msgWrapper = shallow(wrapper.instance().renderInvalidColumnMessage());
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,16 @@ export const queryWithBadColumns = {
|
||||||
name: 'CASE WHEN 1=1 THEN 1 ELSE 0 END',
|
name: 'CASE WHEN 1=1 THEN 1 ELSE 0 END',
|
||||||
type: 'STRING',
|
type: 'STRING',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
is_date: true,
|
||||||
|
name: '_TIMESTAMP',
|
||||||
|
type: 'TIMESTAMP',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
is_date: true,
|
||||||
|
name: '__TIMESTAMP',
|
||||||
|
type: 'TIMESTAMP',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -104,10 +104,11 @@ class ExploreResultsButton extends React.PureComponent {
|
||||||
getInvalidColumns() {
|
getInvalidColumns() {
|
||||||
const re1 = /^[A-Za-z_]\w*$/; // starts with char or _, then only alphanum
|
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 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
|
return this.props.query.results.selected_columns
|
||||||
.map(col => col.name)
|
.map(col => col.name)
|
||||||
.filter(col => !re1.test(col) || re2.test(col));
|
.filter(col => !re1.test(col) || re2.test(col) || re3.test(col));
|
||||||
}
|
}
|
||||||
datasourceName() {
|
datasourceName() {
|
||||||
const { query } = this.props;
|
const { query } = this.props;
|
||||||
|
|
@ -194,13 +195,13 @@ class ExploreResultsButton extends React.PureComponent {
|
||||||
</code>
|
</code>
|
||||||
{t('cannot be used as a column name. Please use aliases (as in ')}
|
{t('cannot be used as a column name. Please use aliases (as in ')}
|
||||||
<code>
|
<code>
|
||||||
SELECT count(*)
|
SELECT count(*)
|
||||||
<strong>AS my_alias</strong>
|
<strong>AS my_alias</strong>
|
||||||
</code>
|
</code>
|
||||||
){' '}
|
){' '}
|
||||||
{t(`limited to alphanumeric characters and underscores. Column aliases ending with
|
{t(`limited to alphanumeric characters and underscores. Column aliases starting
|
||||||
double underscores followed by a numeric value are not allowed for reasons
|
with double underscores or ending with double underscores followed by a
|
||||||
discussed in Github issue #5739.
|
numeric value are not allowed for reasons discussed in Github issue #5739.
|
||||||
`)}
|
`)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue