datafusion_python/expr/
describe_table.rs1use std::fmt::{self, Display, Formatter};
19use std::sync::Arc;
20
21use arrow::datatypes::Schema;
22use arrow::pyarrow::PyArrowType;
23use datafusion::logical_expr::DescribeTable;
24use pyo3::IntoPyObjectExt;
25use pyo3::prelude::*;
26
27use super::logical_node::LogicalNode;
28use crate::common::df_schema::PyDFSchema;
29use crate::sql::logical::PyLogicalPlan;
30
31#[pyclass(
32 from_py_object,
33 frozen,
34 name = "DescribeTable",
35 module = "datafusion.expr",
36 subclass
37)]
38#[derive(Clone)]
39pub struct PyDescribeTable {
40 describe: DescribeTable,
41}
42
43impl Display for PyDescribeTable {
44 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
45 write!(f, "DescribeTable")
46 }
47}
48
49#[pymethods]
50impl PyDescribeTable {
51 #[new]
52 fn new(schema: PyArrowType<Schema>, output_schema: PyDFSchema) -> Self {
53 Self {
54 describe: DescribeTable {
55 schema: Arc::new(schema.0),
56 output_schema: Arc::new(output_schema.into()),
57 },
58 }
59 }
60
61 pub fn schema(&self) -> PyArrowType<Schema> {
62 (*self.describe.schema).clone().into()
63 }
64
65 pub fn output_schema(&self) -> PyDFSchema {
66 (*self.describe.output_schema).clone().into()
67 }
68
69 fn __repr__(&self) -> PyResult<String> {
70 Ok(format!("DescribeTable({self})"))
71 }
72
73 fn __name__(&self) -> PyResult<String> {
74 Ok("DescribeTable".to_string())
75 }
76}
77
78impl From<PyDescribeTable> for DescribeTable {
79 fn from(describe: PyDescribeTable) -> Self {
80 describe.describe
81 }
82}
83
84impl From<DescribeTable> for PyDescribeTable {
85 fn from(describe: DescribeTable) -> PyDescribeTable {
86 PyDescribeTable { describe }
87 }
88}
89
90impl LogicalNode for PyDescribeTable {
91 fn inputs(&self) -> Vec<PyLogicalPlan> {
92 vec![]
93 }
94
95 fn to_variant<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
96 self.clone().into_bound_py_any(py)
97 }
98}