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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

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

View File

@ -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',
},
], ],
}, },
}; };

View File

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