You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "zhaowang (Jira)" <ji...@apache.org> on 2025/07/12 18:25:00 UTC

[jira] [Commented] (CALCITE-7079) Mongodb Adapter unable to translate multiple $ne condition conposed of "AND"

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

zhaowang commented on CALCITE-7079:
-----------------------------------

xx and (state <> 'a' or state <> 'b'), This condition execute wrong, I have tested it multiple times, it's not   not a bug caused by ReduceExpressionsRule. I have resubmitted the PR code  and fixed the case in MongoDB Adapter. [~jensen] 

> Mongodb Adapter unable to translate multiple $ne condition conposed of "AND"
> ----------------------------------------------------------------------------
>
>                 Key: CALCITE-7079
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7079
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: zhaowang
>            Assignee: zhaowang
>            Priority: Major
>              Labels: pull-request-available
>
> Mongodb adapter translate more than one $ne condition error.
> run sql:
> {code:java}
> select city, state from zips where city <> 'ABERDEEN' and city <> 'AIKEN'{code}
> Query plan:
> {code:java}
> {
>   "$match": {
>     "city": {
>       "$ne": "AIKEN"
>     }
>   }
> }, {$project: {CITY: '$city', STATE: '$state'}}{code}
> The condition (city <> 'ABERDEEN') lost,actually, more than one $ne condition conpose of AND have to translate to $nin operation
> Expected plan:
> {code:java}
> {
>   "$match": {
>     "city": {
>       "$nin": [
>         "AIKEN",
>         "ABERDEEN"
>       ]
>     }
>   }
> }, {$project: {CITY: '$city', STATE: '$state'}} {code}
>  
> More test case:
> Case 1:
> {code:java}
> select city, state from zips where city <> 'ABERDEEN' and city <> 'AIKEN' and state <> 'a' and state <> 'b' {code}
> Query plan:
> {code:java}
> {
>   "$match": {
>     "city": {
>       "$ne": "AIKEN"
>     },
>     "state": {
>       "$ne": "b"
>     }
>   }
> }, {$project: {CITY: '$city', STATE: '$state'}} {code}
> Expected plan:
> {code:java}
> {
>   "$match": {
>     "city": {
>       "$nin": [
>         "ABERDEEN",
>         "AIKEN"
>       ]
>     },
>     "state": {
>       "$nin": [
>         "a",
>         "b"
>       ]
>     }
>   }
> }, {$project: {CITY: '$city', STATE: '$state'}} {code}
>  
> Case 2:
> {code:java}
> select city, state from zips where city <> 'ABERDEEN' and city <> 'AIKEN' or (state <> 'a' and state <> 'b') {code}
> Query plan:
> {code:java}
> {
>   "$match": {
>     "$or": [
>       {
>         "city": {
>           "$ne": "AIKEN"
>         }
>       },
>       {
>         "state": {
>           "$ne": "b"
>         }
>       }
>     ]
>   }
> }, {$project: {CITY: '$city', STATE: '$state'}} {code}
> Expected plan:
> {code:java}
> {
>   "$match": {
>     "$or": [
>       {
>         "city": {
>           "$nin": [
>             "ABERDEEN",
>             "AIKEN"
>           ]
>         }
>       },
>       {
>         "state": {
>           "$nin": [
>             "a",
>             "b"
>           ]
>         }
>       }
>     ]
>   }
> }, {$project: {CITY: '$city', STATE: '$state'}} {code}
>  
> Case 3:
> {code:java}
> select city, state from zips where city <> 'ABERDEEN' and city <> 'AIKEN' and state <> 'a'{code}
> Query plan:
> {code:java}
> {
>   "$match": {
>     "city": {
>       "$nin": [
>         "ABERDEEN",
>         "AIKEN"
>       ]
>     },
>     "state": {
>       "$ne": "a"
>     }
>   }
> }, {$project: {CITY: '$city', STATE: '$state'}} {code}
> Expected plan:
> {code:java}
> {
>   "$match": {
>     "city": {
>       "$nin": [
>         "ABERDEEN",
>         "AIKEN"
>       ]
>     },
>     "state": {
>       "$ne": "a"
>     }
>   }
> } , {$project: {CITY: '$city', STATE: '$state'}}  {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)