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