Pārlūkot izejas kodu

HUE-6403 [editor] Show the correct context popover for complex types

Johan Ahlen 8 gadi atpakaļ
vecāks
revīzija
9574e20

+ 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 = 17;
+var version = 18;
 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);

+ 17 - 0
desktop/core/src/desktop/templates/sql_context_popover.mako

@@ -1140,6 +1140,23 @@ from metadata.conf import has_navigator
         self.isAsterisk = params.data.type === 'asterisk';
         self.isView = params.data.type === 'view';
 
+        if ((self.isColumn || self.isComplex) && self.data.tables && self.data.tables.length > 0) {
+          var identifierChain = self.data.identifierChain;
+          var foundTable = $.grep(self.data.tables, function (table) {
+            return (table.alias && table.alias === identifierChain[0].name) ||
+                    (table.identifierChain && table.identifierChain[table.identifierChain.length - 1].name === identifierChain[0].name);
+          });
+          if (foundTable.length === 1 && foundTable.identifierChain) {
+            identifierChain.shift();
+            identifierChain = foundTable.identifierChain.concat(identifierChain);
+            delete self.data.tables;
+          } else if (self.data.tables.length === 1 && self.data.tables[0].identifierChain) {
+            identifierChain = self.data.tables[0].identifierChain.concat(identifierChain);
+            delete self.data.tables;
+          }
+          self.data.identifierChain = identifierChain
+        }
+
         self.pinEnabled = params.pinEnabled && !self.isFunction && !self.isAsterisk && !self.isHdfs;
 
         if (self.isDatabase) {