Skip to content

Commit

Permalink
fix ingest datasource detection falling over on paren (#15339)
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky authored Nov 8, 2023
1 parent 130bfbf commit d12f557
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ describe('WorkbenchQuery', () => {
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', () => {
const sql = sane`
REPLACE INTO trips2 OVERWRITE ALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class WorkbenchQuery {

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(
queryStartingWithInsertOrReplace.substring(0, matchEnd?.index) + ' SELECT * FROM t',
);
Expand Down

0 comments on commit d12f557

Please sign in to comment.