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',
|
||||
'123',
|
||||
'CASE WHEN 1=1 THEN 1 ELSE 0 END',
|
||||
'__TIMESTAMP',
|
||||
]);
|
||||
|
||||
const msgWrapper = shallow(wrapper.instance().renderInvalidColumnMessage());
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue