Explorar o código

[core] Support nested lateral view references

This adds support for references to lateral views in the arguments of a lateral view function.
Johan Ahlen %!s(int64=10) %!d(string=hai) anos
pai
achega
0423bcb

+ 18 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete.js

@@ -138,7 +138,24 @@ Autocompleter.prototype.getViewReferenceIndex = function (statement) {
     }
   }
 
-  // TODO: Support view references from views. (expand result values using result, limit steps to prevent infinite refs)
+  // Expand any references in paths of references
+  var foundRef = false;
+  // Limit iterations to 10
+  for (var i = 0; i < 10 && (i == 0 || foundRef); i++) {
+    $.each(result.index, function(alias, value) {
+      var newLeadingPath = [];
+      $.each(value.leadingPath, function(index, path) {
+        if (result.index[path]) {
+          foundRef = true;
+          newLeadingPath = newLeadingPath.concat(result.index[path].leadingPath);
+          newLeadingPath.push(result.index[path].addition);
+        } else {
+          newLeadingPath.push(path);
+        }
+      });
+      value.leadingPath = newLeadingPath;
+    });
+  }
 
   return result;
 };

+ 20 - 0
desktop/core/src/desktop/static/desktop/spec/autocompleteSpec.js

@@ -381,6 +381,26 @@ describe("autocomplete.js", function() {
         });
       });
 
+      it("should suggest structs from exploded item references to exploded item references to arrays ", function () {
+        assertAutoComplete({
+          serverResponses: {
+            "/testApp/api/autocomplete/testDb/testTable/testArray1/item/testArray2/item": {
+              fields: [
+                {"type": "string", "name": "fieldA"},
+                {"type": "string", "name": "fieldB"}
+              ],
+              type: "struct"
+            }
+          },
+          beforeCursor: "SELECT ta2_exp.",
+          afterCursor: " FROM " +
+          "   testTable tt" +
+          " LATERAL VIEW explode(tt.testArray1) ta1 AS ta1_exp " +
+          " LATERAL VIEW explode(ta1_exp.testArray2) ta2 AS ta2_exp",
+          expectedSuggestions: ["fieldA", "fieldB"]
+        });
+      });
+
       it("should suggest structs from references to exploded arrays", function () {
         assertAutoComplete({
           serverResponses: {