You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metamodel.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/07/12 14:40:20 UTC

[jira] [Commented] (METAMODEL-1103) WildcardPattern not anchored to beginning of string.

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

ASF GitHub Bot commented on METAMODEL-1103:
-------------------------------------------

GitHub user LosD opened a pull request:

    https://github.com/apache/metamodel/pull/115

    Anchor WildcardPattern to start

    This makes sure the `WildcardPattern` anchors its test to the start of the string, not only the end.
    
    This comes with a minor performance penalty (quick test said 5-10%), but I think correctness trumps speed here.
    
    I would have liked to compare speed with pre-compiled regexes (`Pattern.quote()` the operand, replace `%` with `.*?` and anchor it with `^` and `$`), but if the LIKE operand is inside a `SelectItem`, that would mean compiling a new regex pattern for every row, which would probably be _very_ expensive, so I opted not to try. There seem to be some similar optimization of the IN operator, so I might be wrong, though.
    
    Fixes METAMODEL-1103

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/LosD/metamodel METAMODEL-1103/anchor-string-start

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/metamodel/pull/115.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #115
    
----
commit e993e9483a9daf0e0f603362d31fbc231a344ab7
Author: Dennis Du Krøger <d...@hp23c.dk>
Date:   2016-07-12T14:28:00Z

    METAMODEL-1103: Anchor WildcardPattern to start
    
    This makes sure the WildcardPattern anchors its test to the start of
    the string, not only the end.
    
    This comes with a minor performance penalty (quick test said 5-10% ),
    but I think correctness trumps speed here.
    
    I would have liked to compare speed with pre-compiled regexes
    (`Pattern.quote()` the operand, replace `%` with `.*?` and anchor it
    with `^` and `$`), but if the LIKE operand is inside a SelectItem,
    that would mean compiling a new regex pattern for every row, which
    would probably be _very_ expensive, so I opted not to try. There seem
    to be some similar optimization of the IN operator, so I might be
    wrong.
    
    Fixes METAMODEL-1103

----


> WildcardPattern not anchored to beginning of string.
> ----------------------------------------------------
>
>                 Key: METAMODEL-1103
>                 URL: https://issues.apache.org/jira/browse/METAMODEL-1103
>             Project: Apache MetaModel
>          Issue Type: Bug
>    Affects Versions: 4.5.3
>            Reporter: Dennis Du Krøger
>            Assignee: Dennis Du Krøger
>            Priority: Critical
>
> When filtering using LIKE in {{FilterItem.evaluate()}} (really {{WildcardPattern}}) is not properly anchored to the beginning of the string, which is not consistent with SQL LIKE
> Given the table:
> ||name||
> |foobar|
> |bar|
> |oba|
> And the queries:
> {code:sql}
> SELECT * FROM liketest WHERE name LIKE 'oba%'
> SELECT * FROM liketest WHERE name LIKE 'bar'
> {code}
> PostgreSQL and MS SQL will return the results:
> ||name||
> |oba|
> and 
> ||name||
> |bar|
> But MetaModel (on a {{QueryPostprocessDataContext}} based source) will return the results:
> ||name||
> |foobar|
> |oba|
> and 
> ||name||
> |foobar|
> |oba|
> (Marked critical since it is means errors that are easily missed when looking the results over, but can sneak corruptions in later)



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