jiayuasu opened a new pull request, #823:
URL: https://github.com/apache/sedona-db/pull/823

   Adds operator overloading on `sedonadb.expr.Expr`, building on the 
foundation that landed in #807.
   
   This is the second of four small stacked PRs implementing Phase P1 of #791.
   
   ## What's new
   
   - **Binary operators**: `+`, `-`, `*`, `/`, `==`, `!=`, `<`, `<=`, `>`, 
`>=`, `&` (AND), `|` (OR), with reflected variants so `1 - col("x")` works the 
same as `col("x") - 1`.
   - **Unary operators**: `-` (arithmetic negation, via `negate()`) and `~` 
(logical NOT).
   - **Auto-coercion of Python scalars**: `col("x") > 5` works without an 
explicit literal wrap; the scalar is routed through the existing `_to_expr()` 
path internally.
   - `Expr.__hash__ = None` so use as a dict key or set member fails clearly — 
`__eq__` returns an `Expr`, not a `bool`.
   
   ## Implementation notes
   
   Operator dispatch is centralised: every Python dunder routes through a 
single `_binary(op, lhs, rhs)` helper, which calls into a single Rust factory 
`expr_binary(op, lhs, rhs)` that maps the string opcode to a 
`datafusion_expr::Operator`. Adding a new operator is one Rust match arm plus 
one Python dunder. Mirrors the pattern in the R bindings 
(`SedonaDBExprFactory::binary`).
   
   `~` (logical NOT) goes through a separate `expr_not` factory because 
DataFusion models it as `Expr::Not` rather than a binary operator.
   
   ## Tests
   
   - 18 new tests covering arithmetic, comparison, boolean, reflected, unary, 
chained, expr-with-expr, and `__hash__ = None` behaviour. All assertions are 
exact `repr() == ...` per the test module's pinning policy.
   - While here, tightens six inherited foundation tests from substring to 
exact equality so the module is consistent end-to-end.
   
   ## Test plan
   
   - [x] 33/33 tests in `tests/expr/test_expression.py` pass locally.
   - [x] No regressions in existing `tests/test_dataframe.py`.
   - [ ] CI green.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to