datafusion_python/expr/
analyze.rs

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
18use datafusion::logical_expr::logical_plan::Analyze;
19use pyo3::{prelude::*, IntoPyObjectExt};
20use std::fmt::{self, Display, Formatter};
21
22use super::logical_node::LogicalNode;
23use crate::common::df_schema::PyDFSchema;
24use crate::sql::logical::PyLogicalPlan;
25
26#[pyclass(name = "Analyze", module = "datafusion.expr", subclass)]
27#[derive(Clone)]
28pub struct PyAnalyze {
29    analyze: Analyze,
30}
31
32impl PyAnalyze {
33    pub fn new(analyze: Analyze) -> Self {
34        Self { analyze }
35    }
36}
37
38impl From<Analyze> for PyAnalyze {
39    fn from(analyze: Analyze) -> PyAnalyze {
40        PyAnalyze { analyze }
41    }
42}
43
44impl From<PyAnalyze> for Analyze {
45    fn from(analyze: PyAnalyze) -> Self {
46        analyze.analyze
47    }
48}
49
50impl Display for PyAnalyze {
51    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
52        write!(f, "Analyze Table")
53    }
54}
55
56#[pymethods]
57impl PyAnalyze {
58    fn verbose(&self) -> PyResult<bool> {
59        Ok(self.analyze.verbose)
60    }
61
62    fn input(&self) -> PyResult<Vec<PyLogicalPlan>> {
63        Ok(Self::inputs(self))
64    }
65
66    /// Resulting Schema for this `Analyze` node instance
67    fn schema(&self) -> PyResult<PyDFSchema> {
68        Ok((*self.analyze.schema).clone().into())
69    }
70
71    fn __repr__(&self) -> PyResult<String> {
72        Ok(format!("Analyze({})", self))
73    }
74}
75
76impl LogicalNode for PyAnalyze {
77    fn inputs(&self) -> Vec<PyLogicalPlan> {
78        vec![PyLogicalPlan::from((*self.analyze.input).clone())]
79    }
80
81    fn to_variant<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
82        self.clone().into_bound_py_any(py)
83    }
84}