Browse Source

HUE-2852 [core] Support autocomplete of struct types from map values in hive mode

Johan Ahlen 10 years ago
parent
commit
a4dd046

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

@@ -224,7 +224,17 @@ Autocompleter.prototype.autocomplete = function(beforeCursor, afterCursor, callb
     var url = self.options.baseUrl + self.currentDb + "/" + tableName;
     $.each(parts, function(index, part) {
       if (part != '' && (index > 0 || part !== tableName)) {
-        url += "/" + part;
+        url += "/";
+        if (self.currentMode === "hive") {
+          var mapMatch = part.match(/([^\[]*)\[[^\]]+\]$/i);
+          if (mapMatch !== null) {
+            url += mapMatch[1] + "/value"
+          } else {
+            url += part;
+          }
+        } else {
+          url += part;
+        }
       }
     });
 

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

@@ -151,7 +151,82 @@ describe("autocomplete.js", function() {
         expectedSuggestions: ["testTable1", "testTable2"]
       });
     });
+  });
+
+  describe("hive-specific stuff", function() {
+    beforeEach(function() {
+      var options = {
+        baseUrl: "http://baseUrl/",
+        app: "testApp",
+        user: "testUser",
+        db: "testDb",
+        mode: "hive"
+      };
+      subject = new Autocompleter(options);
+      ajaxHelper.responseForUrls = {};
+    });
+
+    it("should suggest struct from map values", function() {
+      assertAutoComplete({
+        serverResponses: {
+          "http://baseUrl/testDb/testTable/testMap/value" : {
+            fields: [
+              {"type": "string", "name": "fieldA" },
+              {"type": "string", "name": "fieldB" },
+              {"type": "struct",  "name": "fieldC", "fields": [
+                {"type": "string", "name": "fieldC_A" },
+                {"type": "boolean", "name": "fieldC_B"}
+              ]}],
+            type: "struct"
+          }
+        },
+        beforeCursor: "SELECT testMap[\"anyKey\"].",
+        afterCursor: " FROM testTable",
+        expectedSuggestions: ["fieldA", "fieldB", "fieldC"]
+      });
+    });
+
+    it("should suggest struct from structs from map values", function() {
+      assertAutoComplete({
+        serverResponses: {
+          "http://baseUrl/testDb/testTable/testMap/value/fieldC" : {
+            fields: [
+              {"type": "string", "name": "fieldC_A" },
+              {"type": "boolean", "name": "fieldC_B"}
+            ],
+            type: "struct"
+          }
+        },
+        beforeCursor: "SELECT testMap[\"anyKey\"].fieldC.",
+        afterCursor: " FROM testTable",
+        expectedSuggestions: ["fieldC_A", "fieldC_B"]
+      });
+    });
+  });
+
+  describe("impala-specific stuff", function() {
+    beforeEach(function () {
+      var options = {
+        baseUrl: "http://baseUrl/",
+        app: "testApp",
+        user: "testUser",
+        db: "testDb",
+        mode: "impala"
+      };
+      subject = new Autocompleter(options);
+      ajaxHelper.responseForUrls = {};
+    });
 
+    it("should not suggest struct from map values with hive style syntax", function() {
+      assertAutoComplete({
+        serverResponses: {
+          "http://baseUrl/testDb/testTable/testMap[\"anyKey\"]" : {}
+        },
+        beforeCursor: "SELECT testMap[\"anyKey\"].",
+        afterCursor: " FROM testTable",
+        expectedSuggestions: []
+      });
+    });
   });
 
   describe("field completion", function() {