Skip to content

Commit

Permalink
move column, dfschema, etc. to common module (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimexist authored Feb 7, 2022
1 parent a39a223 commit 2ec34cf
Show file tree
Hide file tree
Showing 7 changed files with 1,986 additions and 1,952 deletions.
1 change: 1 addition & 0 deletions datafusion-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ parquet = { version = "8.0.0", features = ["arrow"] }
avro-rs = { version = "0.13", features = ["snappy"], optional = true }
pyo3 = { version = "0.15", optional = true }
sqlparser = "0.13"
ordered-float = "2.10"
11 changes: 0 additions & 11 deletions datafusion-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ use arrow::error::ArrowError;
#[cfg(feature = "avro")]
use avro_rs::Error as AvroError;
use parquet::errors::ParquetError;
#[cfg(feature = "pyarrow")]
use pyo3::exceptions::PyException;
#[cfg(feature = "pyarrow")]
use pyo3::prelude::PyErr;
use sqlparser::parser::ParserError;

/// Result type for operations that could result in an [DataFusionError]
Expand Down Expand Up @@ -87,13 +83,6 @@ impl From<ArrowError> for DataFusionError {
}
}

#[cfg(feature = "pyarrow")]
impl From<DataFusionError> for PyErr {
fn from(err: DataFusionError) -> PyErr {
PyException::new_err(err.to_string())
}
}

impl From<DataFusionError> for ArrowError {
fn from(e: DataFusionError) -> Self {
match e {
Expand Down
6 changes: 6 additions & 0 deletions datafusion-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
mod column;
mod dfschema;
mod error;
#[cfg(feature = "pyarrow")]
mod pyarrow;
mod scalar;

pub use column::Column;
pub use dfschema::{DFField, DFSchema, DFSchemaRef, ExprSchema, ToDFSchema};
pub use error::{DataFusionError, Result};
pub use scalar::{
ScalarType, ScalarValue, MAX_PRECISION_FOR_DECIMAL128, MAX_SCALE_FOR_DECIMAL128,
};
18 changes: 13 additions & 5 deletions datafusion/src/pyarrow.rs → datafusion-common/src/pyarrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
// specific language governing permissions and limitations
// under the License.

use pyo3::prelude::*;
//! PyArrow

use crate::{DataFusionError, ScalarValue};
use arrow::array::ArrayData;
use arrow::pyarrow::PyArrowConvert;
use pyo3::exceptions::PyException;
use pyo3::prelude::PyErr;
use pyo3::types::PyList;
use pyo3::{FromPyObject, IntoPy, PyAny, PyObject, PyResult, Python};

use crate::arrow::array::ArrayData;
use crate::arrow::pyarrow::PyArrowConvert;
use crate::scalar::ScalarValue;
impl From<DataFusionError> for PyErr {
fn from(err: DataFusionError) -> PyErr {
PyException::new_err(err.to_string())
}
}

impl PyArrowConvert for ScalarValue {
fn from_pyarrow(value: &PyAny) -> PyResult<Self> {
Expand Down Expand Up @@ -68,7 +77,6 @@ mod tests {
use pyo3::prepare_freethreaded_python;
use pyo3::py_run;
use pyo3::types::PyDict;
use pyo3::Python;

fn init_python() {
prepare_freethreaded_python();
Expand Down
Loading

0 comments on commit 2ec34cf

Please sign in to comment.