Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const SegmentBarChart = function SegmentBarChart(props: SegmentBarChartPr
.addSelect(F.sum(C('num_rows')).as('rows'))
.toString();

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

Expand Down
10 changes: 6 additions & 4 deletions web-console/src/components/segment-timeline/segment-timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const SegmentTimeline = function SegmentTimeline(props: SegmentTimelinePr
const tables = await queryDruidSql<{ TABLE_NAME: string }>(
{
query: `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'`,
context: { engine: 'native' },
},
signal,
);
Expand Down Expand Up @@ -134,9 +135,10 @@ export const SegmentTimeline = function SegmentTimeline(props: SegmentTimelinePr
.addSelect(C('end'), { addToOrderBy: 'end', direction: 'DESC' })
.toString();

const endRes = await queryDruidSql<{ end: string }>({ query: endQuery }, signal).catch(
() => [],
);
const endRes = await queryDruidSql<{ end: string }>(
{ query: endQuery, context: { engine: 'native' } },
signal,
).catch(() => []);
if (endRes.length !== 1) {
return getDateRange(DEFAULT_SHOWN_DURATION);
}
Expand All @@ -153,7 +155,7 @@ export const SegmentTimeline = function SegmentTimeline(props: SegmentTimelinePr
.toString();

const startRes = await queryDruidSql<{ start: string }>(
{ query: startQuery },
{ query: startQuery, context: { engine: 'native' } },
signal,
).catch(() => []);
if (startRes.length !== 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const DatasourceColumnsTable = React.memo(function DatasourceColumnsTable
{
query: `SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'druid' AND TABLE_NAME = ${L(datasourceId)}`,
context: { engine: 'native' },
},
signal,
);
Expand Down
9 changes: 7 additions & 2 deletions web-console/src/dialogs/doctor-dialog/doctor-checks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,15 @@ export const DOCTOR_CHECKS: DoctorCheck[] = [
// Check SQL
// -------------------------------------
{
name: 'Verify that SQL works',
name: 'Verify that native SQL works',
check: async controls => {
// Make sure that we can run the simplest query
let sqlResult: any[];
try {
sqlResult = await queryDruidSql({ query: `SELECT 1 + 1 AS "two"` });
sqlResult = await queryDruidSql({
query: `SELECT 1 + 1 AS "two"`,
context: { engine: 'native' },
});
} catch (e) {
controls.addIssue(
`Could not query SQL ensure that "druid.sql.enable" is set to "true" and that there is a Broker service running. Got: ${e.message}`,
Expand All @@ -310,6 +313,7 @@ export const DOCTOR_CHECKS: DoctorCheck[] = [
FROM sys.servers
WHERE "server_type" = 'historical'
ORDER BY "fill" DESC`,
context: { engine: 'native' },
});
// 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
} catch (e) {
Expand Down Expand Up @@ -367,6 +371,7 @@ FROM (
)
GROUP BY 1
ORDER BY "num_bad_time_chunks"`,
context: { engine: 'native' },
});
} catch (e) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const LookupValuesTable = React.memo(function LookupValuesTable(
return await queryDruidSql<LookupRow>(
{
query: `SELECT "k", "v" FROM ${N('lookup').table(lookupId)} LIMIT 5000`,
context: { engine: 'native' },
},
signal,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ FROM "sys"."servers"
WHERE "server_type" = 'historical'
GROUP BY 1
ORDER BY 1`,
context: { engine: 'native' },
},
signal,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ describe('WorkbenchQuery', () => {
engine: 'sql-native',
query: {
context: {
engine: 'native',
sqlOuterLimit: 1001,
sqlQueryId: 'deadbeef-9fb0-499c-8475-ea461e96a4fd',
sqlStringifyArrays: false,
Expand Down Expand Up @@ -315,6 +316,7 @@ describe('WorkbenchQuery', () => {
engine: 'sql-native',
query: {
context: {
engine: 'native',
sqlOuterLimit: 1001,
sqlQueryId: 'lol',
sqlStringifyArrays: false,
Expand Down Expand Up @@ -354,6 +356,7 @@ describe('WorkbenchQuery', () => {
engine: 'sql-native',
query: {
context: {
engine: 'native',
sqlOuterLimit: 1001,
sqlQueryId: 'deadbeef-9fb0-499c-8475-ea461e96a4fd',
sqlStringifyArrays: false,
Expand Down Expand Up @@ -395,6 +398,7 @@ describe('WorkbenchQuery', () => {
engine: 'sql-native',
query: {
context: {
engine: 'native',
sqlOuterLimit: 1001,
sqlQueryId: 'lol',
sqlStringifyArrays: false,
Expand All @@ -410,6 +414,34 @@ describe('WorkbenchQuery', () => {
});
});

it('works with sql (preserves explicit engine context)', () => {
const sql = `SELECT * FROM wikipedia`;

const workbenchQuery = WorkbenchQuery.blank()
.changeQueryString(sql)
.changeQueryContext({ engine: 'msq-task' });

const apiQuery = workbenchQuery.getApiQuery(makeQueryId);
expect(apiQuery).toEqual({
cancelQueryId: 'deadbeef-9fb0-499c-8475-ea461e96a4fd',
engine: 'sql-native',
query: {
context: {
engine: 'msq-task',
sqlOuterLimit: 1001,
sqlQueryId: 'deadbeef-9fb0-499c-8475-ea461e96a4fd',
sqlStringifyArrays: false,
},
header: true,
query: 'SELECT * FROM wikipedia',
resultFormat: 'array',
sqlTypesHeader: true,
typesHeader: true,
},
prefixLines: 0,
});
});

it('works with sql-task (as SQL string)', () => {
const sql = `INSERT INTO wiki2 SELECT * FROM wikipedia`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ export class WorkbenchQuery {
...queryContext,
};

if (engine === 'sql-native') {
apiQuery.context.engine ??= 'native';
}

let cancelQueryId: string | undefined;
if (engine === 'sql-native' || engine === 'sql-msq-dart') {
cancelQueryId = apiQuery.context.sqlQueryId;
Expand Down
2 changes: 1 addition & 1 deletion web-console/src/helpers/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class Capabilities {
{
query: FUNCTION_SQL,
resultFormat: 'array',
context: { timeout: Capabilities.STATUS_TIMEOUT },
context: { engine: 'native', timeout: Capabilities.STATUS_TIMEOUT },
},
{ timeout: Capabilities.STATUS_TIMEOUT },
)
Expand Down
3 changes: 2 additions & 1 deletion web-console/src/views/datasources-view/datasources-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ GROUP BY 1, 2`;
if (capabilities.hasSql()) {
const query = DatasourcesView.query(visibleColumns);
setIntermediateQuery(query);
datasources = await queryDruidSql({ query }, signal);
datasources = await queryDruidSql({ query, context: { engine: 'native' } }, signal);
} else if (capabilities.hasCoordinatorAccess()) {
const datasourcesResp = await getApiArray(
'/druid/coordinator/v1/datasources?simple',
Expand Down Expand Up @@ -493,6 +493,7 @@ GROUP BY 1, 2`;
const runningTasks = await queryDruidSql<RunningTaskRow>(
{
query: DatasourcesView.RUNNING_TASK_SQL,
context: { engine: 'native' },
},
signal,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const SourcePane = React.memo(function SourcePane(props: SourcePaneProps)
processQuery: async () => {
const tables = await queryDruidSql<{ TABLE_NAME: string }>({
query: `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'`,
context: { engine: 'native' },
});

return tables.map(d => d.TABLE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const SourceQueryPane = React.memo(function SourceQueryPane(props: Source
processQuery: async () => {
return await queryDruidSql<ColumnMetadata>({
query: `SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS`,
context: { engine: 'native' },
});
},
});
Expand Down
1 change: 1 addition & 0 deletions web-console/src/views/explore-view/explore-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const ExploreView = React.memo(function ExploreView({ capabilities }: Exp
async function initializeWithFirstTable() {
const tables = await queryDruidSql<{ TABLE_NAME: string }>({
query: `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE' LIMIT 1`,
context: { engine: 'native' },
});

const firstTableName = tables[0].TABLE_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const DatasourcesCard = React.memo(function DatasourcesCard(props: Dataso
datasources = await queryDruidSql(
{
query: `SELECT datasource FROM sys.segments GROUP BY 1`,
context: { engine: 'native' },
},
signal,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const SegmentsCard = React.memo(function SegmentsCard(props: SegmentsCard
COUNT(*) FILTER (WHERE is_realtime = 1) AS "realtime"
FROM sys.segments
WHERE is_active = 1`,
context: { engine: 'native' },
},
signal,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const ServicesCard = React.memo(function ServicesCard(props: ServicesCard
}>(
{
query: `SELECT server_type AS "service_type", COUNT(*) as "count" FROM sys.servers GROUP BY 1`,
context: { engine: 'native' },
},
signal,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const SupervisorsCard = React.memo(function SupervisorsCard(props: Superv
COUNT(*) FILTER (WHERE "suspended" = 0) AS "running",
COUNT(*) FILTER (WHERE "suspended" = 1) AS "suspended"
FROM sys.supervisors`,
context: { engine: 'native' },
},
signal,
)
Expand Down
1 change: 1 addition & 0 deletions web-console/src/views/home-view/tasks-card/tasks-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function getTaskCounts(capabilities: Capabilities, signal: AbortSignal): P
COUNT(*) AS "count"
FROM sys.tasks
GROUP BY 1`,
context: { engine: 'native' },
},
signal,
);
Expand Down
7 changes: 5 additions & 2 deletions web-console/src/views/segments-view/segments-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment
const orderByClause = sortedToOrderByClause(effectiveSorted);

let queryParts: string[];
const sqlQueryContext: QueryContext = {};
const sqlQueryContext: QueryContext = { engine: 'native' };
if (groupByInterval) {
const innerQuery = compact([
`SELECT "start", "end"`,
Expand All @@ -352,7 +352,9 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment
page ? `OFFSET ${page * pageSize}` : undefined,
]).join('\n');

const intervals: string = (await queryDruidSql({ query: innerQuery }))
const intervals: string = (
await queryDruidSql({ query: innerQuery, context: { engine: 'native' } })
)
.map(({ start, end }) => `'${start}/${end}'`)
.join(', ');

Expand Down Expand Up @@ -403,6 +405,7 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment
await queryDruidSql<{ cnt: number }>(
{
query: sqlQuery,
context: { engine: 'native' },
},
signal,
)
Expand Down
5 changes: 4 additions & 1 deletion web-console/src/views/services-view/services-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ ORDER BY
processQuery: async ({ capabilities, visibleColumns }, signal) => {
let services: ServiceResultRow[];
if (capabilities.hasSql()) {
services = await queryDruidSql({ query: ServicesView.SERVICE_SQL }, signal);
services = await queryDruidSql(
{ query: ServicesView.SERVICE_SQL, context: { engine: 'native' } },
signal,
);
} else if (capabilities.hasCoordinatorAccess()) {
services = (await getApiArray('/druid/coordinator/v1/servers?simple', signal)).map(
(s: any): ServiceResultRow => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ export const SchemaStep = function SchemaStep(props: SchemaStepProps) {
{
query: `SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'druid' ORDER BY TABLE_NAME ASC`,
resultFormat: 'array',
context: { engine: 'native' },
},
signal,
);
Expand Down
2 changes: 2 additions & 0 deletions web-console/src/views/supervisors-view/supervisors-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export class SupervisorsView extends React.PureComponent<
await queryDruidSql<SupervisorQueryResultRow>(
{
query: sqlQuery,
context: { engine: 'native' },
},
signal,
)
Expand All @@ -336,6 +337,7 @@ export class SupervisorsView extends React.PureComponent<
await queryDruidSql<{ cnt: number }>(
{
query: sqlQuery,
context: { engine: 'native' },
},
signal,
)
Expand Down
1 change: 1 addition & 0 deletions web-console/src/views/tasks-view/tasks-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ ORDER BY
return await queryDruidSql(
{
query: TasksView.TASK_SQL,
context: { engine: 'native' },
},
signal,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ FROM sys.tasks
WHERE "type" = 'query_controller'
ORDER BY "created_time" DESC
LIMIT 100`,
context: { engine: 'native' },
},
signal,
);
Expand Down
1 change: 1 addition & 0 deletions web-console/src/views/workbench-view/workbench-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class WorkbenchView extends React.PureComponent<WorkbenchViewProps, Workb
return await queryDruidSql<ColumnMetadata>(
{
query: `SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS`,
context: { engine: 'native' },
},
signal,
);
Expand Down
Loading