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



##########
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:
       Should have mentioned earlier itself. Can we please add one test for 
empty array as well?
   
   Also,  Can we chain the jsonPathArray with jsonExtract as a transform and 
extract a particular value out of the array? Or for such cases, the recommended 
way is to directly use jsonExtract as opposed to doing 
jsonExtract(jsonPathArray(....)) ?




----------------------------------------------------------------
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:
us...@infra.apache.org



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

Reply via email to