This is an automated email from the ASF dual-hosted git repository. vogievetsky pushed a commit to branch segment_timeline2 in repository https://gitbox.apache.org/repos/asf/druid.git
commit 883e0f9a7c276b8ec61d764bdd4691d12fc65517 Author: Vadim Ogievetsky <[email protected]> AuthorDate: Fri Nov 1 15:03:59 2024 -0700 segment wheel fixes --- web-console/src/druid-models/segment/segment.ts | 10 +++ .../src/views/segments-view/segments-view.tsx | 80 ++++++++++++++-------- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/web-console/src/druid-models/segment/segment.ts b/web-console/src/druid-models/segment/segment.ts index 3860d4f5127..1bff0711fcd 100644 --- a/web-console/src/druid-models/segment/segment.ts +++ b/web-console/src/druid-models/segment/segment.ts @@ -38,3 +38,13 @@ export function computeSegmentTimeSpan(start: string, end: string): string { return Duration.fromRange(startDate, endDate, 'Etc/UTC').getDescription(true); } + +export interface ShardSpec { + type: string; + partitionNum?: number; + partitions?: number; + dimensions?: string[]; + partitionDimensions?: string[]; + start?: string[]; + end?: string[]; +} diff --git a/web-console/src/views/segments-view/segments-view.tsx b/web-console/src/views/segments-view/segments-view.tsx index 90cb9311391..8f9aeb5abd4 100644 --- a/web-console/src/views/segments-view/segments-view.tsx +++ b/web-console/src/views/segments-view/segments-view.tsx @@ -44,7 +44,7 @@ import { import { AsyncActionDialog } from '../../dialogs'; import { SegmentTableActionDialog } from '../../dialogs/segments-table-action-dialog/segment-table-action-dialog'; import { ShowValueDialog } from '../../dialogs/show-value-dialog/show-value-dialog'; -import type { QueryWithContext } from '../../druid-models'; +import type { QueryWithContext, ShardSpec } from '../../druid-models'; import { computeSegmentTimeSpan, getDatasourceColor } from '../../druid-models'; import type { Capabilities, CapabilitiesMode } from '../../helpers'; import { @@ -101,7 +101,6 @@ const TABLE_COLUMNS_BY_MODE: Record<CapabilitiesMode, TableColumnSelectorColumn[ 'Is published', 'Is overshadowed', ], - 'no-sql': ['Segment ID', 'Datasource', 'Start', 'End', 'Version', 'Partition', 'Size'], 'no-proxy': [ 'Segment ID', 'Datasource', @@ -123,8 +122,28 @@ const TABLE_COLUMNS_BY_MODE: Record<CapabilitiesMode, TableColumnSelectorColumn[ 'Is published', 'Is overshadowed', ], + 'no-sql': [ + 'Segment ID', + 'Datasource', + 'Start', + 'End', + 'Version', + 'Time span', + 'Shard type', + 'Shard spec', + 'Partition', + 'Size', + ], }; +function maybeParseJsonBig(str: string): any { + try { + return JSONBig.parse(str); + } catch { + return undefined; + } +} + function formatRangeDimensionValue(dimension: any, value: any): string { return `${C(String(dimension))}=${L(String(value))}`; } @@ -179,7 +198,7 @@ interface SegmentQueryResultRow { interval: string; segment_id: string; version: string; - shard_spec: string; + shard_spec: ShardSpec; partition_num: number; size: number; num_rows: NumberLike; @@ -335,7 +354,16 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment } const sqlQuery = queryParts.join('\n'); setIntermediateQuery(sqlQuery); - return await queryDruidSql({ query: sqlQuery }, cancelToken); + let result = await queryDruidSql({ query: sqlQuery }, cancelToken); + + if (visibleColumns.shown('Shard type', 'Shard spec')) { + result = result.map(sr => ({ + ...sr, + shard_spec: maybeParseJsonBig(sr.shard_spec), + })); + } + + return result as SegmentQueryResultRow[]; } else if (capabilities.hasCoordinatorAccess()) { let datasourceList: string[] = ( await Api.instance.get('/druid/coordinator/v1/metadata/datasources', { cancelToken }) @@ -350,7 +378,7 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment if (sorted.length && sorted[0].id === 'datasource') { datasourceList.sort( - sorted[0].desc ? (d1, d2) => d1.localeCompare(d2) : (d1, d2) => d2.localeCompare(d1), + sorted[0].desc ? (d1, d2) => d2.localeCompare(d1) : (d1, d2) => d1.localeCompare(d2), ); } @@ -643,14 +671,9 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment id: 'shard_type', width: 100, sortable: false, - accessor: d => { - let v: any; - try { - v = JSONBig.parse(d.shard_spec); - } catch {} - - if (typeof v?.type !== 'string') return '-'; - return v?.type; + accessor: ({ shard_spec }) => { + if (typeof shard_spec?.type !== 'string') return '-'; + return shard_spec?.type; }, Cell: this.renderFilterableCell('shard_type', true), }, @@ -663,21 +686,18 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment sortable: false, filterable: false, Cell: ({ value }) => { - let v: any; - try { - v = JSONBig.parse(value); - } catch {} - const onShowFullShardSpec = () => { this.setState({ showFullShardSpec: - v && typeof v === 'object' ? JSONBig.stringify(v, undefined, 2) : String(value), + value && typeof value === 'object' + ? JSONBig.stringify(value, undefined, 2) + : String(value), }); }; - switch (v?.type) { + switch (value?.type) { case 'range': { - const dimensions: string[] = v.dimensions || []; + const dimensions: string[] = value.dimensions || []; const formatEdge = (values: string[]) => dimensions.map((d, i) => formatRangeDimensionValue(d, values[i])).join('; '); @@ -688,10 +708,10 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment hoverIcon={IconNames.EYE_OPEN} > <span className="range-label">Start:</span> - {Array.isArray(v.start) ? formatEdge(v.start) : '-∞'} + {Array.isArray(value.start) ? formatEdge(value.start) : '-∞'} <br /> <span className="range-label">End:</span> - {Array.isArray(v.end) ? formatEdge(v.end) : '∞'} + {Array.isArray(value.end) ? formatEdge(value.end) : '∞'} </TableClickableCell> ); } @@ -704,17 +724,21 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment hoverIcon={IconNames.EYE_OPEN} > <span className="range-label">Start:</span> - {v.start != null ? formatRangeDimensionValue(v.dimension, v.start) : '-∞'} + {value.start != null + ? formatRangeDimensionValue(value.dimension, value.start) + : '-∞'} <br /> <span className="range-label">End:</span> - {v.end != null ? formatRangeDimensionValue(v.dimension, v.end) : '∞'} + {value.end != null + ? formatRangeDimensionValue(value.dimension, value.end) + : '∞'} </TableClickableCell> ); } case 'hashed': { - const { partitionDimensions } = v; - if (!Array.isArray(partitionDimensions)) return value; + const { partitionDimensions } = value; + if (!Array.isArray(partitionDimensions)) return JSONBig.stringify(value); return ( <TableClickableCell onClick={onShowFullShardSpec} @@ -747,7 +771,7 @@ export class SegmentsView extends React.PureComponent<SegmentsViewProps, Segment onClick={onShowFullShardSpec} hoverIcon={IconNames.EYE_OPEN} > - {String(value)} + {JSONBig.stringify(value)} </TableClickableCell> ); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
