浏览代码

[core] Support multiple exploded lateral views

This fixes an issue where just one exploded lateral view was supported.
Johan Ahlen 10 年之前
父节点
当前提交
68c50c2

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

@@ -90,7 +90,7 @@ Autocompleter.prototype.getViewReferenceIndex = function (statement) {
   //           map key reference (if group 5 is exists)
   // group 5 = array value (if posexplode)
   //           map value reference (if ! posexplode)
-  var lateralViewRegex = /.*LATERAL\s+VIEW\s+(pos)?explode\(([^\)]+)\)\s+(?:(\S+)\s+)?AS \(?([^ ,\)]*)(?:\s*,\s*([^ ,\)]*))?/gi;
+  var lateralViewRegex = /LATERAL\s+VIEW\s+(pos)?explode\(([^\)]+)\)\s+(?:(\S+)\s+)?AS \(?([^ ,\)]*)(?:\s*,\s*([^ ,]*)\))?/gi;
   var lateralViewMatch;
 
   while (lateralViewMatch = lateralViewRegex.exec(statement)) {

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

@@ -343,6 +343,41 @@ describe("autocomplete.js", function() {
         });
       });
 
+      it("should suggest structs from multiple exploded item references to arrays", function () {
+        assertAutoComplete({
+          serverResponses: {
+            "/testApp/api/autocomplete/testDb/testTable/testArrayA/item": {
+              fields: [
+                {"type": "string", "name": "fieldA"},
+                {"type": "string", "name": "fieldB"}
+              ],
+              type: "struct"
+            }
+          },
+          beforeCursor: "SELECT testItemA.",
+          afterCursor: " FROM testTable " +
+                       " LATERAL VIEW explode(testArrayA) explodedTableA AS testItemA," +
+                       " LATERAL VIEW explode(testArrayB) explodedTableB AS testItemB",
+          expectedSuggestions: ["fieldA", "fieldB"]
+        });
+        assertAutoComplete({
+          serverResponses: {
+            "/testApp/api/autocomplete/testDb/testTable/testArrayB/item": {
+              fields: [
+                {"type": "string", "name": "fieldA"},
+                {"type": "string", "name": "fieldB"}
+              ],
+              type: "struct"
+            }
+          },
+          beforeCursor: "SELECT testItemB.",
+          afterCursor: " FROM testTable " +
+          " LATERAL VIEW explode(testArrayA) explodedTableA AS testItemA," +
+          " LATERAL VIEW explode(testArrayB) explodedTableB AS testItemB",
+          expectedSuggestions: ["fieldA", "fieldB"]
+        });
+      });
+
       it("should suggest structs from references to exploded arrays", function () {
         assertAutoComplete({
           serverResponses: {