|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +from datafusion import SessionContext, LogicalPlan, ExecutionPlan |
| 19 | +import pytest |
| 20 | + |
| 21 | + |
| 22 | +# Note: We must use CSV because memory tables are currently not supported for |
| 23 | +# conversion to/from protobuf. |
| 24 | +@pytest.fixture |
| 25 | +def df(): |
| 26 | + ctx = SessionContext() |
| 27 | + return ctx.read_csv(path="testing/data/csv/aggregate_test_100.csv").select("c1") |
| 28 | + |
| 29 | + |
| 30 | +def test_logical_plan_to_proto(ctx, df) -> None: |
| 31 | + logical_plan_bytes = df.logical_plan().to_proto() |
| 32 | + logical_plan = LogicalPlan.from_proto(ctx, logical_plan_bytes) |
| 33 | + |
| 34 | + df_round_trip = ctx.create_dataframe_from_logical_plan(logical_plan) |
| 35 | + |
| 36 | + assert df.collect() == df_round_trip.collect() |
| 37 | + |
| 38 | + original_execution_plan = df.execution_plan() |
| 39 | + execution_plan_bytes = original_execution_plan.to_proto() |
| 40 | + execution_plan = ExecutionPlan.from_proto(ctx, execution_plan_bytes) |
| 41 | + |
| 42 | + assert str(original_execution_plan) == str(execution_plan) |
0 commit comments