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