Skip to content

Commit 0168055

Browse files
committed
[editor] Auto propose to add a LIMIT
1 parent 44155e8 commit 0168055

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

desktop/core/src/desktop/js/catalog/optimizer/SqlAnalyzer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class SqlAnalyzer implements Optimizer {
6767
{
6868
riskTables: [],
6969
riskAnalysis: I18n('Query has no limit'),
70-
riskId: 22, // To change
70+
riskId: 17,
7171
risk: 'low',
7272
riskRecommendation: I18n('Append a limit clause to reduce the size of the result set')
7373
}

desktop/core/src/desktop/js/ko/components/assist/ko.assistEditorContextPanel.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,10 @@ class AssistEditorContextPanel {
660660
}
661661

662662
if (
663+
riskId === 22 &&
663664
location.type === 'whereClause' &&
664665
!location.subquery &&
665-
(location.missing || riskId === 22)
666+
location.missing
666667
) {
667668
this.activeEditor().moveCursorToPosition({
668669
row: location.location.last_line - 1,
@@ -694,6 +695,42 @@ class AssistEditorContextPanel {
694695
return false;
695696
}
696697

698+
if (
699+
riskId === 17 &&
700+
location.type === 'limitClause' &&
701+
!location.subquery &&
702+
location.missing
703+
) {
704+
this.activeEditor().moveCursorToPosition({
705+
row: location.location.last_line - 1,
706+
column: location.location.last_column - 1
707+
});
708+
this.activeEditor().clearSelection();
709+
710+
if (/\S$/.test(this.activeEditor().getTextBeforeCursor())) {
711+
this.activeEditor().session.insert(this.activeEditor().getCursorPosition(), ' ');
712+
}
713+
714+
const operation = 'LIMIT';
715+
this.activeEditor().session.insert(
716+
this.activeEditor().getCursorPosition(),
717+
isLowerCase ? operation.toLowerCase() : operation
718+
);
719+
this.activeEditor().focus();
720+
721+
if (riskId === 17) {
722+
huePubSub.publish('editor.autocomplete.temporary.sort.override', {
723+
partitionColumnsFirst: true
724+
});
725+
}
726+
727+
window.setTimeout(() => {
728+
this.activeEditor().execCommand('startAutocomplete');
729+
}, 1);
730+
731+
return false;
732+
}
733+
697734
return true;
698735
});
699736
}

0 commit comments

Comments
 (0)