Browse Source

HUE-4659 [editor] The new autocompleter should merge columns from multiple tables when suggesting columns

Johan Ahlen 9 years ago
parent
commit
57156b8d1e

+ 65 - 16
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js

@@ -3915,16 +3915,13 @@ var prioritizeSuggestions = function () {
     delete parser.yy.result.suggestTables;
     delete parser.yy.result.suggestDatabases;
   } else if (typeof parser.yy.result.suggestColumns !== 'undefined') {
-    if (typeof parser.yy.result.suggestColumns.table === 'undefined' && typeof parser.yy.result.suggestColumns.subQuery === 'undefined') {
+    if (typeof parser.yy.result.suggestColumns.tables === 'undefined' || parser.yy.result.suggestColumns.tables.length === 0) {
       delete parser.yy.result.suggestColumns;
       delete parser.yy.result.subQueries;
     } else {
-      if (typeof parser.yy.result.suggestColumns.subQuery === 'undefined') {
-        delete parser.yy.result.subQueries;
-      }
       delete parser.yy.result.suggestTables;
       delete parser.yy.result.suggestDatabases;
-      if (typeof parser.yy.result.suggestColumns.identifierChain !== 'undefined' && parser.yy.result.suggestColumns.identifierChain.length === 0) {
+      if (typeof parser.yy.result.suggestColumns.identifierChain !== 'undefined') {
         delete parser.yy.result.suggestColumns.identifierChain;
       }
     }
@@ -4083,10 +4080,14 @@ var expandIdentifierChain = function (wrapper, anyOwner) {
       delete wrapper.identifierChain;
       return;
     } else if (tables.length === 1) {
-      if (tables[0].database) {
-        wrapper.database = tables[0].database;
+      if (wrapper.tables) {
+        wrapper.tables.push(tables[0]);
+      } else {
+        if (tables[0].database) {
+          wrapper.database = tables[0].database;
+        }
+        wrapper.table = tables[0].table;
       }
-      wrapper.table = tables[0].table;
       delete wrapper.identifierChain;
       return;
     }
@@ -4145,15 +4146,24 @@ var expandIdentifierChain = function (wrapper, anyOwner) {
   }
 
   if (tablePrimaries.length === 1) {
+    var targetTable = wrapper;
+    if (wrapper.tables) {
+      if (wrapper.identifierChain && wrapper.identifierChain.length > 0) {
+        targetTable = { identifierChain: wrapper.identifierChain };
+      } else {
+        targetTable = {};
+      }
+      wrapper.tables.push(targetTable);
+    }
     if (typeof tablePrimaries[0].identifierChain !== 'undefined') {
       if (tablePrimaries[0].identifierChain.length == 2) {
-        wrapper.database = tablePrimaries[0].identifierChain[0].name;
-        wrapper.table = tablePrimaries[0].identifierChain[1].name;
+        targetTable.database = tablePrimaries[0].identifierChain[0].name;
+        targetTable.table = tablePrimaries[0].identifierChain[1].name;
       } else {
-        wrapper.table = tablePrimaries[0].identifierChain[0].name;
+        targetTable.table = tablePrimaries[0].identifierChain[0].name;
       }
     } else if (tablePrimaries[0].subQueryAlias !== 'undefined') {
-      wrapper.subQuery = tablePrimaries[0].subQueryAlias;
+      targetTable.subQuery = tablePrimaries[0].subQueryAlias;
     }
   }
   delete wrapper.owner;
@@ -4216,6 +4226,44 @@ var filterTablePrimariesForOwner = function (owner) {
   return result;
 };
 
+var convertTablePrimariesToSuggestions = function (tablePrimaries) {
+  var tables = [];
+  var impalaIdentifiers = [];
+  tablePrimaries.forEach(function (tablePrimary) {
+    if (tablePrimary.identifierChain && tablePrimary.identifierChain.length > 0) {
+      var table = {};
+      if (tablePrimary.identifierChain.length > 1) {
+        table.database = tablePrimary.identifierChain[0].name;
+        table.table = tablePrimary.identifierChain[1].name;
+      } else {
+        table.table = tablePrimary.identifierChain[0].name;
+      }
+      if (tablePrimary.alias) {
+        table.alias = tablePrimary.alias;
+        if (isImpala()) {
+          var testForImpalaAlias = [{ name: table.alias }];
+          var result = parser.expandImpalaIdentifierChain(tablePrimaries, testForImpalaAlias);
+          if (result.length > 1) {
+            impalaIdentifiers.push({ name: table.alias + '.', type: 'alias' });
+            return;
+          }
+        }
+      }
+      tables.push(table);
+    } else if (tablePrimary.subQueryAlias) {
+      tables.push({ subQuery: tablePrimary.subQueryAlias });
+    }
+  });
+  if (impalaIdentifiers.length > 0) {
+    parser.yy.result.suggestIdentifiers = impalaIdentifiers;
+  }
+  parser.yy.result.suggestColumns.tables = tables;
+  if (parser.yy.result.suggestColumns.identifierChain && parser.yy.result.suggestColumns.identifierChain.length == 0) {
+    delete parser.yy.result.suggestColumns.identifierChain;
+  }
+  parser.yy.result.suggestColumns.linked = true;
+};
+
 var linkTablePrimaries = function () {
   if (!parser.yy.cursorFound || typeof parser.yy.latestTablePrimaries === 'undefined') {
     return;
@@ -4224,18 +4272,19 @@ var linkTablePrimaries = function () {
   var tablePrimaries = parser.yy.latestTablePrimaries;
   if (typeof parser.yy.result.suggestColumns !== 'undefined' && !parser.yy.result.suggestColumns.linked) {
     tablePrimaries = filterTablePrimariesForOwner(parser.yy.result.suggestColumns.owner);
-
+    if (!parser.yy.result.suggestColumns.tables) {
+      parser.yy.result.suggestColumns.tables = [];
+    }
     if (parser.yy.subQueries.length > 0) {
       parser.yy.result.subQueries = parser.yy.subQueries;
     }
     if (typeof parser.yy.result.suggestColumns.identifierChain === 'undefined' || parser.yy.result.suggestColumns.identifierChain.length === 0) {
       if (tablePrimaries.length > 1) {
-        suggestTablePrimariesAsIdentifiers();
-        delete parser.yy.result.suggestColumns;
+        convertTablePrimariesToSuggestions(tablePrimaries);
       } else {
         suggestLateralViewAliasesAsIdentifiers();
         if (tablePrimaries.length == 1 && (tablePrimaries[0].alias || tablePrimaries[0].subQueryAlias)) {
-          suggestTablePrimariesAsIdentifiers();
+          convertTablePrimariesToSuggestions(tablePrimaries);
         }
         expandIdentifierChain(parser.yy.result.suggestColumns);
       }

+ 65 - 16
desktop/core/src/desktop/static/desktop/js/autocomplete/sql_support.js

@@ -261,16 +261,13 @@ var prioritizeSuggestions = function () {
     delete parser.yy.result.suggestTables;
     delete parser.yy.result.suggestDatabases;
   } else if (typeof parser.yy.result.suggestColumns !== 'undefined') {
-    if (typeof parser.yy.result.suggestColumns.table === 'undefined' && typeof parser.yy.result.suggestColumns.subQuery === 'undefined') {
+    if (typeof parser.yy.result.suggestColumns.tables === 'undefined' || parser.yy.result.suggestColumns.tables.length === 0) {
       delete parser.yy.result.suggestColumns;
       delete parser.yy.result.subQueries;
     } else {
-      if (typeof parser.yy.result.suggestColumns.subQuery === 'undefined') {
-        delete parser.yy.result.subQueries;
-      }
       delete parser.yy.result.suggestTables;
       delete parser.yy.result.suggestDatabases;
-      if (typeof parser.yy.result.suggestColumns.identifierChain !== 'undefined' && parser.yy.result.suggestColumns.identifierChain.length === 0) {
+      if (typeof parser.yy.result.suggestColumns.identifierChain !== 'undefined') {
         delete parser.yy.result.suggestColumns.identifierChain;
       }
     }
@@ -429,10 +426,14 @@ var expandIdentifierChain = function (wrapper, anyOwner) {
       delete wrapper.identifierChain;
       return;
     } else if (tables.length === 1) {
-      if (tables[0].database) {
-        wrapper.database = tables[0].database;
+      if (wrapper.tables) {
+        wrapper.tables.push(tables[0]);
+      } else {
+        if (tables[0].database) {
+          wrapper.database = tables[0].database;
+        }
+        wrapper.table = tables[0].table;
       }
-      wrapper.table = tables[0].table;
       delete wrapper.identifierChain;
       return;
     }
@@ -491,15 +492,24 @@ var expandIdentifierChain = function (wrapper, anyOwner) {
   }
 
   if (tablePrimaries.length === 1) {
+    var targetTable = wrapper;
+    if (wrapper.tables) {
+      if (wrapper.identifierChain && wrapper.identifierChain.length > 0) {
+        targetTable = { identifierChain: wrapper.identifierChain };
+      } else {
+        targetTable = {};
+      }
+      wrapper.tables.push(targetTable);
+    }
     if (typeof tablePrimaries[0].identifierChain !== 'undefined') {
       if (tablePrimaries[0].identifierChain.length == 2) {
-        wrapper.database = tablePrimaries[0].identifierChain[0].name;
-        wrapper.table = tablePrimaries[0].identifierChain[1].name;
+        targetTable.database = tablePrimaries[0].identifierChain[0].name;
+        targetTable.table = tablePrimaries[0].identifierChain[1].name;
       } else {
-        wrapper.table = tablePrimaries[0].identifierChain[0].name;
+        targetTable.table = tablePrimaries[0].identifierChain[0].name;
       }
     } else if (tablePrimaries[0].subQueryAlias !== 'undefined') {
-      wrapper.subQuery = tablePrimaries[0].subQueryAlias;
+      targetTable.subQuery = tablePrimaries[0].subQueryAlias;
     }
   }
   delete wrapper.owner;
@@ -562,6 +572,44 @@ var filterTablePrimariesForOwner = function (owner) {
   return result;
 };
 
+var convertTablePrimariesToSuggestions = function (tablePrimaries) {
+  var tables = [];
+  var impalaIdentifiers = [];
+  tablePrimaries.forEach(function (tablePrimary) {
+    if (tablePrimary.identifierChain && tablePrimary.identifierChain.length > 0) {
+      var table = {};
+      if (tablePrimary.identifierChain.length > 1) {
+        table.database = tablePrimary.identifierChain[0].name;
+        table.table = tablePrimary.identifierChain[1].name;
+      } else {
+        table.table = tablePrimary.identifierChain[0].name;
+      }
+      if (tablePrimary.alias) {
+        table.alias = tablePrimary.alias;
+        if (isImpala()) {
+          var testForImpalaAlias = [{ name: table.alias }];
+          var result = parser.expandImpalaIdentifierChain(tablePrimaries, testForImpalaAlias);
+          if (result.length > 1) {
+            impalaIdentifiers.push({ name: table.alias + '.', type: 'alias' });
+            return;
+          }
+        }
+      }
+      tables.push(table);
+    } else if (tablePrimary.subQueryAlias) {
+      tables.push({ subQuery: tablePrimary.subQueryAlias });
+    }
+  });
+  if (impalaIdentifiers.length > 0) {
+    parser.yy.result.suggestIdentifiers = impalaIdentifiers;
+  }
+  parser.yy.result.suggestColumns.tables = tables;
+  if (parser.yy.result.suggestColumns.identifierChain && parser.yy.result.suggestColumns.identifierChain.length == 0) {
+    delete parser.yy.result.suggestColumns.identifierChain;
+  }
+  parser.yy.result.suggestColumns.linked = true;
+};
+
 var linkTablePrimaries = function () {
   if (!parser.yy.cursorFound || typeof parser.yy.latestTablePrimaries === 'undefined') {
     return;
@@ -570,18 +618,19 @@ var linkTablePrimaries = function () {
   var tablePrimaries = parser.yy.latestTablePrimaries;
   if (typeof parser.yy.result.suggestColumns !== 'undefined' && !parser.yy.result.suggestColumns.linked) {
     tablePrimaries = filterTablePrimariesForOwner(parser.yy.result.suggestColumns.owner);
-
+    if (!parser.yy.result.suggestColumns.tables) {
+      parser.yy.result.suggestColumns.tables = [];
+    }
     if (parser.yy.subQueries.length > 0) {
       parser.yy.result.subQueries = parser.yy.subQueries;
     }
     if (typeof parser.yy.result.suggestColumns.identifierChain === 'undefined' || parser.yy.result.suggestColumns.identifierChain.length === 0) {
       if (tablePrimaries.length > 1) {
-        suggestTablePrimariesAsIdentifiers();
-        delete parser.yy.result.suggestColumns;
+        convertTablePrimariesToSuggestions(tablePrimaries);
       } else {
         suggestLateralViewAliasesAsIdentifiers();
         if (tablePrimaries.length == 1 && (tablePrimaries[0].alias || tablePrimaries[0].subQueryAlias)) {
-          suggestTablePrimariesAsIdentifiers();
+          convertTablePrimariesToSuggestions(tablePrimaries);
         }
         expandIdentifierChain(parser.yy.result.suggestColumns);
       }

+ 58 - 26
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter2.js

@@ -58,6 +58,7 @@
 
     var deferrals = [];
     var completions = [];
+    var columnSuggestions = [];
 
     if (parseResult.suggestKeywords) {
       parseResult.suggestKeywords.forEach(function (keyword) {
@@ -155,15 +156,19 @@
       var suggestColumnsDeferral =  $.Deferred();
       if (parseResult.suggestColumns.types && parseResult.suggestColumns.types[0] === 'COLREF') {
         $.when.apply($, colRefDeferral).done(function () {
-          if (colRef !== null) {
-            deferrals.push(self.addColumns(parseResult, editor, database, [colRef.type.toUpperCase()], completions));
-          } else {
-            deferrals.push(self.addColumns(parseResult, editor, database, ['T'], completions));
-          }
+          parseResult.suggestColumns.tables.forEach(function (table) {
+            if (colRef !== null) {
+              deferrals.push(self.addColumns(parseResult, table, editor, database, [colRef.type.toUpperCase()], columnSuggestions));
+            } else {
+              deferrals.push(self.addColumns(parseResult, table, editor, database, ['T'], columnSuggestions));
+            }
+          });
           suggestColumnsDeferral.resolve();
         });
       } else {
-        deferrals.push(self.addColumns(parseResult, editor, database, parseResult.suggestColumns.types || ['T'], completions));
+        parseResult.suggestColumns.tables.forEach(function (table) {
+          deferrals.push(self.addColumns(parseResult, table, editor, database, parseResult.suggestColumns.types || ['T'], columnSuggestions));
+        });
         suggestColumnsDeferral.resolve();
       }
       if (typeof parseResult.suggestColumns.identifierChain === 'undefined' && self.snippet.type() === 'hive') {
@@ -186,6 +191,33 @@
     }
 
     $.when.apply($, deferrals).done(function () {
+      columnSuggestions.sort(function (a, b) {
+        return a.value.localeCompare(b.value);
+      });
+
+      for (var i = 0; i < columnSuggestions.length; i++) {
+        var suggestion = columnSuggestions[i];
+        if (i + 1 < columnSuggestions.length) {
+          var nextSuggestion = columnSuggestions[i + 1];
+          if (suggestion.value === nextSuggestion.value) {
+            if (suggestion.table.alias) {
+              suggestion.value = suggestion.table.alias + '.' + suggestion.value;
+            } else {
+              suggestion.value = suggestion.table.table + '.' + suggestion.value;
+            }
+            if (nextSuggestion.table.alias) {
+              nextSuggestion.value = nextSuggestion.table.alias + '.' + nextSuggestion.value;
+            } else {
+              nextSuggestion.value = nextSuggestion.table.table + '.' + nextSuggestion.value;
+            }
+          }
+        }
+        if (suggestion.table.alias && suggestion.value.indexOf(suggestion.table.alias) !== 0) {
+          suggestion.value = suggestion.table.alias + '.' + suggestion.value;
+        }
+        delete suggestion.table;
+      }
+      completions = completions.concat(columnSuggestions);
       self.finalizeCompletions(completions, callback, editor);
     });
   };
@@ -301,12 +333,12 @@
     return null;
   };
 
-  SqlAutocompleter2.prototype.addColumns = function (parseResult, editor, database, types, completions) {
+  SqlAutocompleter2.prototype.addColumns = function (parseResult, table, editor, database, types, columnSuggestions) {
     var self = this;
     var addColumnsDeferred = $.Deferred();
 
-    if (parseResult.suggestColumns.subQuery && !parseResult.suggestColumns.identifierChain) {
-      var foundSubQuery = self.locateSubQuery(parseResult.subQueries, parseResult.suggestColumns.subQuery);
+    if (table.subQuery && !table.identifierChain) {
+      var foundSubQuery = self.locateSubQuery(parseResult.subQueries, table.subQuery);
 
       var addSubQueryColumns = function (subQueryColumns) {
         subQueryColumns.forEach(function (column) {
@@ -314,9 +346,9 @@
             // TODO: Potentially fetch column types for sub-queries, possible performance hit.
             var type = typeof column.type !== 'undefined' && column.type !== 'COLREF' ? column.type : 'T';
             if (column.alias) {
-              completions.push({value: self.backTickIfNeeded(column.alias), meta: type, weight: DEFAULT_WEIGHTS.COLUMN})
+              columnSuggestions.push({value: self.backTickIfNeeded(column.alias), meta: type, weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             } else if (column.identifierChain && column.identifierChain.length === 1) {
-              completions.push({value: self.backTickIfNeeded(column.identifierChain[0].name), meta: type, weight: DEFAULT_WEIGHTS.COLUMN})
+              columnSuggestions.push({value: self.backTickIfNeeded(column.identifierChain[0].name), meta: type, weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             }
             addColumnsDeferred.resolve();
             return addColumnsDeferred;
@@ -336,58 +368,58 @@
         if (data.extended_columns) {
           data.extended_columns.forEach(function (column) {
             if (column.type.indexOf('map') === 0 && self.snippet.type() === 'hive') {
-              completions.push({value: self.backTickIfNeeded(column.name) + '[]', meta: 'map', weight: DEFAULT_WEIGHTS.COLUMN})
+              columnSuggestions.push({value: self.backTickIfNeeded(column.name) + '[]', meta: 'map', weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             } else if (column.type.indexOf('map') === 0) {
-              completions.push({value: self.backTickIfNeeded(column.name), meta: 'map', weight: DEFAULT_WEIGHTS.COLUMN})
+              columnSuggestions.push({value: self.backTickIfNeeded(column.name), meta: 'map', weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             } else if (column.type.indexOf('struct') === 0) {
-              completions.push({value: self.backTickIfNeeded(column.name), meta: 'struct', weight: DEFAULT_WEIGHTS.COLUMN})
+              columnSuggestions.push({value: self.backTickIfNeeded(column.name), meta: 'struct', weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             } else if (column.type.indexOf('array') === 0 && self.snippet.type() === 'hive') {
-              completions.push({value: self.backTickIfNeeded(column.name) + '[]', meta: 'array', weight: DEFAULT_WEIGHTS.COLUMN})
+              columnSuggestions.push({value: self.backTickIfNeeded(column.name) + '[]', meta: 'array', weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             } else if (column.type.indexOf('array') === 0) {
-              completions.push({value: self.backTickIfNeeded(column.name), meta: 'array', weight: DEFAULT_WEIGHTS.COLUMN})
+              columnSuggestions.push({value: self.backTickIfNeeded(column.name), meta: 'array', weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             } else if (sqlFunctions.matchesType(self.snippet.type(), types, [column.type.toUpperCase()]) ||
                 sqlFunctions.matchesType(self.snippet.type(), [column.type.toUpperCase()], types)) {
-              completions.push({value: self.backTickIfNeeded(column.name), meta: column.type, weight: DEFAULT_WEIGHTS.COLUMN})
+              columnSuggestions.push({value: self.backTickIfNeeded(column.name), meta: column.type, weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             }
           });
         } else if (data.columns) {
           data.columns.forEach(function (column) {
-            completions.push({value: self.backTickIfNeeded(column), meta: 'column', weight: DEFAULT_WEIGHTS.COLUMN})
+            columnSuggestions.push({value: self.backTickIfNeeded(column), meta: 'column', weight: DEFAULT_WEIGHTS.COLUMN, table: table })
           });
         }
         if (data.type === 'map' && self.snippet.type() === 'impala') {
-          completions.push({value: 'key', meta: 'key', weight: DEFAULT_WEIGHTS.COLUMN});
-          completions.push({value: 'value', meta: 'value', weight: DEFAULT_WEIGHTS.COLUMN});
+          columnSuggestions.push({value: 'key', meta: 'key', weight: DEFAULT_WEIGHTS.COLUMN, table: table });
+          columnSuggestions.push({value: 'value', meta: 'value', weight: DEFAULT_WEIGHTS.COLUMN, table: table });
         }
         if (data.type === 'struct') {
           data.fields.forEach(function (field) {
-            completions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN})
+            columnSuggestions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN, table: table })
           });
         } else if (data.type === 'map' && (data.value && data.value.fields)) {
           data.value.fields.forEach(function (field) {
             if (sqlFunctions.matchesType(self.snippet.type(), types, [field.type.toUpperCase()]) ||
                 sqlFunctions.matchesType(self.snippet.type(), [column.type.toUpperCase()], types)) {
-              completions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN});
+              columnSuggestions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN, table: table });
             }
           });
         } else if (data.type === 'array' && (data.item && data.item.fields)) {
           data.item.fields.forEach(function (field) {
             if ((field.type === 'array' || field.type === 'map')) {
               if (self.snippet.type() === 'hive') {
-                completions.push({value: self.backTickIfNeeded(field.name) + '[]', meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN});
+                columnSuggestions.push({value: self.backTickIfNeeded(field.name) + '[]', meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN, table: table });
               } else {
-                completions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN});
+                columnSuggestions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN, table: table });
               }
             } else if (sqlFunctions.matchesType(self.snippet.type(), types, [field.type.toUpperCase()]) ||
                 sqlFunctions.matchesType(self.snippet.type(), [column.type.toUpperCase()], types)) {
-              completions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN});
+              columnSuggestions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN, table: table });
             }
           });
         }
         addColumnsDeferred.resolve();
       };
 
-      self.fetchFieldsForIdentifiers(editor, parseResult.suggestColumns.table, parseResult.suggestColumns.database || database, parseResult.suggestColumns.identifierChain, callback, addColumnsDeferred.resolve);
+      self.fetchFieldsForIdentifiers(editor, table.table, table.database || database, table.identifierChain, callback, addColumnsDeferred.resolve);
     }
     return addColumnsDeferred;
   };

+ 21 - 21
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecAlter.js

@@ -325,8 +325,8 @@ define([
             dialect: 'hive',
             hasLocations: true,
             expectedResult: {
-              lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] },
+              lowerCase: false
             }
           });
         });
@@ -339,7 +339,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -391,7 +391,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' },
+              suggestColumns: { tables: [{ table: 'bar' }] },
               suggestKeywords: ['COLUMN']
             }
           });
@@ -444,7 +444,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar'}
+              suggestColumns: { tables: [{ table: 'bar'}] }
             }
           });
         });
@@ -457,7 +457,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar'}
+              suggestColumns: { tables: [{ table: 'bar'}] }
             }
           });
         });
@@ -509,7 +509,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -522,7 +522,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -574,7 +574,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { database: 'foo', table: 'bar' }
+              suggestColumns: { tables: [{ database: 'foo', table: 'bar' }] }
             }
           });
         });
@@ -653,7 +653,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -864,7 +864,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' },
+              suggestColumns: { tables: [{ table: 'bar' }] },
               suggestKeywords: ['COLUMN']
             }
           });
@@ -930,7 +930,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar'}
+              suggestColumns: { tables: [{ table: 'bar'}] }
             }
           });
         });
@@ -943,7 +943,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar'}
+              suggestColumns: { tables: [{ table: 'bar'}] }
             }
           });
         });
@@ -1281,7 +1281,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -1294,7 +1294,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -1320,7 +1320,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -1333,7 +1333,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { database: 'foo', table: 'bar' }
+              suggestColumns: { tables: [{ database: 'foo', table: 'bar' }] }
             }
           });
         });
@@ -1519,7 +1519,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -1532,7 +1532,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });
@@ -1558,7 +1558,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' },
+              suggestColumns: { tables: [{ table: 'bar' }] },
               suggestKeywords: ['COLUMN', 'PARTITION']
             }
           });
@@ -1573,7 +1573,7 @@ define([
             hasLocations: true,
             expectedResult: {
               lowerCase: false,
-              suggestColumns: { table: 'bar' }
+              suggestColumns: { tables: [{ table: 'bar' }] }
             }
           });
         });

+ 4 - 4
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecCreate.js

@@ -735,7 +735,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { database: 'foo', table: 'bar' }
+            suggestColumns: { tables: [{ database: 'foo', table: 'bar' }] }
           }
         });
       });
@@ -748,7 +748,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { database: 'foo', table: 'bar' }
+            suggestColumns: { tables: [{ database: 'foo', table: 'bar' }] }
           }
         });
       });
@@ -2268,7 +2268,7 @@ define([
             suggestAggregateFunctions: true,
             suggestAnalyticFunctions: true,
             suggestFunctions: {},
-            suggestColumns: { table: 'tableOne' },
+            suggestColumns: { tables: [{ table: 'tableOne' }] },
             suggestKeywords: ['*']
           }
         });
@@ -2354,7 +2354,7 @@ define([
               suggestAggregateFunctions: true,
               suggestAnalyticFunctions: true,
               suggestFunctions: {},
-              suggestColumns: { table: 'tableOne' },
+              suggestColumns: { tables: [{ table: 'tableOne' }] },
               suggestKeywords: ['*']
             }
           });

+ 4 - 17
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecDescribe.js

@@ -241,10 +241,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: {
-              table: 'tbl',
-              database: 'db'
-            }
+            suggestColumns: { tables: [{ table: 'tbl', database: 'db' }] }
           }
         });
       });
@@ -382,10 +379,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: {
-              database: 'db',
-              table: 'tbl'
-            }
+            suggestColumns: { tables: [{ database: 'db', table: 'tbl' }] }
           }
         });
       });
@@ -425,10 +419,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: {
-              database: 'db',
-              table: 'tbl'
-            }
+            suggestColumns: { tables: [{ database: 'db', table: 'tbl' }] }
           }
         });
       });
@@ -441,11 +432,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: {
-              identifierChain: [{ name: 'col' }],
-              database: 'db',
-              table: 'tbl'
-            }
+            suggestColumns: { tables: [{ identifierChain: [{ name: 'col' }], database: 'db', table: 'tbl' }] }
           }
         });
       });

+ 3 - 3
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecError.js

@@ -38,7 +38,7 @@ define([
         expectedResult: {
           lowerCase: false,
           suggestFunctions: {},
-          suggestColumns: { table: 'testTable' }
+          suggestColumns: { tables: [{ table: 'testTable' }] }
         }
       });
     });
@@ -51,7 +51,7 @@ define([
         expectedResult: {
           lowerCase: false,
           suggestFunctions: {},
-          suggestColumns: { table: 'testTable' }
+          suggestColumns: { tables: [{ table: 'testTable' }] }
         }
       });
     });
@@ -64,7 +64,7 @@ define([
         expectedResult: {
           lowerCase: false,
           suggestFunctions: {},
-          suggestColumns: { table: 'testTable' }
+          suggestColumns: { tables: [{ table: 'testTable' }] }
         }
       });
     });

+ 10 - 10
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecInsert.js

@@ -311,7 +311,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { table: 'baa' }
+            suggestColumns: { tables: [{ table: 'baa' }] }
           }
         });
       });
@@ -324,7 +324,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { table: 'baa' }
+            suggestColumns: { tables: [{ table: 'baa' }] }
           }
         });
       });
@@ -356,7 +356,7 @@ define([
             suggestFunctions: {},
             suggestAggregateFunctions: true,
             suggestAnalyticFunctions: true,
-            suggestColumns: { table: 'boo', database: 'baa' }
+            suggestColumns: { tables: [{ table: 'boo', database: 'baa' }] }
           }
         });
       });
@@ -373,7 +373,7 @@ define([
             suggestFunctions: {},
             suggestAggregateFunctions: true,
             suggestAnalyticFunctions: true,
-            suggestColumns: { table: 'boo', database: 'baa' }
+            suggestColumns: { tables: [{ table: 'boo', database: 'baa' }] }
           }
         });
       });
@@ -431,7 +431,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { table: 'ble', database: 'bla' }
+            suggestColumns: { tables: [{ table: 'ble', database: 'bla' }] }
           }
         });
       });
@@ -505,7 +505,7 @@ define([
             suggestFunctions: {},
             suggestAggregateFunctions: true,
             suggestAnalyticFunctions: true,
-            suggestColumns: { table: 'boo', database: 'baa' }
+            suggestColumns: { tables: [{ table: 'boo', database: 'baa' }] }
           }
         });
       });
@@ -557,7 +557,7 @@ define([
             suggestFunctions: {},
             suggestAggregateFunctions: true,
             suggestAnalyticFunctions: true,
-            suggestColumns: { table: 'boo', database: 'baa' }
+            suggestColumns: { tables: [{ table: 'boo', database: 'baa' }] }
           }
         });
       });
@@ -642,7 +642,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { table: 'baa' }
+            suggestColumns: { tables: [{ table: 'baa' }] }
           }
         });
       });
@@ -655,7 +655,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { table: 'baa' }
+            suggestColumns: { tables: [{ table: 'baa' }] }
           }
         });
       });
@@ -763,7 +763,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { table: 'ble', database: 'bla' }
+            suggestColumns: { tables: [{ table: 'ble', database: 'bla' }] }
           }
         });
       });

+ 2 - 2
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecLoad.js

@@ -148,7 +148,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { table: 'boo' }
+            suggestColumns: { tables: [{ table: 'boo' }] }
           }
         });
       });
@@ -313,7 +313,7 @@ define([
           hasLocations: true,
           expectedResult: {
             lowerCase: false,
-            suggestColumns: { table: 'baa', database: 'boo' }
+            suggestColumns: { tables: [{ table: 'baa', database: 'boo' }] }
           }
         });
       });

File diff suppressed because it is too large
+ 98 - 222
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecSelect.js


+ 5 - 17
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecUpdate.js

@@ -146,10 +146,7 @@ define([
         afterCursor: '',
         expectedResult: {
           lowerCase: false,
-          suggestColumns: {
-            database: 'bar',
-            table: 'foo'
-          },
+          suggestColumns: { tables: [{ database: 'bar', table: 'foo' }] },
           locations: [
             {type: 'table', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15}, database: 'bar', table: 'foo'}
           ]
@@ -163,10 +160,7 @@ define([
         afterCursor: '',
         expectedResult: {
           lowerCase: false,
-          suggestColumns: {
-            database: 'bar',
-            table: 'foo'
-          },
+          suggestColumns: { tables: [{ database: 'bar', table: 'foo' }] },
           locations: [
             {type: 'table', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15}, database: 'bar', table: 'foo'},
             {type: 'column', location: { first_line: 1, last_line: 1, first_column: 20, last_column: 22}, database: 'bar', table: 'foo', identifierChain: [{ name: 'id' }]},
@@ -183,10 +177,7 @@ define([
         expectedResult: {
           lowerCase: false,
           suggestFunctions: {},
-          suggestColumns: {
-            database: 'bar',
-            table: 'foo'
-          },
+          suggestColumns: { tables: [{ database: 'bar', table: 'foo' }] },
           suggestKeywords: ['EXISTS', 'NOT EXISTS'],
           locations: [
             {type: 'table', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15}, database: 'bar', table: 'foo'},
@@ -210,7 +201,7 @@ define([
             table: 'foo',
             identifierChain: [{ name: 'id' }]
           },
-          suggestColumns : { types: ['COLREF'] , database: 'bar', table: 'foo' },
+          suggestColumns: { types: ['COLREF'], tables: [{ database: 'bar', table: 'foo' }] },
           locations: [
             {type: 'table', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15 }, database:'bar', table: 'foo'},
             {type: 'column', location: { first_line: 1, last_line: 1, first_column: 20, last_column: 23 }, identifierChain: [{ name: 'bla'}], database: 'bar', table: 'foo'},
@@ -230,10 +221,7 @@ define([
         expectedResult: {
           lowerCase: false,
           suggestFunctions: {},
-          suggestColumns: {
-            database: 'bar',
-            table: 'foo'
-          },
+          suggestColumns: { tables: [{ database: 'bar', table: 'foo' }] },
           locations: [
             {type: 'table', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15 }, database:'bar', table: 'foo'},
             {type: 'column', location: { first_line: 1, last_line: 1, first_column: 20, last_column: 23 }, identifierChain: [{ name: 'bla'}], database: 'bar', table: 'foo'},

Some files were not shown because too many files changed in this diff