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

ASF GitHub Bot commented on PHOENIX-3046:
-----------------------------------------

Github user JamesRTaylor commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/208#discussion_r78280999
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/compile/ExpressionCompiler.java 
---
    @@ -523,7 +523,12 @@ public Expression visitLeave(LikeParseNode node, 
List<Expression> children) thro
                     byte[] wildcard = {StringUtil.MULTI_CHAR_LIKE};
                     StringUtil.fill(nullExpressionString, 0, pattern.length(), 
wildcard, 0, 1, false);
                     if (pattern.equals(new String (nullExpressionString))) {
    -                    return IsNullExpression.create(lhs, true, 
context.getTempPtr());
    --- End diff --
    
    I think the original code, optimizing to COL IS NOT NULL is not correct, 
because if COL is null, it'll evaluate to false when it should evaluate to 
null. Instead, I think it should become COL >= CAST(KeyRange.IS_NOT_NULL_RANGE 
AS VARCHAR) and for the negate case, it'd be COL < 
CAST(KeyRange.IS_NOT_NULL_RANGE AS VARCHAR). That way in any case, if COL is 
null, the expression will evaluate to null. If COL is any string then the first 
expression will evaluate to true and the latter to false.
    
    The code will look something like this:
        // Declare this as a static constant at top of file
        private static final Expression NOT_NULL_STRING = 
LiteralExpression.newConstant(PVarchar.INSTANCE.toObject(KeyRange.IS_NOT_NULL_RANGE.getLowerRange()));
        List<Expression> compareChildren = Arrays.asList(lhs, NOT_NULL_STRING);
        return new ComparisonExpression.create(compareChildren, node.isNegate() 
? CompareOp.LESS : CompareOp.GREATER_OR_EQUAL);
    
    Then make sure we have tests around COL being null too.


> `NOT LIKE '%'` unexpectedly returns results
> -------------------------------------------
>
>                 Key: PHOENIX-3046
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3046
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.7.0
>            Reporter: Kevin Liew
>            Assignee: Kevin Liew
>            Priority: Minor
>              Labels: like, like-predicate, phoenix, regex, wildcard, wildcards
>             Fix For: 4.9.0, 4.8.1
>
>
> The following returns all rows in the table when it should return no rows:
> {code}select * from emp where first_name not like '%'{code}
> The following returns no rows as expected:
> {code}select * from emp where first_name not like '%%'{code}
> first_name is a VARCHAR column



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to