Skip to main content

datafusion_python/common/
df_schema.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::sync::Arc;
19
20use datafusion::common::DFSchema;
21use pyo3::prelude::*;
22
23#[derive(Debug, Clone)]
24#[pyclass(
25    from_py_object,
26    frozen,
27    name = "DFSchema",
28    module = "datafusion.common",
29    subclass
30)]
31pub struct PyDFSchema {
32    schema: Arc<DFSchema>,
33}
34
35impl From<PyDFSchema> for DFSchema {
36    fn from(schema: PyDFSchema) -> DFSchema {
37        (*schema.schema).clone()
38    }
39}
40
41impl From<DFSchema> for PyDFSchema {
42    fn from(schema: DFSchema) -> PyDFSchema {
43        PyDFSchema {
44            schema: Arc::new(schema),
45        }
46    }
47}
48
49#[pymethods]
50impl PyDFSchema {
51    #[pyo3(name = "empty")]
52    #[staticmethod]
53    fn py_empty() -> PyResult<Self> {
54        Ok(Self {
55            schema: Arc::new(DFSchema::empty()),
56        })
57    }
58
59    #[pyo3(name = "field_names")]
60    fn py_field_names(&self) -> PyResult<Vec<String>> {
61        Ok(self.schema.field_names())
62    }
63}