[ https://issues.apache.org/jira/browse/PHOENIX-1661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14641220#comment-14641220 ]
ASF GitHub Bot commented on PHOENIX-1661: ----------------------------------------- Github user twdsilva commented on a diff in the pull request: https://github.com/apache/phoenix/pull/101#discussion_r35474234 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java --- @@ -1339,4 +1363,188 @@ public Expression visit(SubqueryParseNode node) throws SQLException { public int getTotalNodeCount() { return totalNodeCount; } + //JSON node + @Override + public boolean visitEnter(JsonSingleKeySearchParseNode node) { + return true; + } + + @Override + public boolean visitEnter(JsonSubsetParseNode node) { + return true; + } + + @Override + public boolean visitEnter(JsonSupersetParseNode node) { + return true; + } + + @Override + public boolean visitEnter(JsonMultiKeySearchOrParseNode node) { + return true; + } + + @Override + public boolean visitEnter(JsonMultiKeySeatchAndParseNode node) { + return true; + } + + @Override + public boolean visitEnter(JsonPathAsTextParseNode node) { + return true; + } + + @Override + public boolean visitEnter(JsonPathAsElementParseNode node) { + return true; + } + + @Override + public boolean visitEnter(JsonPointAsElementParseNode node) throws SQLException { + return true; + } + + @Override + public boolean visitEnter(JsonPointAsTextParseNode node){ + return true; + } + + + @Override + public Expression visitLeave(JsonSingleKeySearchParseNode node, List<Expression> children) throws SQLException { + if(!(PJson.INSTANCE.isComparableTo(children.get(0).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + if(!(PVarchar.INSTANCE.isComparableTo(children.get(1).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + Expression expression = new JsonSingleKeySearchExpression(children); + return wrapGroupByExpression(expression); + } + + @Override + public Expression visitLeave(JsonSubsetParseNode node, List<Expression> children) throws SQLException { + if(!(PJson.INSTANCE.isComparableTo(children.get(0).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + if(!(PJson.INSTANCE.isComparableTo(children.get(1).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + LiteralExpression rhs=(LiteralExpression)children.get(1); + Expression expression = new JsonSubsetExpression(children); + return wrapGroupByExpression(expression); + } + + @Override + public Expression visitLeave(JsonSupersetParseNode node, List<Expression> children) throws SQLException { + if(!(PJson.INSTANCE.isComparableTo(children.get(0).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + if(!(PVarchar.INSTANCE.isComparableTo(children.get(1).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + LiteralExpression rhs=(LiteralExpression)children.get(1); + Expression expression = new JsonSupersetExpression(children); + return wrapGroupByExpression(expression); + } + + @Override + public Expression visitLeave(JsonMultiKeySearchOrParseNode node, List<Expression> children) throws SQLException { + if(!(PJson.INSTANCE.isComparableTo(children.get(0).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + if(children.get(1).getDataType()!=PVarcharArray.INSTANCE){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + Expression expression = new JsonMultiKeySearchOrExpression(children); + return wrapGroupByExpression(expression); + } + + @Override + public Expression visitLeave(JsonMultiKeySeatchAndParseNode node, List<Expression> children) throws SQLException { + if(!(PJson.INSTANCE.isComparableTo(children.get(0).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + if(children.get(1).getDataType()!=PVarcharArray.INSTANCE){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + Expression expression = new JsonMultiKeySearchAndExpression(children); + return wrapGroupByExpression(expression); + } + + @Override + public Expression visitLeave(JsonPathAsTextParseNode node, List<Expression> children) throws SQLException { + if(!(PJson.INSTANCE.isComparableTo(children.get(0).getDataType()))){ + throw TypeMismatchException.newException(children.get(0).getDataType(), children.get(1).getDataType()); + } + if(!(PVarchar.INSTANCE.isComparableTo(children.get(1).getDataType()))){ --- End diff -- Can you change this to be a PVarcharArray to be consistent with ?| and ?& > Implement built-in functions for JSON > ------------------------------------- > > Key: PHOENIX-1661 > URL: https://issues.apache.org/jira/browse/PHOENIX-1661 > Project: Phoenix > Issue Type: Sub-task > Reporter: James Taylor > Labels: JSON, Java, SQL, gsoc2015, mentor > Attachments: PhoenixJSONSpecification-First-Draft.pdf > > > Take a look at the JSON built-in functions that are implemented in Postgres > (http://www.postgresql.org/docs/9.3/static/functions-json.html) and implement > the same for Phoenix in Java following this guide: > http://phoenix-hbase.blogspot.com/2013/04/how-to-add-your-own-built-in-function.html > Examples of functions include ARRAY_TO_JSON, ROW_TO_JSON, TO_JSON, etc. The > implementation of these built-in functions will be impacted by how JSON is > stored in Phoenix. See PHOENIX-628. An initial implementation could work off > of a simple text-based JSON representation and then when a native JSON type > is implemented, they could be reworked to be more efficient. -- This message was sent by Atlassian JIRA (v6.3.4#6332)