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