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