You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/01/26 22:18:55 UTC

[GitHub] [incubator-pinot] siddharthteotia commented on a change in pull request #6490: Adding scalar function JsonPathArray to extract arrays from json

siddharthteotia commented on a change in pull request #6490:
URL: https://github.com/apache/incubator-pinot/pull/6490#discussion_r564872686



##########
File path: pinot-common/src/test/java/org/apache/pinot/common/function/JsonFunctionsTest.java
##########
@@ -65,4 +65,42 @@ public void testJsonFunction()
     assertEquals(JsonFunctions.jsonPathDouble(jsonString, "$.actor.aaa", 53.2), 53.2);
   }
 
+  @Test
+  public void testJsonFunctionExtractingArray()
+      throws JsonProcessingException {
+    String jsonString = "{\n" +
+        "    \"name\": \"Pete\",\n" +
+        "    \"age\": 24,\n" +
+        "    \"subjects\": [\n" +
+        "        {\n" +
+        "            \"name\": \"maths\",\n" +
+        "        \"grade\": \"A\"\n" +
+        "        },\n" +
+        "        {\n" +
+        "            \"name\": \"maths\",\n" +
+        "        \"grade\": \"B\"\n" +
+        "        }\n" +
+        "    ]\n" +
+        "}";
+    assertEquals(JsonFunctions.jsonPathArray(jsonString, "$.subjects[*].name"), new String[]{"maths", "maths"});
+    assertEquals(JsonFunctions.jsonPathArray(jsonString, "$.subjects[*].grade"), new String[]{"A", "B"});
+  }
+
+  @Test
+  public void testJsonFunctionOnJsonArray()
+      throws JsonProcessingException {
+    String jsonArrayString =
+        "[\n" +
+        "        {\n" +
+        "            \"name\": \"maths\",\n" +
+        "        \"grade\": \"A\"\n" +
+        "        },\n" +

Review comment:
       Can we try nested array as well?
   Something like subjects 
   `{ name, array of lastTwoSemesterGrades}`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org