浏览代码

[frontend] Switch to using the sqlParserRepository for the local optimizer strategy

This greatly reduces the bundle size for editor other than Hive
Johan Ahlen 5 年之前
父节点
当前提交
6979b5fe09
共有 1 个文件被更改,包括 32 次插入30 次删除
  1. 32 30
      desktop/core/src/desktop/js/catalog/optimizer/localStrategy.js

+ 32 - 30
desktop/core/src/desktop/js/catalog/optimizer/localStrategy.js

@@ -18,44 +18,46 @@ import $ from 'jquery';
 
 import BaseStrategy from './baseStrategy';
 import dataCatalog from 'catalog/dataCatalog';
-import sqlAutocompleteParser from 'parse/sql/hive/hiveAutocompleteParser';
+import sqlParserRepository from 'parse/sql/sqlParserRepository';
 import I18n from 'utils/i18n';
 
 export default class LocalStrategy extends BaseStrategy {
   analyzeRisk(options) {
     const snippet = JSON.parse(options.snippetJson);
 
-    // TODO: Get parser from repository, need to extract SqlFunctions dep first
-    // to reduce size of main hue bundle
-    // const parser = await sqlParserRepository.getAutocompleteParser(snippet.dialect);
-    const sqlParseResult = sqlAutocompleteParser.parseSql(snippet.statement + ' ', '');
+    const deferred = $.Deferred();
+    sqlParserRepository
+      .getAutocompleteParser(this.connector.dialect)
+      .then(sqlAutocompleteParser => {
+        const sqlParseResult = sqlAutocompleteParser.parseSql(snippet.statement + ' ', '');
 
-    const hasLimit = sqlParseResult.locations.some(
-      location => location.type === 'limitClause' && !location.missing
-    );
+        const hasLimit = sqlParseResult.locations.some(
+          location => location.type === 'limitClause' && !location.missing
+        );
+
+        deferred.resolve({
+          status: 0,
+          message: '',
+          query_complexity: {
+            hints: !hasLimit
+              ? [
+                  {
+                    riskTables: [],
+                    riskAnalysis: I18n('Query has no limit'),
+                    riskId: 22, // To change
+                    risk: 'low',
+                    riskRecommendation: I18n(
+                      'Append a limit clause to reduce the size of the result set'
+                    )
+                  }
+                ]
+              : [],
+            noStats: true,
+            noDDL: false
+          }
+        });
+      });
 
-    const deferred = $.Deferred();
-    deferred.resolve({
-      status: 0,
-      message: '',
-      query_complexity: {
-        hints: !hasLimit
-          ? [
-              {
-                riskTables: [],
-                riskAnalysis: I18n('Query has no limit'),
-                riskId: 22, // To change
-                risk: 'low',
-                riskRecommendation: I18n(
-                  'Append a limit clause to reduce the size of the result set'
-                )
-              }
-            ]
-          : [],
-        noStats: true,
-        noDDL: false
-      }
-    });
     return deferred.promise();
   }