Explorar o código

HUE-8549 [autocomplete] Improve CTE alias suggestions when there's a trailing ";"

Johan Ahlen %!s(int64=7) %!d(string=hai) anos
pai
achega
894f6b3

+ 29 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecSelect.js

@@ -6435,6 +6435,35 @@
           }
         });
       });
+
+      it('should suggest keywords for "with s as (select * from foo join bar) select * from |"', function () {
+        assertAutoComplete({
+          beforeCursor: 'with s as (select * from foo join bar) select * from ',
+          afterCursor: '',
+          expectedResult: {
+            lowerCase: true,
+            suggestTables: {},
+            suggestDatabases: { appendDot: true },
+            commonTableExpressions: [{ columns: [{ tables: [{ identifierChain: [{ name: 'foo' }] }, { identifierChain: [{ name: 'bar' }] }] }], alias: 's' }],
+            suggestCommonTableExpressions: [{ name: 's' }]
+          }
+        });
+      });
+
+      it('should suggest keywords for "with s as (select * from foo join bar) select * from |;', function () {
+        assertAutoComplete({
+          beforeCursor: 'with s as (select * from foo join bar) select * from ',
+          afterCursor: ';',
+          expectedResult: {
+            lowerCase: true,
+            suggestTables: {},
+            suggestDatabases: { appendDot: true },
+            commonTableExpressions: [{ columns: [{ tables: [{ identifierChain: [{ name: 'foo' }] }, { identifierChain: [{ name: 'bar' }] }] }], alias: 's' }],
+            suggestCommonTableExpressions: [{ name: 's' }]
+          }
+        });
+      });
+
     });
 
     describe('Joins', function() {

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

@@ -702,9 +702,9 @@ var SqlParseSupport = (function () {
         }
       }
 
-      if (typeof parser.yy.result.suggestTables !== 'undefined' && typeof parser.yy.latestCommonTableExpressions !== 'undefined') {
+      if (typeof parser.yy.result.suggestTables !== 'undefined' && typeof parser.yy.result.commonTableExpressions !== 'undefined') {
         var ctes = [];
-        parser.yy.latestCommonTableExpressions.forEach(function (cte) {
+        parser.yy.result.commonTableExpressions.forEach(function (cte) {
           var suggestion = {name: cte.alias};
           if (parser.yy.result.suggestTables.prependFrom) {
             suggestion.prependFrom = true