datafusion_python/expr/
create_memory_table.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use 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}