Browse Source

[editor] Add checkSelectStar to assist

Romain Rigaux 4 years ago
parent
commit
93252bacf2

+ 8 - 9
desktop/core/src/desktop/js/catalog/optimizer/SqlAnalyzer.ts

@@ -76,15 +76,14 @@ export default class SqlAnalyzer implements Optimizer {
 
       const isSelectStar = await this.checkSelectStar(snippet.statement, this.connector.dialect);
       if (isSelectStar) {
-        hints.push(
-          {
-            riskTables: [],
-            riskAnalysis: I18n('Query doing a SELECT *'), // Could be triggered only if column number > 10 (todo in Validator API)
-            riskId: 18,
-            risk: 'low',
-            riskRecommendation: I18n('Select only a subset of columns instead of all of them')
-          }
-        );
+        hints.push({
+          riskTables: [],
+          riskAnalysis: I18n('Query doing a SELECT *'), // Could be triggered only if column number > 10 (todo in Validator API)
+          riskId: 18,
+          risk: 'low',
+          riskRecommendation: I18n('Select only a subset of columns instead of all of them')
+        });
+      }
 
       try {
         const apiResponse = await apiPromise;

+ 17 - 6
desktop/core/src/desktop/js/ko/components/assist/ko.assistEditorContextPanel.js

@@ -116,7 +116,7 @@ const TEMPLATE =
           <li>
             <div class="risk-list-title" data-bind="css: { 'risk-list-high' : risk === 'high', 'risk-list-normal':  risk !== 'high' }, tooltip: { title: risk + ' ' + riskTables }"><span data-bind="text: riskAnalysis"></span></div>
             <div class="risk-list-description" data-bind="text: riskRecommendation"></div>
-            <div class="risk-quickfix" data-bind="visible: (riskId === 17 || riskId === 22) && $parent.activeEditor() && $parent.activeLocations()" style="display:none;">
+            <div class="risk-quickfix" data-bind="visible: (riskId === 17 || riskId === 18 || riskId === 22) && $parent.activeEditor() && $parent.activeLocations()" style="display:none;">
               <a href="javascript:void(0);" data-bind="click: function () { $parent.addFilter(riskId); hueAnalytics.convert('optimizer', 'addFilter/' + riskId); }">${I18n(
                 'Add filter'
               )}</a>
@@ -718,11 +718,22 @@ class AssistEditorContextPanel {
           );
           this.activeEditor().focus();
 
-          if (riskId === 17) {
-            huePubSub.publish('editor.autocomplete.temporary.sort.override', {
-              partitionColumnsFirst: true
-            });
-          }
+          window.setTimeout(() => {
+            this.activeEditor().execCommand('startAutocomplete');
+          }, 1);
+
+          return false;
+        }
+
+        if (riskId === 18 && location.type === 'asterisk' && !location.subquery) {
+          this.activeEditor().moveCursorToPosition({
+            row: location.location.last_line - 1,
+            column: location.location.last_column - 1
+          });
+
+          this.activeEditor().clearSelection();
+          this.activeEditor().removeTextBeforeCursor(1);
+          this.activeEditor().focus();
 
           window.setTimeout(() => {
             this.activeEditor().execCommand('startAutocomplete');