Browse Source

HUE-7342 [editor] Make the syntax checker aware of CTE aliases

Johan Ahlen 8 năm trước cách đây
mục cha
commit
74644ad3c9

+ 1 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_main.jison

@@ -1542,6 +1542,7 @@ WithQueries_EDIT
 WithQuery
  : RegularOrBacktickedIdentifier AnyAs '(' TableSubQueryInner ')'
    {
+     parser.addCteAliasLocation(@1, $1);
      $4.alias = $1;
      $$ = $4;
    }

+ 20 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecLocations.js

@@ -35,6 +35,26 @@
       });
     };
 
+    it('should report locations for "WITH boo AS (SELECT * FROM tbl) SELECT * FROM boo; |"', function() {
+      assertLocations({
+        beforeCursor: 'WITH boo AS (SELECT * FROM tbl) SELECT * FROM boo; ',
+        expectedLocations: [
+          { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 50 } },
+          { type: 'alias', source: 'cte', alias: 'boo', location: { first_line: 1, last_line: 1, first_column: 6, last_column: 9 } },
+          { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 21, last_column: 22 }, subquery: true },
+          { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 21, last_column: 22 }, tables: [{ identifierChain: [{ name: 'tbl' }] }] },
+          { type: 'table', location: { first_line: 1, last_line: 1, first_column: 28, last_column: 31 }, identifierChain: [{ name: 'tbl' }] },
+          { type: 'whereClause', missing: true, location: { first_line: 1, last_line: 1, first_column: 31, last_column: 31 }, subquery: true },
+          { type: 'limitClause', missing: true, location: { first_line: 1, last_line: 1, first_column: 31, last_column: 31 }, subquery: true },
+          { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 40, last_column: 41 } },
+          { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 40, last_column: 41 }, tables: [{ identifierChain: [{ name: 'boo' }] }] },
+          { type: 'table', location: { first_line: 1, last_line: 1, first_column: 47, last_column: 50 }, identifierChain: [{ name: 'boo' }] },
+          { type: 'whereClause', missing: true, location: { first_line: 1, last_line: 1, first_column: 50, last_column: 50 } },
+          { type: 'limitClause', missing: true, location: { first_line: 1, last_line: 1, first_column: 50, last_column: 50 } }
+        ]
+      });
+    });
+
     it('should report locations for "SELECT * FROM testTable1 JOIN db1.table2; |"', function() {
       assertLocations({
         beforeCursor: 'SELECT * FROM testTable1 JOIN db1.table2; ',

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


+ 11 - 2
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -1413,6 +1413,15 @@ var SqlParseSupport = (function () {
       });
     };
 
+    parser.addCteAliasLocation = function (location, alias) {
+      parser.yy.locations.push({
+        type: 'alias',
+        source: 'cte',
+        alias: alias,
+        location: adjustLocationForCursor(location)
+      });
+    };
+
     parser.addUnknownLocation = function (location, identifierChain) {
       var unknownLoc = {
         type: 'unknown',
@@ -1660,8 +1669,8 @@ var SqlParseSupport = (function () {
     'suggestKeywords', 'suggestColRefKeywords', 'suggestTablesOrColumns', 'suggestFunctions', 'suggestAggregateFunctions', 'suggestAnalyticFunctions',
     'suggestColumns', 'suggestGroupBys', 'suggestOrderBys', 'suggestFilters', 'suggestKeyValues', 'suggestTables', 'addFunctionLocation',
     'addStatementLocation', 'firstDefined', 'addClauseLocation', 'addHdfsLocation', 'addDatabaseLocation', 'addColumnAliasLocation', 'addTableAliasLocation',
-    'addSubqueryAliasLocation', 'addTableLocation', 'addAsteriskLocation', 'addColumnLocation', 'addUnknownLocation', 'suggestDatabases', 'suggestHdfs',
-    'suggestValues'];
+    'addSubqueryAliasLocation', 'addTableLocation', 'addAsteriskLocation', 'addColumnLocation', 'addCteAliasLocation', 'addUnknownLocation',
+    'suggestDatabases', 'suggestHdfs', 'suggestValues'];
 
   var SYNTAX_PARSER_NOOP = function () {};
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


+ 1 - 1
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -3740,7 +3740,7 @@
           // Append table aliases
           for (var i = 0; i < allLocations.length; i++) {
             var location = allLocations[i];
-            if (location.type === 'alias' && (location.source === 'table' || location.source === 'subquery' || location.source === 'column')) {
+            if (location.type === 'alias' && (location.source === 'column' || location.source === 'table' || location.source === 'subquery' || location.source === 'cte')) {
               possibleValues.push({ name: location.alias.toLowerCase() });
             }
           }

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác