diff --git a/web-console/package-lock.json b/web-console/package-lock.json index 437f665fe03..787f6c7e0fb 100644 --- a/web-console/package-lock.json +++ b/web-console/package-lock.json @@ -4395,9 +4395,9 @@ "integrity": "sha512-0sYnfUHHMoajaud/i5BHKA12bUxiWEHJ9rxGqVEppFxsEcxef0TZQ5J59lU+UniEBcz/sG5fTESRyS7cOm3tSQ==" }, "druid-query-toolkit": { - "version": "0.3.12", - "resolved": "https://registry.npmjs.org/druid-query-toolkit/-/druid-query-toolkit-0.3.12.tgz", - "integrity": "sha512-q2w6dDdZFYuLRTVyUvZwyXx/63ZQivjhll3Ppo3zpRcF4iWg+z+sXY9UI+sobl5q3/WojOkw/ZI0Kwzy9bWd2Q==", + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/druid-query-toolkit/-/druid-query-toolkit-0.3.13.tgz", + "integrity": "sha512-yBPAJ0tjbV/2X1tgvByx53bnoOizMQet4mhUv43Zlx0ongS7Hj7na/6E1iISmPVKOPbJd38DfvIf7yr50BkYsw==", "requires": { "tslib": "^1.10.0" } diff --git a/web-console/package.json b/web-console/package.json index 1080e5de0f6..66d3c976caf 100644 --- a/web-console/package.json +++ b/web-console/package.json @@ -61,7 +61,7 @@ "d3": "^5.9.7", "d3-array": "^2.2.0", "druid-console": "^0.0.2", - "druid-query-toolkit": "^0.3.12", + "druid-query-toolkit": "^0.3.13", "file-saver": "^2.0.2", "has-own-prop": "^2.0.0", "hjson": "^3.1.2", diff --git a/web-console/src/views/query-view/__snapshots__/query-view.spec.tsx.snap b/web-console/src/views/query-view/__snapshots__/query-view.spec.tsx.snap index 1efef33ab6f..4bc32b5b7d9 100644 --- a/web-console/src/views/query-view/__snapshots__/query-view.spec.tsx.snap +++ b/web-console/src/views/query-view/__snapshots__/query-view.spec.tsx.snap @@ -44,6 +44,7 @@ exports[`sql view matches snapshot 1`] = ` escapeSqlIdentifier(String(child.label))); - } else { - columns = ['*']; - } - if (tableSchema === 'druid') { - return `SELECT ${columns.join(', ')} -FROM ${escapeSqlIdentifier(String(nodeData.label))} -WHERE "__time" >= CURRENT_TIMESTAMP - INTERVAL '1' DAY`; - } else { - return `SELECT ${columns.join(', ')} -FROM ${tableSchema}.${nodeData.label}`; - } -} - function handleColumnClick( columnSchema: string, columnTable: string, @@ -99,35 +82,6 @@ ORDER BY "Count" DESC`); } } -function getColumnQuery(columnSchema: string, columnTable: string, nodeData: ITreeNode): string { - if (columnSchema === 'druid') { - if (nodeData.icon === IconNames.TIME) { - return `SELECT - TIME_FLOOR(${escapeSqlIdentifier(String(nodeData.label))}, 'PT1H') AS "Time", - COUNT(*) AS "Count" -FROM ${escapeSqlIdentifier(columnTable)} -WHERE "__time" >= CURRENT_TIMESTAMP - INTERVAL '1' DAY -GROUP BY 1 -ORDER BY "Time" ASC`; - } else { - return `SELECT - "${nodeData.label}", - COUNT(*) AS "Count" -FROM ${escapeSqlIdentifier(columnTable)} -WHERE "__time" >= CURRENT_TIMESTAMP - INTERVAL '1' DAY -GROUP BY 1 -ORDER BY "Count" DESC`; - } - } else { - return `SELECT - ${escapeSqlIdentifier(String(nodeData.label))}, - COUNT(*) AS "Count" -FROM ${columnSchema}.${columnTable} -GROUP BY 1 -ORDER BY "Count" DESC`; - } -} - export interface ColumnTreeProps { columnMetadataLoading: boolean; columnMetadata?: ColumnMetadata[]; @@ -190,19 +144,7 @@ export class ColumnTree extends React.PureComponent { - copyAndAlert( - getTableQuery(schema, { - id: table, - icon: IconNames.TH, - label: table, - childNodes: metadata.map(columnData => ({ - id: columnData.COLUMN_NAME, - icon: ColumnTree.dataTypeToIcon(columnData.DATA_TYPE), - label: columnData.COLUMN_NAME, - })), - }), - `${table} query copied to clipboard`, - ); + copyAndAlert(table, `${table} query copied to clipboard`); }} /> @@ -241,11 +183,7 @@ export class ColumnTree extends React.PureComponent { copyAndAlert( - getColumnQuery(schema, table, { - id: columnData.COLUMN_NAME, - icon: ColumnTree.dataTypeToIcon(columnData.DATA_TYPE), - label: columnData.COLUMN_NAME, - }), + columnData.COLUMN_NAME, `${columnData.COLUMN_NAME} query copied to clipboard`, ); }} diff --git a/web-console/src/views/query-view/query-output/query-output.spec.tsx b/web-console/src/views/query-view/query-output/query-output.spec.tsx index 1fd30c3bd06..e56b1d1d052 100644 --- a/web-console/src/views/query-view/query-output/query-output.spec.tsx +++ b/web-console/src/views/query-view/query-output/query-output.spec.tsx @@ -25,6 +25,7 @@ describe('query output', () => { it('matches snapshot', () => { const queryOutput = ( null} sqlFilterRow={() => null} sqlExcludeColumn={() => null} diff --git a/web-console/src/views/query-view/query-output/query-output.tsx b/web-console/src/views/query-view/query-output/query-output.tsx index 059539b7a9d..9a3f4ea142a 100644 --- a/web-console/src/views/query-view/query-output/query-output.tsx +++ b/web-console/src/views/query-view/query-output/query-output.tsx @@ -16,7 +16,7 @@ * limitations under the License. */ -import { Popover } from '@blueprintjs/core'; +import { Menu, MenuItem, Popover } from '@blueprintjs/core'; import { IconNames } from '@blueprintjs/icons'; import { HeaderRows } from 'druid-query-toolkit'; import { @@ -41,6 +41,7 @@ export interface QueryOutputProps { sorted?: { id: string; desc: boolean }[]; result?: HeaderRows; error?: string; + runeMode: boolean; } export class QueryOutput extends React.PureComponent { @@ -91,38 +92,44 @@ export class QueryOutput extends React.PureComponent { ); } getHeaderActions(h: string) { - const { disabled, sqlExcludeColumn, sqlOrderBy } = this.props; + const { disabled, sqlExcludeColumn, sqlOrderBy, runeMode } = this.props; let actionsMenu; if (disabled) { - actionsMenu = basicActionsToMenu([ - { - icon: IconNames.CLIPBOARD, - title: `Copy: ${h}`, - onAction: () => { - copyAndAlert(h, `${h}' copied to clipboard`); - }, - }, - { - icon: IconNames.CLIPBOARD, - title: `Copy: ORDER BY ${basicIdentifierEscape(h)} ASC`, - onAction: () => { - copyAndAlert( - `ORDER BY ${basicIdentifierEscape(h)} ASC`, - `ORDER BY ${basicIdentifierEscape(h)} ASC' copied to clipboard`, - ); - }, - }, - { - icon: IconNames.CLIPBOARD, - title: `Copy: 'ORDER BY ${basicIdentifierEscape(h)} DESC'`, - onAction: () => { - copyAndAlert( - `ORDER BY ${basicIdentifierEscape(h)} DESC`, - `ORDER BY ${basicIdentifierEscape(h)} DESC' copied to clipboard`, - ); - }, - }, - ]); + actionsMenu = ( + + { + copyAndAlert(h, `${h}' copied to clipboard`); + }} + /> + {runeMode && ( + + copyAndAlert( + `ORDER BY ${basicIdentifierEscape(h)} ASC`, + `ORDER BY ${basicIdentifierEscape(h)} ASC' copied to clipboard`, + ) + } + /> + )} + {runeMode && ( + + copyAndAlert( + `ORDER BY ${basicIdentifierEscape(h)} DESC`, + `ORDER BY ${basicIdentifierEscape(h)} DESC' copied to clipboard`, + ) + } + /> + )} + + ); } else { const { sorted } = this.props; const basicActions: BasicAction[] = []; @@ -162,38 +169,46 @@ export class QueryOutput extends React.PureComponent { } getRowActions(row: string, header: string) { - const { disabled, sqlFilterRow } = this.props; + const { disabled, sqlFilterRow, runeMode } = this.props; let actionsMenu; if (disabled) { - actionsMenu = basicActionsToMenu([ - { - icon: IconNames.CLIPBOARD, - title: `Copy: '${row}'`, - onAction: () => { - copyAndAlert(row, `${row} copied to clipboard`); - }, - }, - { - icon: IconNames.CLIPBOARD, - title: `Copy: ${basicIdentifierEscape(header)} = ${basicLiteralEscape(row)}`, - onAction: () => { - copyAndAlert( - `${basicIdentifierEscape(header)} = ${basicLiteralEscape(row)}`, - `${basicIdentifierEscape(header)} = ${basicLiteralEscape(row)} copied to clipboard`, - ); - }, - }, - { - icon: IconNames.CLIPBOARD, - title: `Copy: ${basicIdentifierEscape(header)} != ${basicLiteralEscape(row)}`, - onAction: () => { - copyAndAlert( - `${basicIdentifierEscape(header)} != ${basicLiteralEscape(row)}`, - `${basicIdentifierEscape(header)} != ${basicLiteralEscape(row)} copied to clipboard`, - ); - }, - }, - ]); + actionsMenu = ( + + copyAndAlert(row, `${row} copied to clipboard`)} + /> + {runeMode && ( + + copyAndAlert( + `${basicIdentifierEscape(header)} = ${basicLiteralEscape(row)}`, + `${basicIdentifierEscape(header)} = ${basicLiteralEscape( + row, + )} copied to clipboard`, + ) + } + /> + )} + {runeMode && ( + + copyAndAlert( + `${basicIdentifierEscape(header)} != ${basicLiteralEscape(row)}`, + `${basicIdentifierEscape(header)} != ${basicLiteralEscape( + row, + )} copied to clipboard`, + ) + } + /> + )} + + ); } else { actionsMenu = basicActionsToMenu([ { diff --git a/web-console/src/views/query-view/query-view.tsx b/web-console/src/views/query-view/query-view.tsx index bec17b573b4..68aa550424e 100644 --- a/web-console/src/views/query-view/query-view.tsx +++ b/web-console/src/views/query-view/query-view.tsx @@ -418,6 +418,7 @@ export class QueryView extends React.PureComponent