Przeglądaj źródła

HUE-6201 [autocomplete] Fix location type for complex columns

Johan Ahlen 8 lat temu
rodzic
commit
51aafc2

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/aceSqlWorker.js

@@ -14,7 +14,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-var version = 16;
+var version = 17;
 importScripts('/static/desktop/js/autocomplete/sqlParseSupport.js?version=' + version);
 importScripts('/static/desktop/js/autocomplete/sql.js?version=' + version);
 importScripts('/static/desktop/js/sqlFunctions.js?version=' + version);

+ 6 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -322,6 +322,12 @@ var SqlParseSupport = (function () {
             if (found.length > 0) {
               if (found[0].identifierChain.length > 1 && location.identifierChain.length === 1 && found[0].identifierChain[0].name === location.identifierChain[0].name) {
                 location.type = 'database';
+              } else if (found[0].alias && location.identifierChain[0].name === found[0].alias && location.identifierChain.length > 1) {
+                location.type = 'column';
+                parser.expandIdentifierChain(location, true);
+              } else if (!found[0].alias && found[0].identifierChain && location.identifierChain[0].name === found[0].identifierChain[found[0].identifierChain.length - 1].name && location.identifierChain.length > 1) {
+                location.type = 'column';
+                parser.expandIdentifierChain(location, true);
               } else {
                 location.type = 'table';
                 parser.expandIdentifierChain(location, true);

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

@@ -467,6 +467,51 @@
         });
       });
 
+      it('should report locations for "SELECT tbl.col FROM some_tbl tbl;"', function() {
+        assertLocations({
+          dialect: 'hive',
+          beforeCursor: 'SELECT tbl.col FROM some_tbl tbl;',
+          afterCursor: '',
+          expectedLocations: [
+            { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 33 } },
+            { type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11 }, identifierChain: [{ name: 'some_tbl' }] },
+            { type: 'column', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15 }, identifierChain: [{ name: 'col' }], tables: [{ identifierChain: [{ name: 'some_tbl' }], alias: 'tbl' }] },
+            { type: 'table', location: { first_line: 1, last_line: 1, first_column: 21, last_column: 29 }, identifierChain: [{ name: 'some_tbl' }] }
+          ]
+        });
+      });
+
+      it('should report locations for "SELECT tbl.col.cplx FROM some_tbl tbl;"', function() {
+        assertLocations({
+          dialect: 'hive',
+          beforeCursor: 'SELECT tbl.col.cplx FROM some_tbl tbl;',
+          afterCursor: '',
+          expectedLocations: [
+            { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 38 } },
+            { type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11 }, identifierChain: [{ name: 'some_tbl' }] },
+            { type: 'column', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15 }, identifierChain: [{ name: 'col' }], tables: [{ identifierChain: [{ name: 'some_tbl' }], alias: 'tbl' }] },
+            { type: 'column', location: { first_line: 1, last_line: 1, first_column: 16, last_column: 20 }, identifierChain: [{ name: 'col' }, { name: 'cplx' }], tables: [{ identifierChain: [{ name: 'some_tbl' }], alias: 'tbl' }] },
+            { type: 'table', location: { first_line: 1, last_line: 1, first_column: 26, last_column: 34 }, identifierChain: [{ name: 'some_tbl' }] }
+          ]
+        });
+      });
+
+      it('should report locations for "SELECT some_tbl.col.cplx FROM some_tbl;"', function() {
+        assertLocations({
+          dialect: 'hive',
+          beforeCursor: 'SELECT some_tbl.col.cplx FROM some_tbl;',
+          afterCursor: '',
+          expectedLocations: [
+            { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 39 } },
+            { type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 16 }, identifierChain: [{ name: 'some_tbl' }] },
+            { type: 'column', location: { first_line: 1, last_line: 1, first_column: 17, last_column: 20 }, identifierChain: [{ name: 'col' }], tables: [{ identifierChain: [{ name: 'some_tbl' }] }] },
+            { type: 'column', location: { first_line: 1, last_line: 1, first_column: 21, last_column: 25 }, identifierChain: [{ name: 'col' }, { name: 'cplx' }], tables: [{ identifierChain: [{ name: 'some_tbl' }] }] },
+            { type: 'table', location: { first_line: 1, last_line: 1, first_column: 31, last_column: 39 }, identifierChain: [{ name: 'some_tbl' }] }
+          ]
+        });
+      });
+
+
       it('should report locations for "SELECT testTableB.a, cos(1), tta.abcdefg|hijk, tta.bla, cos(1) FROM testTableA tta, testTableB;"', function() {
         assertLocations({
           dialect: 'hive',