diff --git a/web-console/src/druid-models/workbench-query/workbench-query.spec.ts b/web-console/src/druid-models/workbench-query/workbench-query.spec.ts index 78ac3e8f1e74..36c108d7e5f3 100644 --- a/web-console/src/druid-models/workbench-query/workbench-query.spec.ts +++ b/web-console/src/druid-models/workbench-query/workbench-query.spec.ts @@ -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 diff --git a/web-console/src/druid-models/workbench-query/workbench-query.ts b/web-console/src/druid-models/workbench-query/workbench-query.ts index 621e5028f4b3..0c7775e515fc 100644 --- a/web-console/src/druid-models/workbench-query/workbench-query.ts +++ b/web-console/src/druid-models/workbench-query/workbench-query.ts @@ -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', );