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