| 1044 | |
| 1045 | |
| 1046 | def test_serializing_with_compute(): |
| 1047 | schema = pa.schema([ |
| 1048 | pa.field("x", pa.int32()), |
| 1049 | pa.field("y", pa.int32()) |
| 1050 | ]) |
| 1051 | expr = pc.equal(pc.field("x"), 7) |
| 1052 | expr_norm = pc.equal(pc.field(0), 7) |
| 1053 | buf = expr.to_substrait(schema) |
| 1054 | returned = pa.substrait.deserialize_expressions(buf) |
| 1055 | |
| 1056 | assert schema == returned.schema |
| 1057 | assert len(returned.expressions) == 1 |
| 1058 | |
| 1059 | assert str(returned.expressions["expression"]) == str(expr_norm) |
| 1060 | |
| 1061 | # Compute can't deserialize messages with multiple expressions |
| 1062 | buf = pa.substrait.serialize_expressions([expr, expr], ["first", "second"], schema) |
| 1063 | with pytest.raises(ValueError) as excinfo: |
| 1064 | pc.Expression.from_substrait(buf) |
| 1065 | assert 'contained multiple expressions' in str(excinfo.value) |
| 1066 | |
| 1067 | # Deserialization should be possible regardless of the expression name |
| 1068 | buf = pa.substrait.serialize_expressions([expr], ["weirdname"], schema) |
| 1069 | expr2 = pc.Expression.from_substrait(buf) |
| 1070 | assert str(expr2) == str(expr_norm) |
| 1071 | |
| 1072 | |
| 1073 | def test_serializing_udfs(): |