You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/06/26 06:45:52 UTC
[GitHub] [calcite] chunweilei commented on a change in pull request #1277:
[CALCITE-3139] Implement JSON_EXTRACT function
chunweilei commented on a change in pull request #1277: [CALCITE-3139] Implement JSON_EXTRACT function
URL: https://github.com/apache/calcite/pull/1277#discussion_r297504544
##########
File path: core/src/main/java/org/apache/calcite/runtime/JsonFunctions.java
##########
@@ -644,6 +644,35 @@ public static Integer jsonStorageSize(JsonValueContext input) {
}
}
+ public static String jsonExtract(String input, String... pathSpecs) {
+ return jsonExtract(jsonValueExpression(input), pathSpecs);
+ }
+
+ public static String jsonExtract(JsonValueContext input, String... pathSpecs) {
+ try {
+ DocumentContext ctx = JsonPath.parse(input.obj,
+ Configuration
+ .builder()
+ .options(Option.SUPPRESS_EXCEPTIONS)
+ .jsonProvider(JSON_PATH_JSON_PROVIDER)
+ .mappingProvider(JSON_PATH_MAPPING_PROVIDER)
+ .build());
+ List<Object> arrayList = new ArrayList<Object>();
+ Object value;
+ for (String pathSpec : pathSpecs) {
+ value = ctx.read(pathSpec);
+ if ((pathSpec != null) && (value != null)) {
+ arrayList.add(value);
Review comment:
It seems parentheses is not necessary in` (pathSpec != null) && (value != null)`.
----------------------------------------------------------------
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
With regards,
Apache Git Services