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