You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "waynexia (via GitHub)" <gi...@apache.org> on 2023/06/12 07:55:45 UTC

[GitHub] [arrow-datafusion] waynexia commented on pull request #6604: Support Expr::InList to Substrait::RexType

waynexia commented on PR #6604:
URL: https://github.com/apache/arrow-datafusion/pull/6604#issuecomment-1586780824

   @alamb's suggestion makes sense to me. For `NOT IN` there is no direct corresponding expression, maybe we can wrap an `Expr::Not` over `SingularOrList`.
   
   Interestingly, I inspected the official java implementation of substrait via its cli tool [Isthmus](https://github.com/substrait-io/substrait-java/blob/main/isthmus/README.md), it seems like they don't use `SingularOrList` as well. Don't know the reason. But through the doc it's applicable to use `SingularOrList` here.
   
   Here is the result I get from `SELECT a FROM t where a IN ('a', 'b')` and `SELECT a FROM t where a not IN ('a', 'b')`:
   
   <details>
     <summary> `SELECT a FROM t where a IN ('a', 'b')` </summary>
   
     ```json
   {
     "extensionUris": [{
       "extensionUriAnchor": 1,
       "uri": "/functions_boolean.yaml"
     }, {
       "extensionUriAnchor": 2,
       "uri": "/functions_comparison.yaml"
     }],
     "extensions": [{
       "extensionFunction": {
         "extensionUriReference": 1,
         "functionAnchor": 0,
         "name": "or:bool"
       }
     }, {
       "extensionFunction": {
         "extensionUriReference": 2,
         "functionAnchor": 1,
         "name": "equal:any_any"
       }
     }],
     "relations": [{
       "root": {
         "input": {
           "project": {
             "common": {
               "emit": {
                 "outputMapping": [3]
               }
             },
             "input": {
               "filter": {
                 "common": {
                   "direct": {
                   }
                 },
                 "input": {
                   "read": {
                     "common": {
                       "direct": {
                       }
                     },
                     "baseSchema": {
                       "names": ["A", "B", "C"],
                       "struct": {
                         "types": [{
                           "string": {
                             "typeVariationReference": 0,
                             "nullability": "NULLABILITY_NULLABLE"
                           }
                         }, {
                           "string": {
                             "typeVariationReference": 0,
                             "nullability": "NULLABILITY_NULLABLE"
                           }
                         }, {
                           "string": {
                             "typeVariationReference": 0,
                             "nullability": "NULLABILITY_NULLABLE"
                           }
                         }],
                         "typeVariationReference": 0,
                         "nullability": "NULLABILITY_REQUIRED"
                       }
                     },
                     "namedTable": {
                       "names": ["T"]
                     }
                   }
                 },
                 "condition": {
                   "scalarFunction": {
                     "functionReference": 0,
                     "args": [],
                     "outputType": {
                       "bool": {
                         "typeVariationReference": 0,
                         "nullability": "NULLABILITY_NULLABLE"
                       }
                     },
                     "arguments": [{
                       "value": {
                         "scalarFunction": {
                           "functionReference": 1,
                           "args": [],
                           "outputType": {
                             "bool": {
                               "typeVariationReference": 0,
                               "nullability": "NULLABILITY_NULLABLE"
                             }
                           },
                           "arguments": [{
                             "value": {
                               "selection": {
                                 "directReference": {
                                   "structField": {
                                     "field": 0
                                   }
                                 },
                                 "rootReference": {
                                 }
                               }
                             }
                           }, {
                             "value": {
                               "cast": {
                                 "type": {
                                   "string": {
                                     "typeVariationReference": 0,
                                     "nullability": "NULLABILITY_NULLABLE"
                                   }
                                 },
                                 "input": {
                                   "literal": {
                                     "fixedChar": "a",
                                     "nullable": false,
                                     "typeVariationReference": 0
                                   }
                                 },
                                 "failureBehavior": "FAILURE_BEHAVIOR_UNSPECIFIED"
                               }
                             }
                           }],
                           "options": []
                         }
                       }
                     }, {
                       "value": {
                         "scalarFunction": {
                           "functionReference": 1,
                           "args": [],
                           "outputType": {
                             "bool": {
                               "typeVariationReference": 0,
                               "nullability": "NULLABILITY_NULLABLE"
                             }
                           },
                           "arguments": [{
                             "value": {
                               "selection": {
                                 "directReference": {
                                   "structField": {
                                     "field": 0
                                   }
                                 },
                                 "rootReference": {
                                 }
                               }
                             }
                           }, {
                             "value": {
                               "cast": {
                                 "type": {
                                   "string": {
                                     "typeVariationReference": 0,
                                     "nullability": "NULLABILITY_NULLABLE"
                                   }
                                 },
                                 "input": {
                                   "literal": {
                                     "fixedChar": "b",
                                     "nullable": false,
                                     "typeVariationReference": 0
                                   }
                                 },
                                 "failureBehavior": "FAILURE_BEHAVIOR_UNSPECIFIED"
                               }
                             }
                           }],
                           "options": []
                         }
                       }
                     }],
                     "options": []
                   }
                 }
               }
             },
             "expressions": [{
               "selection": {
                 "directReference": {
                   "structField": {
                     "field": 0
                   }
                 },
                 "rootReference": {
                 }
               }
             }]
           }
         },
         "names": ["A"]
       }
     }],
     "expectedTypeUrls": []
   }
   
     ```
   </details>
   
   <details>
     <summary> `SELECT a FROM t where a not IN ('a', 'b')` </summary>
   
     ```json
   {
     "extensionUris": [{
       "extensionUriAnchor": 1,
       "uri": "/functions_boolean.yaml"
     }, {
       "extensionUriAnchor": 2,
       "uri": "/functions_comparison.yaml"
     }],
     "extensions": [{
       "extensionFunction": {
         "extensionUriReference": 1,
         "functionAnchor": 0,
         "name": "not:bool"
       }
     }, {
       "extensionFunction": {
         "extensionUriReference": 1,
         "functionAnchor": 1,
         "name": "or:bool"
       }
     }, {
       "extensionFunction": {
         "extensionUriReference": 2,
         "functionAnchor": 2,
         "name": "equal:any_any"
       }
     }],
     "relations": [{
       "root": {
         "input": {
           "project": {
             "common": {
               "emit": {
                 "outputMapping": [3]
               }
             },
             "input": {
               "filter": {
                 "common": {
                   "direct": {
                   }
                 },
                 "input": {
                   "read": {
                     "common": {
                       "direct": {
                       }
                     },
                     "baseSchema": {
                       "names": ["A", "B", "C"],
                       "struct": {
                         "types": [{
                           "string": {
                             "typeVariationReference": 0,
                             "nullability": "NULLABILITY_NULLABLE"
                           }
                         }, {
                           "string": {
                             "typeVariationReference": 0,
                             "nullability": "NULLABILITY_NULLABLE"
                           }
                         }, {
                           "string": {
                             "typeVariationReference": 0,
                             "nullability": "NULLABILITY_NULLABLE"
                           }
                         }],
                         "typeVariationReference": 0,
                         "nullability": "NULLABILITY_REQUIRED"
                       }
                     },
                     "namedTable": {
                       "names": ["T"]
                     }
                   }
                 },
                 "condition": {
                   "scalarFunction": {
                     "functionReference": 0,
                     "args": [],
                     "outputType": {
                       "bool": {
                         "typeVariationReference": 0,
                         "nullability": "NULLABILITY_NULLABLE"
                       }
                     },
                     "arguments": [{
                       "value": {
                         "scalarFunction": {
                           "functionReference": 1,
                           "args": [],
                           "outputType": {
                             "bool": {
                               "typeVariationReference": 0,
                               "nullability": "NULLABILITY_NULLABLE"
                             }
                           },
                           "arguments": [{
                             "value": {
                               "scalarFunction": {
                                 "functionReference": 2,
                                 "args": [],
                                 "outputType": {
                                   "bool": {
                                     "typeVariationReference": 0,
                                     "nullability": "NULLABILITY_NULLABLE"
                                   }
                                 },
                                 "arguments": [{
                                   "value": {
                                     "selection": {
                                       "directReference": {
                                         "structField": {
                                           "field": 0
                                         }
                                       },
                                       "rootReference": {
                                       }
                                     }
                                   }
                                 }, {
                                   "value": {
                                     "cast": {
                                       "type": {
                                         "string": {
                                           "typeVariationReference": 0,
                                           "nullability": "NULLABILITY_NULLABLE"
                                         }
                                       },
                                       "input": {
                                         "literal": {
                                           "fixedChar": "a",
                                           "nullable": false,
                                           "typeVariationReference": 0
                                         }
                                       },
                                       "failureBehavior": "FAILURE_BEHAVIOR_UNSPECIFIED"
                                     }
                                   }
                                 }],
                                 "options": []
                               }
                             }
                           }, {
                             "value": {
                               "scalarFunction": {
                                 "functionReference": 2,
                                 "args": [],
                                 "outputType": {
                                   "bool": {
                                     "typeVariationReference": 0,
                                     "nullability": "NULLABILITY_NULLABLE"
                                   }
                                 },
                                 "arguments": [{
                                   "value": {
                                     "selection": {
                                       "directReference": {
                                         "structField": {
                                           "field": 0
                                         }
                                       },
                                       "rootReference": {
                                       }
                                     }
                                   }
                                 }, {
                                   "value": {
                                     "cast": {
                                       "type": {
                                         "string": {
                                           "typeVariationReference": 0,
                                           "nullability": "NULLABILITY_NULLABLE"
                                         }
                                       },
                                       "input": {
                                         "literal": {
                                           "fixedChar": "b",
                                           "nullable": false,
                                           "typeVariationReference": 0
                                         }
                                       },
                                       "failureBehavior": "FAILURE_BEHAVIOR_UNSPECIFIED"
                                     }
                                   }
                                 }],
                                 "options": []
                               }
                             }
                           }],
                           "options": []
                         }
                       }
                     }],
                     "options": []
                   }
                 }
               }
             },
             "expressions": [{
               "selection": {
                 "directReference": {
                   "structField": {
                     "field": 0
                   }
                 },
                 "rootReference": {
                 }
               }
             }]
           }
         },
         "names": ["A"]
       }
     }],
     "expectedTypeUrls": []
   }
     ```
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org