[ 
https://issues.apache.org/jira/browse/PHOENIX-952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14008978#comment-14008978
 ] 

James Taylor commented on PHOENIX-952:
--------------------------------------

Not exactly, but yes that's pretty close:
- Yes, create an ArrayAnyParseNode which holds an expression of type ARRAY
- Also create an ArrayAllParseNode which holds an expression of type ARRAY (I'd 
create these separately)
- Add a visitEnter/visitLeave for these nodes in ParseNodeVisitor
- Don't assume that it's a comparison node - it can be any operator that 
returns a boolean. For example, the IS NULL operator should be ok too.
- In ParseNodeRewriter, set a boolean flag on the visitor when you encounter an 
ArrayAnyParseNode (i.e. in the visitEnter(ArrayAnyParseNode)).
- In the visitLeave of any boolean expression (ComparisonParseNode, 
IsNullParseNode, not sure if there are others, but maybe not), if the boolean 
flag is set then rewrite the parse nodes to be something like 
ArrayAnyCombinedParseNode(lhs, ComparisonParseNode(ArrayIndexLoopParseNode(), 
rhs)).
- Add a visitEnter/visitLeave for ArrayAnyCombinedParseNode and 
ArrayAllCombinedParseNode to ParseNodeVisitor
- In ExpressionCompiler, you'll do a bit more validation. If 
visitEnter(ArrayAnyParseNode) is called, this is an error case, so you'd throw 
here. That would mean that the ANY or ALL are used in some unexpected place, 
since they weren't re-written as mentioned above. You could also check that the 
lhs of an ArrayAnyCombinedParseNode is of type ARRAY in the 
visitLeave(ArrayAnyCombinedParseNode) since at this point you have the type 
information. If the validation succeeds, then the visitLeave would compile the 
following: 
{code}
ArrayAnyCombinedParseNode(lhs, ComparisonParseNode(ArrayIndexLoopParseNode(), 
rhs))
{code}
into this:
{code}
ArrayAnyCombinedExpression(b,ComparisonExpression(ArrayIndexFunction(b,ArrayIndexLoopExpression()))
{code}
where ArrayIndexLoopExpression is an anonymous inner class of 
ArrayAnyCombinedExpression. Each evaluate of ArrayAnyCombinedExpression would 
cause ArrayIndexLoopExpression to evaluate to the next index (up to the length 
of b). So the ArrayAnyCombinedExpression is nothing more than a looping 
construct - the contained boolean expression would just be evaluated the same 
way it is now.


> Support ANY and ALL built-ins for ARRAYs
> ----------------------------------------
>
>                 Key: PHOENIX-952
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-952
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 3.0.0, 4.0.0
>            Reporter: James Taylor
>            Assignee: ramkrishna.s.vasudevan
>             Fix For: 3.1, 4.1
>
>         Attachments: Phoenix-932_1.patch, Phoenix-932_2.patch
>
>
> There's currently no good way to search array elements. We should support the 
> ANY and ALL built-ins for our ARRAY type like Postgres does: 
> http://www.postgresql.org/docs/9.1/static/arrays.html#ARRAYS-SEARCHING



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to