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
22 changes: 18 additions & 4 deletions web-console/src/utils/druid-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import axios from 'axios';
import { Api } from '../singletons';

import type { RowColumn } from './general';
import { assemble } from './general';
import { assemble, lookupBy } from './general';

const CANCELED_MESSAGE = 'Query canceled by user.';

Expand Down Expand Up @@ -345,10 +345,24 @@ export async function queryDruidSql<T = any>(
export interface QueryExplanation {
query: any;
signature: { name: string; type: string }[];
columnMappings: {
queryColumn: string;
outputColumn: string;
}[];
}

export function formatSignature(queryExplanation: QueryExplanation): string {
return queryExplanation.signature
.map(({ name, type }) => `${C.optionalQuotes(name)}::${type}`)
export function formatColumnMappingsAndSignature(queryExplanation: QueryExplanation): string {
const columnNameToType = lookupBy(
queryExplanation.signature,
c => c.name,
c => c.type,
);
return queryExplanation.columnMappings
.map(({ queryColumn, outputColumn }) => {
const type = columnNameToType[queryColumn];
return `${C.optionalQuotes(queryColumn)}${type ? `::${type}` : ''}→${C.optionalQuotes(
outputColumn,
)}`;
})
.join(', ');
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ exports[`ExplainDialog matches snapshot on some data (many queries) 1`] = `
label="Signature"
>
<Blueprint5.InputGroup
defaultValue="channel::STRING"
defaultValue="channel::STRING→channel"
readOnly={true}
/>
</Blueprint5.FormGroup>
Expand Down Expand Up @@ -287,7 +287,7 @@ exports[`ExplainDialog matches snapshot on some data (many queries) 1`] = `
label="Signature"
>
<Blueprint5.InputGroup
defaultValue="channel::STRING"
defaultValue="channel::STRING→channel"
readOnly={true}
/>
</Blueprint5.FormGroup>
Expand Down Expand Up @@ -473,7 +473,7 @@ exports[`ExplainDialog matches snapshot on some data (one query) 1`] = `
label="Signature"
>
<Blueprint5.InputGroup
defaultValue="d0::STRING, a0::LONG"
defaultValue="d0::STRING→channel, a0::LONG→"Count""
Comment thread
asdf2014 marked this conversation as resolved.
readOnly={true}
/>
</Blueprint5.FormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ describe('ExplainDialog', () => {
type: 'LONG',
},
],
columnMappings: [
{
queryColumn: 'd0',
outputColumn: 'channel',
},
{
queryColumn: 'a0',
outputColumn: 'Count',
},
],
},
],
});
Expand Down Expand Up @@ -199,6 +209,12 @@ describe('ExplainDialog', () => {
type: 'STRING',
},
],
columnMappings: [
{
queryColumn: 'channel',
outputColumn: 'channel',
},
],
},
{
query: {
Expand Down Expand Up @@ -234,6 +250,12 @@ describe('ExplainDialog', () => {
type: 'STRING',
},
],
columnMappings: [
{
queryColumn: 'channel',
outputColumn: 'channel',
},
],
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { Api } from '../../../singletons';
import type { QueryExplanation } from '../../../utils';
import {
deepGet,
formatSignature,
formatColumnMappingsAndSignature,
getDruidErrorMessage,
nonEmptyArray,
queryDruidSql,
Expand Down Expand Up @@ -141,7 +141,7 @@ export const ExplainDialog = React.memo(function ExplainDialog(props: ExplainDia
/>
</FormGroup>
<FormGroup className="signature-group" label="Signature">
<InputGroup defaultValue={formatSignature(queryExplanation)} readOnly />
<InputGroup defaultValue={formatColumnMappingsAndSignature(queryExplanation)} readOnly />
</FormGroup>
{openQueryLabel && (
<Button
Expand Down