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