| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| |
| use std::sync::Arc; |
| |
| use datafusion_expr::LogicalPlan; |
| use pyo3::prelude::*; |
| |
| #[pyclass(name = "LogicalPlan", module = "datafusion", subclass)] |
| #[derive(Debug, Clone)] |
| pub struct PyLogicalPlan { |
| pub(crate) plan: Arc<LogicalPlan>, |
| } |
| |
| impl PyLogicalPlan { |
| /// creates a new PyLogicalPlan |
| pub fn new(plan: LogicalPlan) -> Self { |
| Self { |
| plan: Arc::new(plan), |
| } |
| } |
| } |
| |
| #[pymethods] |
| impl PyLogicalPlan { |
| /// Get the inputs to this plan |
| pub fn inputs(&self) -> Vec<PyLogicalPlan> { |
| let mut inputs = vec![]; |
| for input in self.plan.inputs() { |
| inputs.push(input.to_owned().into()); |
| } |
| inputs |
| } |
| |
| pub fn display(&self) -> String { |
| format!("{}", self.plan.display()) |
| } |
| |
| pub fn display_indent(&self) -> String { |
| format!("{}", self.plan.display_indent()) |
| } |
| |
| pub fn display_indent_schema(&self) -> String { |
| format!("{}", self.plan.display_indent_schema()) |
| } |
| |
| pub fn display_graphviz(&self) -> String { |
| format!("{}", self.plan.display_indent_schema()) |
| } |
| } |
| |
| impl From<PyLogicalPlan> for LogicalPlan { |
| fn from(logical_plan: PyLogicalPlan) -> LogicalPlan { |
| logical_plan.plan.as_ref().clone() |
| } |
| } |
| |
| impl From<LogicalPlan> for PyLogicalPlan { |
| fn from(logical_plan: LogicalPlan) -> PyLogicalPlan { |
| PyLogicalPlan { |
| plan: Arc::new(logical_plan), |
| } |
| } |
| } |