Răsfoiți Sursa

HUE-7551 [autocomplete] Fix issue where suggestions are missing when there's no alias for a complex reference

Johan Ahlen 8 ani în urmă
părinte
comite
6417a999b2

+ 13 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpec.js

@@ -684,6 +684,19 @@
         expect(actual).toEqual([{ name: 't' }, { name: 'testMap' }]);
       });
 
+      it('should expand a simple map reference without alias', function () {
+        var tablePrimaries = [
+          { alias: 't', identifierChain: [{ name: 'testTable' }] },
+          { identifierChain: [{ name: 't' }, { name: 'testMap' }] }
+        ];
+
+        var identifierChain = [{ name: 'testMap' }];
+
+        var actual = sqlAutocompleteParser.expandImpalaIdentifierChain(tablePrimaries, identifierChain);
+
+        expect(actual).toEqual([{ name: 't' }, { name: 'testMap' }]);
+      });
+
       it('should not expand without map reference', function () {
         var tablePrimaries = [
           { alias: 't1', identifierChain: [{ name: 'databaseTwo' }, { name: 'testTable1' }] },

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

@@ -3382,6 +3382,19 @@
         });
       });
 
+      it('should suggest columns for "SELECT testMap.| FROM testTable t, t.testMap;"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SELECT testMap.',
+          afterCursor: ' FROM testTable t, t.testMap;',
+          dialect: 'impala',
+          expectedResult: {
+            suggestKeywords: ['*'],
+            lowerCase: false,
+            suggestColumns: { source: 'select', identifierChain: [{ name: 'testMap' }], tables: [{ identifierChain: [{ name: 'testTable' }] }] }
+          }
+        });
+      });
+
       it('should suggest columns for "SELECT tm.a| FROM testTable t, t.testMap tm;"', function() {
         assertAutoComplete({
           beforeCursor: 'SELECT tm.a',

+ 5 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -715,7 +715,11 @@ var SqlParseSupport = (function () {
       }
       var expand = function (identifier, expandedChain) {
         var foundPrimary = tablePrimaries.filter(function (tablePrimary) {
-          return equalIgnoreCase(tablePrimary.alias, identifier);
+          var primaryIdentifier = tablePrimary.alias;
+          if (!primaryIdentifier && tablePrimary.identifierChain && tablePrimary.identifierChain.length > 0) {
+            primaryIdentifier = tablePrimary.identifierChain[tablePrimary.identifierChain.length - 1].name;
+          }
+          return equalIgnoreCase(primaryIdentifier, identifier);
         });
 
         if (foundPrimary.length === 1 && foundPrimary[0].identifierChain) {

+ 4 - 0
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter3.js

@@ -1874,6 +1874,10 @@ var SqlAutocompleter3 = (function () {
     try {
       parseResult = self.parseActiveStatement();
 
+      if (typeof hueDebug !== 'undefined' && hueDebug.showParseResult) {
+        console.log(parseResult);
+      }
+
       // This could happen in case the user is editing at the borders of the statement and the locations haven't
       // been updated yet, in that case we have to force a location update before parsing
       if (!parseResult) {