phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twdsilva <...@git.apache.org>
Subject [GitHub] phoenix pull request: PHOENIX-1661 Implement built-in functions fo...
Date Fri, 24 Jul 2015 03:10:17 GMT
Github user twdsilva commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/93#discussion_r35392706
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/schema/json/PhoenixJson.java ---
    @@ -231,4 +236,197 @@ private PhoenixJson getPhoenixJsonInternal(String[] paths) {
             }
             return new PhoenixJson(node, node.toString());
         }
    +
    +    /**
    +     * If the current {@link PhoenixJson} is a JsonArray,then it returns the length of
the JsonArray.
    +     * <p>For example:[1,2,3] ,it will return 3
    +     * <p>Its required for json_array_length().
    +     * @throws SQLException
    +     */
    +    public int getJsonArrayLength() throws SQLException {
    +       if(this.rootNode.isArray()){
    +           return this.rootNode.size();
    +       }else{
    +           throw new SQLException("The JsonNode should be an Array");
    +       }
    +    }
    +
    +    /**
    +     * If the current {@link PhoenixJson} is a JsonArray,then it returns the set of array
elements.
    +     * <p>For example:[1,false,[2,"string"]]
    +     * it will return (new Object[]{"1","false","[2,\"string\"]"})
    +     * <p>Its required for json_array_elements().
    +     * @return {@link String []} as the set of JSON elements
    +     * @throws SQLException
    +     */
    +    public Object[] getJsonArrayElements() throws SQLException {
    +        if(this.rootNode.isArray()) {
    +            List<String> elementlist = new ArrayList();
    +            Iterator<JsonNode> elements = this.rootNode.getElements();
    +            while (elements.hasNext()) {
    +                JsonNode e = elements.next();
    +                elementlist.add(e.toString());
    +            }
    +            return elementlist.toArray();
    +        }else{
    +            throw new SQLException("The JsonNode should be an Array");
    --- End diff --
    
    Add a new SQLExceptionCode and use SQLExceptionInfo.Builder


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message