{"record":{"id":"42083c47bb27673c","repo":"pola-rs/polars","slug":"unknown-lhs-op-rhs","errorCode":null,"errorMessage":"Unknown: {lhs} {op} {rhs}","messagePattern":"Unknown: (.+?) (.+?) (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_utils.py","lineNumber":302,"sourceCode":"\n@_convert_predicate.register(Attribute)\ndef _(a: Attribute) -> Any:\n    return a.attr\n\n\n@_convert_predicate.register(BinOp)\ndef _(a: BinOp) -> Any:\n    lhs = _ensure_boolean_expression(_convert_predicate(a.left))\n    rhs = _ensure_boolean_expression(_convert_predicate(a.right))\n\n    op = a.op\n    if isinstance(op, BitAnd):\n        return pyiceberg.expressions.And(lhs, rhs)\n    if isinstance(op, BitOr):\n        return pyiceberg.expressions.Or(lhs, rhs)\n    else:\n        msg = f\"Unknown: {lhs} {op} {rhs}\"\n        raise TypeError(msg)\n\n\n@_convert_predicate.register(Compare)\ndef _(a: Compare) -> Any:\n    op = a.ops[0]\n    lhs = _convert_predicate(a.left)[0]\n    rhs = _convert_predicate(a.comparators[0])\n\n    if isinstance(op, Gt):\n        return pyiceberg.expressions.GreaterThan(lhs, rhs)  # type: ignore[misc, call-arg]\n    if isinstance(op, GtE):\n        return pyiceberg.expressions.GreaterThanOrEqual(lhs, rhs)  # type: ignore[misc, call-arg]\n    if isinstance(op, Eq):\n        return pyiceberg.expressions.EqualTo(lhs, rhs)  # type: ignore[misc, call-arg]\n    if isinstance(op, Lt):\n        return pyiceberg.expressions.LessThan(lhs, rhs)  # type: ignore[misc, call-arg]\n    if isinstance(op, LtE):\n        return pyiceberg.expressions.LessThanOrEqual(lhs, rhs)  # type: ignore[misc, call-arg]","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_utils.py#L284-L320","documentation":"Boolean combination nodes in the pyarrow predicate AST (BinOp) are supported only for BitAnd (`&`) and BitOr (`|`), mapping to pyiceberg And/Or. Any other binary operator (arithmetic +,-,*, /, shifts, etc.) reaches the fallback and raises TypeError('Unknown: lhs op rhs').","triggerScenarios":"A pyarrow.compute filter passed to scan_iceberg combining operands with operators other than `&`/`|` — e.g. `pc.field('a') + pc.field('b') == 3`, or using `and`/`or` keywords that leaked into the AST, or XOR-like constructs.","commonSituations":"Writing SQL-style `and`/`or` instead of `&`/`|` in pyarrow expressions; doing arithmetic inside filters; mixing bitwise ops with comparisons in ways the AST walker can't lower to Iceberg predicates.","solutions":["Combine conditions with `&` and `|` only, parenthesizing each comparison","Move arithmetic out of the filter (precompute or filter after load with polars)","Express the predicate as a pyiceberg expression directly for shapes pyarrow filters can't represent"],"exampleFix":"// before\npc.field('a') + pc.field('b') == 3  # Unknown: ...\n// after\n(pc.field('a') == 1) & (pc.field('b') == 2)","handlingStrategy":"validation","validationCode":"def boolean_ops_ok(expr) -> bool:\n    import ast\n    return all(isinstance(n.op, (ast.BitAnd, ast.BitOr))\n               for n in ast.walk(expr) if isinstance(n, ast.BinOp))","typeGuard":null,"tryCatchPattern":"try:\n    lf = pl.scan_iceberg(src, filter=pred)\nexcept TypeError as e:\n    if 'Unknown:' in str(e):\n        lf = pl.scan_iceberg(src).filter(downstream_condition)","preventionTips":["Combine sub-predicates with `&` and `|` only, with parentheses","Never use Python `and`/`or` in expression filters","Keep arithmetic out of pushdown filters","Unit-test each filter expression against scan_iceberg"],"tags":["iceberg","predicate","pyarrow","boolean-operators"],"backgroundTag":"unsupported-operation","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}