Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use schema:multi for all query requests #1399

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -46,7 +46,7 @@ export function TopQueries({tenantName}: TopQueriesProps) {
);

const loading = isFetching && currentData === undefined;
const {result: data} = currentData || {};
const data = currentData?.resultSets?.[0]?.result || [];

const handleRowClick = React.useCallback(
(row: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const TopShards = ({tenantName, path}: TopShardsProps) => {
);

const loading = isFetching && currentData === undefined;
const {result: data} = currentData || {};
const data = currentData?.resultSets?.[0]?.result || [];

const columns = getTopShardsColumns(tenantName, location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function TopTables({path}: TopTablesProps) {
);
const loading = isFetching && currentData === undefined;

const {result: data} = currentData || {};
const data = currentData?.resultSets?.[0]?.result || [];

const formatSize = (value?: number) => {
const size = getSizeWithSignificantDigits(data?.length ? Number(data[0].Size) : 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ interface Props {
export const RunningQueriesData = ({database}: Props) => {
const [autoRefreshInterval] = useAutoRefreshInterval();
const filters = useTypedSelector((state) => state.executeTopQueries);
const {
currentData: data,
isFetching,
error,
} = topQueriesApi.useGetRunningQueriesQuery(
const {currentData, isFetching, error} = topQueriesApi.useGetRunningQueriesQuery(
{
database,
filters,
},
{pollingInterval: autoRefreshInterval},
);

const data = currentData?.resultSets?.[0].result || [];

return (
<React.Fragment>
{error ? <ResponseError error={parseQueryErrorToString(error)} /> : null}
Expand All @@ -41,7 +39,7 @@ export const RunningQueriesData = ({database}: Props) => {
emptyDataMessage={i18n('no-data')}
columnsWidthLSKey={RUNNING_QUERIES_COLUMNS_WIDTH_LS_KEY}
columns={RUNNING_QUERIES_COLUMNS}
data={data || []}
data={data}
settings={QUERY_TABLE_SETTINGS}
/>
</TableWithControlsLayout.Table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const TopQueriesData = ({database, onRowClick}: Props) => {
},
{pollingInterval: autoRefreshInterval},
);
const {result: data} = currentData || {};
const data = currentData?.resultSets?.[0]?.result || [];

const rawColumns = TOP_QUERIES_COLUMNS;
const columns = rawColumns.map((column) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Tenant/Diagnostics/TopShards/TopShards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const TopShards = ({tenantName, path, type}: TopShardsProps) => {
{pollingInterval: autoRefreshInterval},
);
const loading = isFetching && result === undefined;
const {result: data} = result ?? {};
const data = result?.resultSets?.[0]?.result || [];

const onSort = (newSortOrder?: SortOrder | SortOrder[]) => {
// omit information about sort order to disable ASC order, only DESC makes sense for top shards
Expand Down
7 changes: 3 additions & 4 deletions src/containers/Tenant/Query/ExecuteResult/ExecuteResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ export function ExecuteResult({
const {error, isLoading, queryId, data} = result;

const stats: TKqpStatsQuery | undefined = data?.stats;
const resultsSetsCount = data?.resultSets?.length;
const isMulti = resultsSetsCount && resultsSetsCount > 0;
const currentResult = isMulti ? data?.resultSets?.[selectedResultSet] : data;
const resultsSetsCount = data?.resultSets?.length || 0;
const currentResult = data?.resultSets?.[selectedResultSet];
const {plan, simplifiedPlan} = React.useMemo(() => getPlan(data), [data]);

const resultOptions: ControlGroupOption<SectionID>[] = [
Expand Down Expand Up @@ -106,7 +105,7 @@ export function ExecuteResult({
const renderResult = () => {
return (
<div className={b('result-wrapper')}>
{isMulti && resultsSetsCount > 1 && (
{resultsSetsCount > 1 && (
<div>
<Tabs
className={b('result-tabs')}
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Tenant/Query/Preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Preview = ({database, path, type}: PreviewProps) => {

const [autoRefreshInterval] = useAutoRefreshInterval();

const query = `--!syntax_v1\nselect * from \`${path}\` limit 32`;
const query = `select * from \`${path}\` limit 32`;
const {currentData, isFetching, error} = previewApi.useSendQueryQuery(
{database, query, action: isExternalTableType(type) ? 'execute-query' : 'execute-scan'},
{
Expand All @@ -40,7 +40,7 @@ export const Preview = ({database, path, type}: PreviewProps) => {
},
);
const loading = isFetching && currentData === undefined;
const data = currentData ?? {};
const data = currentData?.resultSets?.[0] ?? {};

const handleClosePreview = () => {
dispatch(setShowPreview(false));
Expand Down
5 changes: 0 additions & 5 deletions src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
DEFAULT_IS_QUERY_RESULT_COLLAPSED,
DEFAULT_SIZE_RESULT_PANE_KEY,
LAST_USED_QUERY_ACTION_KEY,
QUERY_USE_MULTI_SCHEMA_KEY,
} from '../../../../utils/constants';
import {useEventHandler, useQueryExecutionSettings, useSetting} from '../../../../utils/hooks';
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
Expand Down Expand Up @@ -105,7 +104,6 @@ function QueryEditor(props: QueryEditorProps) {
useLastQueryExecutionSettings();
const {resetBanner} = useChangedQuerySettings();

const [useMultiSchema] = useSetting(QUERY_USE_MULTI_SCHEMA_KEY);
const [lastUsedQueryAction, setLastUsedQueryAction] = useSetting<QueryAction>(
LAST_USED_QUERY_ACTION_KEY,
);
Expand Down Expand Up @@ -148,8 +146,6 @@ function QueryEditor(props: QueryEditorProps) {
const handleSendExecuteClick = useEventHandler((text?: string) => {
const {input, history} = executeQuery;

const schema = useMultiSchema ? 'multi' : 'modern';

const query = text ?? input;

setLastUsedQueryAction(QUERY_ACTIONS.execute);
Expand All @@ -163,7 +159,6 @@ function QueryEditor(props: QueryEditorProps) {
query,
database: tenantName,
querySettings,
schema,
enableTracingLevel,
queryId,
});
Expand Down
3 changes: 0 additions & 3 deletions src/containers/UserSettings/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@

"settings.showDomainDatabase.title": "Show domain database",

"settings.queryUseMultiSchema.title": "Allow queries with multiple result sets",
"settings.queryUseMultiSchema.description": "Use 'multi' schema for queries. It enables queries with multiple result sets. It returns nothing on versions 23-3 and older",

"settings.useClusterBalancerAsBackend.title": "Use cluster balancer as backend",
"settings.useClusterBalancerAsBackend.description": "By default random cluster node is used as backend. It causes saved links to become invalid after some time, when node is restarted. Using balancer as backend fixes it",

Expand Down
9 changes: 1 addition & 8 deletions src/containers/UserSettings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ENABLE_AUTOCOMPLETE,
INVERTED_DISKS_KEY,
LANGUAGE_KEY,
QUERY_USE_MULTI_SCHEMA_KEY,
SHOW_DOMAIN_DATABASE_KEY,
THEME_KEY,
USE_CLUSTER_BALANCER_AS_BACKEND_KEY,
Expand Down Expand Up @@ -100,12 +99,6 @@ export const showDomainDatabase: SettingProps = {
title: i18n('settings.showDomainDatabase.title'),
};

export const queryUseMultiSchemaSetting: SettingProps = {
settingKey: QUERY_USE_MULTI_SCHEMA_KEY,
title: i18n('settings.queryUseMultiSchema.title'),
description: i18n('settings.queryUseMultiSchema.description'),
};

export const useClusterBalancerAsBackendSetting: SettingProps = {
settingKey: USE_CLUSTER_BALANCER_AS_BACKEND_KEY,
title: i18n('settings.useClusterBalancerAsBackend.title'),
Expand Down Expand Up @@ -143,7 +136,7 @@ export const appearanceSection: SettingsSection = {
export const experimentsSection: SettingsSection = {
id: 'experimentsSection',
title: i18n('section.experiments'),
settings: [usePaginatedTables, queryUseMultiSchemaSetting],
settings: [usePaginatedTables],
};
export const devSettingsSection: SettingsSection = {
id: 'devSettingsSection',
Expand Down
12 changes: 4 additions & 8 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import type {
Actions,
ErrorResponse,
QueryAPIResponse,
Schemas,
Stats,
Timeout,
TracingLevel,
Expand Down Expand Up @@ -529,12 +528,11 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
},
);
}
sendQuery<Action extends Actions, Schema extends Schemas = undefined>(
sendQuery<Action extends Actions>(
params: {
query?: string;
database?: string;
action?: Action;
schema?: Schema;
syntax?: QuerySyntax;
stats?: Stats;
tracingLevel?: TracingLevel;
Expand All @@ -553,14 +551,12 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
true,
);
// FIXME: after backend fix
const {schema, ...rest} = params;

// FIXME: base64 is passed both to params and body to work on versions before and after 24-3
return this.post<QueryAPIResponse<Action, Schema> | ErrorResponse | null>(
return this.post<QueryAPIResponse<Action> | ErrorResponse | null>(
this.getPath('/viewer/json/query'),
{...rest, base64},
{schema, base64},
{...params, base64},
{schema: 'multi', base64},
{
concurrentId,
timeout: params.timeout,
Expand Down
2 changes: 0 additions & 2 deletions src/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
PARTITIONS_HIDDEN_COLUMNS_KEY,
QUERY_EXECUTION_SETTINGS_KEY,
QUERY_SETTINGS_BANNER_LAST_CLOSED_KEY,
QUERY_USE_MULTI_SCHEMA_KEY,
SAVED_QUERIES_KEY,
SHOW_DOMAIN_DATABASE_KEY,
TENANT_INITIAL_PAGE_KEY,
Expand All @@ -31,7 +30,6 @@ export const DEFAULT_USER_SETTINGS = {
[THEME_KEY]: 'system',
[LANGUAGE_KEY]: undefined,
[INVERTED_DISKS_KEY]: false,
[QUERY_USE_MULTI_SCHEMA_KEY]: true,
[BINARY_DATA_IN_PLAIN_TEXT_DISPLAY]: true,
[SAVED_QUERIES_KEY]: [],
[TENANT_INITIAL_PAGE_KEY]: TENANT_PAGES_IDS.query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,87 +30,109 @@ describe('parseGroupsStatsQueryResponse', () => {

// 2 disk types and 2 erasure types
const dataSet1 = {
columns,
result: [
['Type:SSD', 'block-4-2', '1000', '2000', 100, 50],
['Type:ROT', 'block-4-2', '2000', '1000', 50, 0],
['Type:ROT', 'mirror-3of4', '1000', '0', 15, 0],
['Type:SSD', 'mirror-3of4', '1000', '0', 5, 50],
['Type:ROT', 'mirror-3-dc', null, null, null, 0],
['Type:SSD', 'mirror-3-dc', null, null, null, 0],
{
columns,
rows: [
['Type:SSD', 'block-4-2', '1000', '2000', 100, 50],
['Type:ROT', 'block-4-2', '2000', '1000', 50, 0],
['Type:ROT', 'mirror-3of4', '1000', '0', 15, 0],
['Type:SSD', 'mirror-3of4', '1000', '0', 5, 50],
['Type:ROT', 'mirror-3-dc', null, null, null, 0],
['Type:SSD', 'mirror-3-dc', null, null, null, 0],
],
},
],
};

// 2 disk types and 1 erasure types, but with additional disks params
const dataSet2 = {
columns,
result: [
['Type:ROT,SharedWithOs:0,ReadCentric:0,Kind:0', 'mirror-3-dc', '1000', '500', 16, 16],
['Type:ROT,SharedWithOs:1,ReadCentric:0,Kind:0', 'mirror-3-dc', '2000', '1000', 8, 24],
['Type:SSD', 'mirror-3-dc', '3000', '400', 2, 10],
['Type:ROT', 'mirror-3-dc', null, null, null, 32],
['Type:ROT', 'block-4-2', null, null, null, 20],
['Type:SSD', 'block-4-2', null, null, null, 0],
{
columns,
rows: [
[
'Type:ROT,SharedWithOs:0,ReadCentric:0,Kind:0',
'mirror-3-dc',
'1000',
'500',
16,
16,
],
[
'Type:ROT,SharedWithOs:1,ReadCentric:0,Kind:0',
'mirror-3-dc',
'2000',
'1000',
8,
24,
],
['Type:SSD', 'mirror-3-dc', '3000', '400', 2, 10],
['Type:ROT', 'mirror-3-dc', null, null, null, 32],
['Type:ROT', 'block-4-2', null, null, null, 20],
['Type:SSD', 'block-4-2', null, null, null, 0],
],
},
],
};
const parsedDataSet1 = {
SSD: {
HDD: {
'block-4-2': {
diskType: 'SSD',
allocatedSize: 1000,
availableSize: 2000,
createdGroups: 50,
diskType: 'HDD',
erasure: 'block-4-2',
createdGroups: 100,
totalGroups: 150,
allocatedSize: 2000,
availableSize: 1000,
totalGroups: 50,
},
'mirror-3of4': {
diskType: 'SSD',
erasure: 'mirror-3of4',
createdGroups: 5,
totalGroups: 55,
allocatedSize: 0,
availableSize: 1000,
createdGroups: 15,
diskType: 'HDD',
erasure: 'mirror-3of4',
totalGroups: 15,
},
},
HDD: {
SSD: {
'block-4-2': {
diskType: 'HDD',
allocatedSize: 2000,
availableSize: 1000,
createdGroups: 100,
diskType: 'SSD',
erasure: 'block-4-2',
createdGroups: 50,
totalGroups: 50,
allocatedSize: 1000,
availableSize: 2000,
totalGroups: 150,
},
'mirror-3of4': {
diskType: 'HDD',
erasure: 'mirror-3of4',
createdGroups: 15,
totalGroups: 15,
allocatedSize: 0,
availableSize: 1000,
createdGroups: 5,
diskType: 'SSD',
erasure: 'mirror-3of4',
totalGroups: 55,
},
},
};

const parsedDataSet2 = {
HDD: {
'mirror-3-dc': {
allocatedSize: 1500,
availableSize: 3000,
createdGroups: 24,
diskType: 'HDD',
erasure: 'mirror-3-dc',
createdGroups: 24,
totalGroups: 64,
allocatedSize: 1500,
availableSize: 3000,
},
},
SSD: {
'mirror-3-dc': {
allocatedSize: 400,
availableSize: 3000,
createdGroups: 2,
diskType: 'SSD',
erasure: 'mirror-3-dc',
createdGroups: 2,
totalGroups: 12,
allocatedSize: 400,
availableSize: 3000,
},
},
};
Expand Down
Loading
Loading