Skip to content

Commit 86aa058

Browse files
authored
Web console: explicitly set engine: 'native' for system table queries (#18857)
1 parent 35ec60d commit 86aa058

File tree

25 files changed

+79
-12
lines changed

25 files changed

+79
-12
lines changed

web-console/src/components/segment-timeline/segment-bar-chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const SegmentBarChart = function SegmentBarChart(props: SegmentBarChartPr
7272
.addSelect(F.sum(C('num_rows')).as('rows'))
7373
.toString();
7474

75-
return (await queryDruidSql({ query }, signal)).map(sr => {
75+
return (await queryDruidSql({ query, context: { engine: 'native' } }, signal)).map(sr => {
7676
const start = new Date(sr.start);
7777
const end = new Date(sr.end);
7878

web-console/src/components/segment-timeline/segment-timeline.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const SegmentTimeline = function SegmentTimeline(props: SegmentTimelinePr
102102
const tables = await queryDruidSql<{ TABLE_NAME: string }>(
103103
{
104104
query: `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'`,
105+
context: { engine: 'native' },
105106
},
106107
signal,
107108
);
@@ -134,9 +135,10 @@ export const SegmentTimeline = function SegmentTimeline(props: SegmentTimelinePr
134135
.addSelect(C('end'), { addToOrderBy: 'end', direction: 'DESC' })
135136
.toString();
136137

137-
const endRes = await queryDruidSql<{ end: string }>({ query: endQuery }, signal).catch(
138-
() => [],
139-
);
138+
const endRes = await queryDruidSql<{ end: string }>(
139+
{ query: endQuery, context: { engine: 'native' } },
140+
signal,
141+
).catch(() => []);
140142
if (endRes.length !== 1) {
141143
return getDateRange(DEFAULT_SHOWN_DURATION);
142144
}
@@ -153,7 +155,7 @@ export const SegmentTimeline = function SegmentTimeline(props: SegmentTimelinePr
153155
.toString();
154156

155157
const startRes = await queryDruidSql<{ start: string }>(
156-
{ query: startQuery },
158+
{ query: startQuery, context: { engine: 'native' } },
157159
signal,
158160
).catch(() => []);
159161
if (startRes.length !== 1) {

web-console/src/dialogs/datasource-table-action-dialog/datasource-columns-table/datasource-columns-table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const DatasourceColumnsTable = React.memo(function DatasourceColumnsTable
4747
{
4848
query: `SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS
4949
WHERE TABLE_SCHEMA = 'druid' AND TABLE_NAME = ${L(datasourceId)}`,
50+
context: { engine: 'native' },
5051
},
5152
signal,
5253
);

web-console/src/dialogs/doctor-dialog/doctor-checks.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,15 @@ export const DOCTOR_CHECKS: DoctorCheck[] = [
278278
// Check SQL
279279
// -------------------------------------
280280
{
281-
name: 'Verify that SQL works',
281+
name: 'Verify that native SQL works',
282282
check: async controls => {
283283
// Make sure that we can run the simplest query
284284
let sqlResult: any[];
285285
try {
286-
sqlResult = await queryDruidSql({ query: `SELECT 1 + 1 AS "two"` });
286+
sqlResult = await queryDruidSql({
287+
query: `SELECT 1 + 1 AS "two"`,
288+
context: { engine: 'native' },
289+
});
287290
} catch (e) {
288291
controls.addIssue(
289292
`Could not query SQL ensure that "druid.sql.enable" is set to "true" and that there is a Broker service running. Got: ${e.message}`,
@@ -310,6 +313,7 @@ export const DOCTOR_CHECKS: DoctorCheck[] = [
310313
FROM sys.servers
311314
WHERE "server_type" = 'historical'
312315
ORDER BY "fill" DESC`,
316+
context: { engine: 'native' },
313317
});
314318
// Note: for some reason adding ` AND "curr_size" * 100.0 / "max_size" > 90` to the filter does not work as of this writing Apr 8, 2024
315319
} catch (e) {
@@ -367,6 +371,7 @@ FROM (
367371
)
368372
GROUP BY 1
369373
ORDER BY "num_bad_time_chunks"`,
374+
context: { engine: 'native' },
370375
});
371376
} catch (e) {
372377
return;

web-console/src/dialogs/lookup-table-action-dialog/lookup-values-table/lookup-values-table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const LookupValuesTable = React.memo(function LookupValuesTable(
4545
return await queryDruidSql<LookupRow>(
4646
{
4747
query: `SELECT "k", "v" FROM ${N('lookup').table(lookupId)} LIMIT 5000`,
48+
context: { engine: 'native' },
4849
},
4950
signal,
5051
);

web-console/src/dialogs/retention-dialog/retention-dialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ FROM "sys"."servers"
6363
WHERE "server_type" = 'historical'
6464
GROUP BY 1
6565
ORDER BY 1`,
66+
context: { engine: 'native' },
6667
},
6768
signal,
6869
);

web-console/src/druid-models/workbench-query/workbench-query.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ describe('WorkbenchQuery', () => {
287287
engine: 'sql-native',
288288
query: {
289289
context: {
290+
engine: 'native',
290291
sqlOuterLimit: 1001,
291292
sqlQueryId: 'deadbeef-9fb0-499c-8475-ea461e96a4fd',
292293
sqlStringifyArrays: false,
@@ -315,6 +316,7 @@ describe('WorkbenchQuery', () => {
315316
engine: 'sql-native',
316317
query: {
317318
context: {
319+
engine: 'native',
318320
sqlOuterLimit: 1001,
319321
sqlQueryId: 'lol',
320322
sqlStringifyArrays: false,
@@ -354,6 +356,7 @@ describe('WorkbenchQuery', () => {
354356
engine: 'sql-native',
355357
query: {
356358
context: {
359+
engine: 'native',
357360
sqlOuterLimit: 1001,
358361
sqlQueryId: 'deadbeef-9fb0-499c-8475-ea461e96a4fd',
359362
sqlStringifyArrays: false,
@@ -395,6 +398,7 @@ describe('WorkbenchQuery', () => {
395398
engine: 'sql-native',
396399
query: {
397400
context: {
401+
engine: 'native',
398402
sqlOuterLimit: 1001,
399403
sqlQueryId: 'lol',
400404
sqlStringifyArrays: false,
@@ -410,6 +414,34 @@ describe('WorkbenchQuery', () => {
410414
});
411415
});
412416

417+
it('works with sql (preserves explicit engine context)', () => {
418+
const sql = `SELECT * FROM wikipedia`;
419+
420+
const workbenchQuery = WorkbenchQuery.blank()
421+
.changeQueryString(sql)
422+
.changeQueryContext({ engine: 'msq-task' });
423+
424+
const apiQuery = workbenchQuery.getApiQuery(makeQueryId);
425+
expect(apiQuery).toEqual({
426+
cancelQueryId: 'deadbeef-9fb0-499c-8475-ea461e96a4fd',
427+
engine: 'sql-native',
428+
query: {
429+
context: {
430+
engine: 'msq-task',
431+
sqlOuterLimit: 1001,
432+
sqlQueryId: 'deadbeef-9fb0-499c-8475-ea461e96a4fd',
433+
sqlStringifyArrays: false,
434+
},
435+
header: true,
436+
query: 'SELECT * FROM wikipedia',
437+
resultFormat: 'array',
438+
sqlTypesHeader: true,
439+
typesHeader: true,
440+
},
441+
prefixLines: 0,
442+
});
443+
});
444+
413445
it('works with sql-task (as SQL string)', () => {
414446
const sql = `INSERT INTO wiki2 SELECT * FROM wikipedia`;
415447

web-console/src/druid-models/workbench-query/workbench-query.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ export class WorkbenchQuery {
552552
...queryContext,
553553
};
554554

555+
if (engine === 'sql-native') {
556+
apiQuery.context.engine ??= 'native';
557+
}
558+
555559
let cancelQueryId: string | undefined;
556560
if (engine === 'sql-native' || engine === 'sql-msq-dart') {
557561
cancelQueryId = apiQuery.context.sqlQueryId;

web-console/src/helpers/capabilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class Capabilities {
233233
{
234234
query: FUNCTION_SQL,
235235
resultFormat: 'array',
236-
context: { timeout: Capabilities.STATUS_TIMEOUT },
236+
context: { engine: 'native', timeout: Capabilities.STATUS_TIMEOUT },
237237
},
238238
{ timeout: Capabilities.STATUS_TIMEOUT },
239239
)

web-console/src/views/datasources-view/datasources-view.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ GROUP BY 1, 2`;
441441
if (capabilities.hasSql()) {
442442
const query = DatasourcesView.query(visibleColumns);
443443
setIntermediateQuery(query);
444-
datasources = await queryDruidSql({ query }, signal);
444+
datasources = await queryDruidSql({ query, context: { engine: 'native' } }, signal);
445445
} else if (capabilities.hasCoordinatorAccess()) {
446446
const datasourcesResp = await getApiArray(
447447
'/druid/coordinator/v1/datasources?simple',
@@ -493,6 +493,7 @@ GROUP BY 1, 2`;
493493
const runningTasks = await queryDruidSql<RunningTaskRow>(
494494
{
495495
query: DatasourcesView.RUNNING_TASK_SQL,
496+
context: { engine: 'native' },
496497
},
497498
signal,
498499
);

0 commit comments

Comments
 (0)