mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 17:52:34 -05:00
query result selection summary improvement (both perf and usability) (#23378)
This commit is contained in:
@@ -33,11 +33,11 @@ import { ActionBar, ActionsOrientation } from 'vs/base/browser/ui/actionbar/acti
|
||||
import { isInDOM, Dimension } from 'vs/base/browser/dom';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IAction, Separator } from 'vs/base/common/actions';
|
||||
import { IAction, Separator, toAction } from 'vs/base/common/actions';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IGridDataProvider } from 'sql/workbench/services/query/common/gridDataProvider';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { GridPanelState, GridTableState } from 'sql/workbench/common/editor/query/gridTableState';
|
||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
import { SaveFormat } from 'sql/workbench/services/query/common/resultSerializer';
|
||||
@@ -48,7 +48,7 @@ import { Orientation } from 'vs/base/browser/ui/splitview/splitview';
|
||||
import { IQueryModelService } from 'sql/workbench/services/query/common/queryModel';
|
||||
import { FilterButtonWidth, HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin';
|
||||
import { HybridDataProvider } from 'sql/base/browser/ui/table/hybridDataProvider';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { INotificationHandle, INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
||||
import { alert, status } from 'vs/base/browser/ui/aria/aria';
|
||||
import { IExecutionPlanService } from 'sql/workbench/services/executionPlan/common/interfaces';
|
||||
import { ExecutionPlanInput } from 'sql/workbench/contrib/executionPlan/browser/executionPlanInput';
|
||||
@@ -58,6 +58,8 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib
|
||||
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
|
||||
import { queryEditorNullBackground } from 'sql/platform/theme/common/colorRegistry';
|
||||
import { IComponentContextService } from 'sql/workbench/services/componentContext/browser/componentContextService';
|
||||
import { GridRange } from 'sql/base/common/gridRange';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
const ROW_HEIGHT = 29;
|
||||
const HEADER_HEIGHT = 26;
|
||||
@@ -373,6 +375,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView, IQue
|
||||
private filterPlugin: HeaderFilter<T>;
|
||||
private isDisposed: boolean = false;
|
||||
private gridConfig: IResultGridConfiguration;
|
||||
private selectionChangeHandlerTokenSource: CancellationTokenSource | undefined;
|
||||
|
||||
private columns: Slick.Column<T>[];
|
||||
|
||||
@@ -664,7 +667,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView, IQue
|
||||
if (this.state) {
|
||||
this.state.selection = this.selectionModel.getSelectedRanges();
|
||||
}
|
||||
await this.notifyTableSelectionChanged();
|
||||
await this.handleTableSelectionChange();
|
||||
});
|
||||
|
||||
this.table.grid.onScroll.subscribe((e, data) => {
|
||||
@@ -763,7 +766,7 @@ export abstract class GridTableBase<T> extends Disposable implements IView, IQue
|
||||
this._state = val;
|
||||
}
|
||||
|
||||
private async getRowData(start: number, length: number): Promise<ICellValue[][]> {
|
||||
private async getRowData(start: number, length: number, cancellationToken?: CancellationToken, onProgressCallback?: (availableRows: number) => void): Promise<ICellValue[][]> {
|
||||
let subset;
|
||||
if (this.dataProvider.isDataInMemory) {
|
||||
// handle the scenario when the data is sorted/filtered,
|
||||
@@ -771,23 +774,102 @@ export abstract class GridTableBase<T> extends Disposable implements IView, IQue
|
||||
const data = await this.dataProvider.getRangeAsync(start, length);
|
||||
subset = data.map(item => Object.keys(item).map(key => item[key]));
|
||||
} else {
|
||||
subset = (await this.gridDataProvider.getRowData(start, length)).rows;
|
||||
subset = (await this.gridDataProvider.getRowData(start, length, cancellationToken, onProgressCallback)).rows;
|
||||
}
|
||||
return subset;
|
||||
}
|
||||
|
||||
private async notifyTableSelectionChanged() {
|
||||
const selectedCells = [];
|
||||
for (const range of this.state.selection) {
|
||||
const subset = await this.getRowData(range.fromRow, range.toRow - range.fromRow + 1);
|
||||
subset.forEach(row => {
|
||||
// start with range.fromCell -1 because we have row number column which is not available in the actual data
|
||||
for (let i = range.fromCell - 1; i < range.toCell; i++) {
|
||||
selectedCells.push(row[i]);
|
||||
}
|
||||
});
|
||||
private async handleTableSelectionChange(): Promise<void> {
|
||||
if (this.selectionChangeHandlerTokenSource) {
|
||||
this.selectionChangeHandlerTokenSource.cancel();
|
||||
}
|
||||
this.selectionChangeHandlerTokenSource = new CancellationTokenSource();
|
||||
await this.notifyTableSelectionChanged(this.selectionChangeHandlerTokenSource);
|
||||
}
|
||||
|
||||
private async notifyTableSelectionChanged(cancellationTokenSource: CancellationTokenSource): Promise<void> {
|
||||
const gridRanges = GridRange.fromSlickRanges(this.state.selection ?? []);
|
||||
const rowRanges = GridRange.getUniqueRows(gridRanges);
|
||||
const columnRanges = GridRange.getUniqueColumns(gridRanges);
|
||||
const rowCount = rowRanges.map(range => range.end - range.start + 1).reduce((p, c) => p + c);
|
||||
const runAction = async (proceed: boolean) => {
|
||||
const selectedCells = [];
|
||||
if (proceed && !cancellationTokenSource.token.isCancellationRequested) {
|
||||
let notificationHandle: INotificationHandle = undefined;
|
||||
const timeout = setTimeout(() => {
|
||||
notificationHandle = this.notificationService.notify({
|
||||
message: localize('resultsGrid.loadingData', "Loading selected rows for calculation..."),
|
||||
severity: Severity.Info,
|
||||
progress: {
|
||||
infinite: true
|
||||
},
|
||||
actions: {
|
||||
primary: [
|
||||
toAction({
|
||||
id: 'cancelLoadingCells',
|
||||
label: localize('resultsGrid.cancel', "Cancel"),
|
||||
run: () => {
|
||||
cancellationTokenSource.cancel();
|
||||
notificationHandle.close();
|
||||
}
|
||||
})]
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
this.queryModelService.notifyCellSelectionChanged([]);
|
||||
let rowsInProcessedRanges = 0;
|
||||
for (const range of rowRanges) {
|
||||
if (cancellationTokenSource.token.isCancellationRequested) {
|
||||
break;
|
||||
}
|
||||
const rows = await this.getRowData(range.start, range.end - range.start + 1, cancellationTokenSource.token, (availableRows: number) => {
|
||||
notificationHandle?.updateMessage(localize('resultsGrid.loadingDataWithProgress', "Loading selected rows for calculation ({0}/{1})...", rowsInProcessedRanges + availableRows, rowCount));
|
||||
});
|
||||
rows.forEach((row, rowIndex) => {
|
||||
columnRanges.forEach(cr => {
|
||||
for (let i = cr.start; i <= cr.end; i++) {
|
||||
if (this.state.selection.some(selection => selection.contains(rowIndex + range.start, i))) {
|
||||
// need to reduce the column index by 1 because we have row number column which is not available in the actual data
|
||||
selectedCells.push(row[i - 1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
rowsInProcessedRanges += range.end - range.start + 1;
|
||||
}
|
||||
clearTimeout(timeout);
|
||||
notificationHandle?.close();
|
||||
}
|
||||
cancellationTokenSource.dispose();
|
||||
if (!cancellationTokenSource.token.isCancellationRequested) {
|
||||
this.queryModelService.notifyCellSelectionChanged(selectedCells);
|
||||
}
|
||||
};
|
||||
const showPromptConfigValue = this.configurationService.getValue<IQueryEditorConfiguration>('queryEditor').results.promptForLargeRowSelection;
|
||||
if (this.options.inMemoryDataCountThreshold && rowCount > this.options.inMemoryDataCountThreshold && showPromptConfigValue) {
|
||||
this.notificationService.prompt(Severity.Warning, localize('resultsGrid.largeRowSelectionPrompt.', 'You have selected {0} rows, it might take a while to load the data and calculate the summary, do you want to continue?', rowCount), [
|
||||
{
|
||||
label: localize('resultsGrid.confirmLargeRowSelection', "Yes"),
|
||||
run: async () => {
|
||||
await runAction(true);
|
||||
}
|
||||
}, {
|
||||
label: localize('resultsGrid.cancelLargeRowSelection', "Cancel"),
|
||||
run: async () => {
|
||||
await runAction(false);
|
||||
}
|
||||
}, {
|
||||
label: localize('resultsGrid.donotShowLargeRowSelectionPromptAgain', "Don't show again"),
|
||||
run: async () => {
|
||||
this.configurationService.updateValue('queryEditor.results.promptForLargeRowSelection', false).catch(e => onUnexpectedError(e));
|
||||
await runAction(true);
|
||||
},
|
||||
isSecondary: true
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
await runAction(true);
|
||||
}
|
||||
this.queryModelService.notifyCellSelectionChanged(selectedCells);
|
||||
}
|
||||
|
||||
private async onTableClick(event: ITableMouseEvent) {
|
||||
|
||||
@@ -424,6 +424,11 @@ const queryEditorConfiguration: IConfigurationNode = {
|
||||
'description': localize('queryEditor.results.showActionBar', "Whether to show the action bar in the query results view"),
|
||||
'default': true
|
||||
},
|
||||
'queryEditor.results.promptForLargeRowSelection': {
|
||||
'type': 'boolean',
|
||||
'default': true,
|
||||
'description': localize('queryEditor.results.promptForLargeRowSelection', "When cells are selected in the results grid, ADS will calculate the summary for them, This setting controls whether to show the a confirmation when the number of rows selected is larger than the value specified in the 'inMemoryDataProcessingThreshold' setting. The default value is true.")
|
||||
},
|
||||
'queryEditor.messages.showBatchTime': {
|
||||
'type': 'boolean',
|
||||
'description': localize('queryEditor.messages.showBatchTime', "Should execution time be shown for individual batches"),
|
||||
|
||||
@@ -316,10 +316,12 @@ export class QueryResultSelectionSummaryStatusBarContribution extends Disposable
|
||||
const nullCount = selectedCells.filter(cell => cell.isNull).length;
|
||||
let summaryText, tooltipText;
|
||||
if (numericValues.length >= 2) {
|
||||
const sum = numericValues.reduce((previous, current, idx, array) => previous + current);
|
||||
const sum = numericValues.reduce((previous, current) => previous + current);
|
||||
const min = numericValues.reduce((previous, current) => Math.min(previous, current));
|
||||
const max = numericValues.reduce((previous, current) => Math.max(previous, current));
|
||||
summaryText = localize('status.query.summaryText', "Average: {0} Count: {1} Sum: {2}", Number((sum / numericValues.length).toFixed(3)), selectedCells.length, sum);
|
||||
tooltipText = localize('status.query.summaryTooltip', "Average: {0} Count: {1} Distinct Count: {2} Max: {3} Min: {4} Null Count: {5} Sum: {6}",
|
||||
Number((sum / numericValues.length).toFixed(3)), selectedCells.length, distinctValues.size, Math.max(...numericValues), Math.min(...numericValues), nullCount, sum);
|
||||
Number((sum / numericValues.length).toFixed(3)), selectedCells.length, distinctValues.size, max, min, nullCount, sum);
|
||||
} else {
|
||||
summaryText = summaryText = localize('status.query.summaryTextNonNumeric', "Count: {0} Distinct Count: {1} Null Count: {2}", selectedCells.length, distinctValues.size, nullCount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user