fix ingest datasource detection falling over on paren (#15339)

This commit is contained in:
Vadim Ogievetsky 2023-11-08 13:32:27 -08:00 committed by GitHub
parent 130bfbfc6d
commit d12f557492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -487,6 +487,18 @@ describe('WorkbenchQuery', () => {
expect(workbenchQuery.changeEngine('sql-native').getIngestDatasource()).toBeUndefined(); expect(workbenchQuery.changeEngine('sql-native').getIngestDatasource()).toBeUndefined();
}); });
it('works with INSERT (unparsable with paren)', () => {
const sql = sane`
-- Some comment
INSERT into trips2
(SELECT TIME_PARSE(pickup_datetime) AS __time,
`;
const workbenchQuery = WorkbenchQuery.blank().changeQueryString(sql);
expect(workbenchQuery.getIngestDatasource()).toEqual('trips2');
expect(workbenchQuery.changeEngine('sql-native').getIngestDatasource()).toBeUndefined();
});
it('works with REPLACE', () => { it('works with REPLACE', () => {
const sql = sane` const sql = sane`
REPLACE INTO trips2 OVERWRITE ALL REPLACE INTO trips2 OVERWRITE ALL

View File

@ -226,7 +226,7 @@ export class WorkbenchQuery {
const queryStartingWithInsertOrReplace = queryFragment.substring(matchInsertReplaceIndex); const queryStartingWithInsertOrReplace = queryFragment.substring(matchInsertReplaceIndex);
const matchEnd = queryStartingWithInsertOrReplace.match(/\b(?:SELECT|WITH)\b|$/i); const matchEnd = queryStartingWithInsertOrReplace.match(/\(|\b(?:SELECT|WITH)\b|$/i);
const fragmentQuery = SqlQuery.maybeParse( const fragmentQuery = SqlQuery.maybeParse(
queryStartingWithInsertOrReplace.substring(0, matchEnd?.index) + ' SELECT * FROM t', queryStartingWithInsertOrReplace.substring(0, matchEnd?.index) + ' SELECT * FROM t',
); );