Skip to content

Commit dbdce22

Browse files
committed
fix: move speed metrics to result sets
1 parent 083b977 commit dbdce22

File tree

6 files changed

+32
-37
lines changed

6 files changed

+32
-37
lines changed

src/containers/Tenant/Query/QueryResult/QueryResultViewer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function QueryResultViewer({
114114
});
115115
const [useShowPlanToSvg] = useSetting<boolean>(USE_SHOW_PLAN_SVG_KEY);
116116

117-
const {error, isLoading, data = {}, speedMetrics} = result;
117+
const {error, isLoading, data = {}} = result;
118118
const {preparedPlan, simplifiedPlan, stats, resultSets, ast} = data;
119119

120120
React.useEffect(() => {
@@ -227,7 +227,6 @@ export function QueryResultViewer({
227227
if (activeSection === RESULT_OPTIONS_IDS.result) {
228228
return (
229229
<ResultSetsViewer
230-
rowsPerSecond={speedMetrics?.rowsPerSecond}
231230
resultSets={resultSets}
232231
selectedResultSet={selectedResultSet}
233232
errorHeader={<QueryResultError error={error} />}

src/containers/Tenant/Query/QueryResult/components/ResultSetsViewer/ResultSetsViewer.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import './ResultSetsViewer.scss';
1111
const b = cn('ydb-query-result-sets-viewer');
1212

1313
interface ResultSetsViewerProps {
14-
rowsPerSecond?: number;
1514
resultSets?: ParsedResultSet[];
1615
selectedResultSet: number;
1716
errorHeader?: React.ReactNode;
@@ -54,18 +53,13 @@ export function ResultSetsViewer(props: ResultSetsViewerProps) {
5453
{currentResult?.truncated ? i18n('title.truncated') : i18n('title.result')}
5554
</Text>
5655
{currentResult?.result ? (
57-
<Text
58-
color="secondary"
59-
variant="body-2"
60-
className={b('row-count')}
61-
>{`(${currentResult?.result.length})`}</Text>
62-
) : null}
63-
{props.rowsPerSecond ? (
64-
<Text
65-
color="secondary"
66-
variant="body-2"
67-
className={b('row-count')}
68-
>{`(${props.rowsPerSecond.toFixed(0)} rows/s)`}</Text>
56+
<Text color="secondary" variant="body-2" className={b('row-count')}>
57+
{`(${currentResult?.result.length}${
58+
currentResult.speedMetrics?.rowsPerSecond
59+
? `, ${currentResult.speedMetrics.rowsPerSecond.toFixed(0)} rows/s`
60+
: ''
61+
})`}
62+
</Text>
6963
) : null}
7064
</div>
7165
);

src/services/api/streaming.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export class StreamingAPI extends BaseYdbAPI {
4545
true,
4646
);
4747

48-
const queryParams = qs.stringify({...params, base64}, {encoder: encodeURIComponent});
48+
const queryParams = qs.stringify(
49+
{...params, base64, schema: 'multipart'},
50+
{encoder: encodeURIComponent},
51+
);
4952

5053
const headers = new Headers({
5154
Accept: 'multipart/x-mixed-replace',

src/store/reducers/query/streamingReducers.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {PayloadAction} from '@reduxjs/toolkit';
22

3+
import type {SpeedMetrics} from '../../../types/store/query';
34
import type {
45
QueryResponseChunk,
56
SessionChunk,
@@ -57,8 +58,6 @@ export const setStreamQueryResponse = (
5758
}
5859
};
5960

60-
type SpeedMetrics = NonNullable<NonNullable<QueryState['result']>['speedMetrics']>;
61-
6261
const updateSpeedMetrics = (metrics: SpeedMetrics, totalNewRows: number) => {
6362
const currentTime = Date.now();
6463
const WINDOW_SIZE = 5000; // 5 seconds in milliseconds
@@ -87,11 +86,6 @@ export const addStreamingChunks = (state: QueryState, action: PayloadAction<Stre
8786
}
8887

8988
state.result.data = state.result.data || prepareQueryData(null);
90-
state.result.speedMetrics = state.result.speedMetrics || {
91-
rowsPerSecond: 0,
92-
lastUpdateTime: Date.now(),
93-
recentChunks: [],
94-
};
9589
state.result.data.resultSets = state.result.data.resultSets || [];
9690

9791
// Merge chunks by result index
@@ -115,10 +109,6 @@ export const addStreamingChunks = (state: QueryState, action: PayloadAction<Stre
115109
0,
116110
);
117111

118-
if (state.result.speedMetrics) {
119-
updateSpeedMetrics(state.result.speedMetrics, totalNewRows);
120-
}
121-
122112
// Process merged chunks
123113
for (const [resultIndex, chunk] of mergedChunks.entries()) {
124114
const {columns, rows} = chunk.result;
@@ -127,6 +117,11 @@ export const addStreamingChunks = (state: QueryState, action: PayloadAction<Stre
127117
] || {
128118
columns: [],
129119
result: [],
120+
speedMetrics: {
121+
rowsPerSecond: 0,
122+
lastUpdateTime: Date.now(),
123+
recentChunks: [],
124+
},
130125
});
131126

132127
if (columns && !resultSet.columns?.length) {
@@ -136,5 +131,9 @@ export const addStreamingChunks = (state: QueryState, action: PayloadAction<Stre
136131
const safeRows = rows || [];
137132
const formattedRows = parseResult(safeRows, resultSet.columns || []);
138133
resultSet.result?.push(...formattedRows);
134+
135+
if (resultSet.speedMetrics) {
136+
updateSpeedMetrics(resultSet.speedMetrics, totalNewRows);
137+
}
139138
}
140139
};

src/store/reducers/query/types.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,12 @@ export interface PreparedQueryData extends IQueryResult {
4848
simplifiedPlan?: SimplifiedPlan;
4949
}
5050

51-
export interface SpeedMetrics {
52-
rowsPerSecond: number;
53-
lastUpdateTime: number;
54-
recentChunks: Array<{
55-
timestamp: number;
56-
rowCount: number;
57-
}>;
58-
}
59-
6051
export interface QueryResult {
6152
type: QueryAction;
6253
data?: PreparedQueryData;
6354
error?: unknown;
6455
queryId: string;
6556
isLoading: boolean;
66-
speedMetrics?: SpeedMetrics;
6757
}
6858

6959
export interface QueryState {

src/types/store/query.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@ import type {
2020
} from '../api/query';
2121
import type {ValueOf} from '../common';
2222

23+
export interface SpeedMetrics {
24+
rowsPerSecond: number;
25+
lastUpdateTime: number;
26+
recentChunks: Array<{
27+
timestamp: number;
28+
rowCount: number;
29+
}>;
30+
}
31+
2332
export interface ParsedResultSet {
2433
columns?: ColumnType[];
2534
result?: KeyValueRow[];
2635
truncated?: boolean;
36+
speedMetrics?: SpeedMetrics;
2737
}
2838

2939
export interface IQueryResult {

0 commit comments

Comments
 (0)