Skip to content

Commit

Permalink
remove PyDFField and related methods
Browse files Browse the repository at this point in the history
DFField was removed upstream.

Ref: apache/datafusion#9595
  • Loading branch information
Michael-J-Ward committed May 13, 2024
1 parent ddcd58f commit abe09a2
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 155 deletions.
1 change: 0 additions & 1 deletion datafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
)

from .common import (
DFField,
DFSchema,
)

Expand Down
3 changes: 1 addition & 2 deletions datafusion/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
)

from datafusion.common import (
DFField,
DFSchema,
)

Expand Down Expand Up @@ -161,7 +160,7 @@ def test_class_module_is_datafusion():
assert klass.__module__ == "datafusion.expr"

# schema
for klass in [DFField, DFSchema]:
for klass in [DFSchema]:
assert klass.__module__ == "datafusion.common"


Expand Down
2 changes: 0 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
use pyo3::prelude::*;

pub mod data_type;
pub mod df_field;
pub mod df_schema;
pub mod function;
pub mod schema;

/// Initializes the `common` module to match the pattern of `datafusion-common` https://docs.rs/datafusion-common/18.0.0/datafusion_common/index.html
pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
m.add_class::<df_schema::PyDFSchema>()?;
m.add_class::<df_field::PyDFField>()?;
m.add_class::<data_type::PyDataType>()?;
m.add_class::<data_type::DataTypeMap>()?;
m.add_class::<data_type::PythonType>()?;
Expand Down
111 changes: 0 additions & 111 deletions src/common/df_field.rs

This file was deleted.

42 changes: 3 additions & 39 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@ use std::convert::{From, Into};
use datafusion::arrow::datatypes::DataType;
use datafusion::arrow::pyarrow::PyArrowType;
use datafusion::scalar::ScalarValue;
use datafusion_common::DFField;
use datafusion_expr::{
col,
expr::{AggregateFunction, InList, InSubquery, ScalarFunction, Sort, WindowFunction},
lit,
utils::exprlist_to_fields,
Between, BinaryExpr, Case, Cast, Expr, GetFieldAccess, GetIndexedField, Like, LogicalPlan,
Operator, TryCast,
lit, Between, BinaryExpr, Case, Cast, Expr, GetFieldAccess, GetIndexedField, Like, Operator,
TryCast,
};

use crate::common::data_type::{DataTypeMap, RexType};
use crate::errors::{py_datafusion_err, py_runtime_err, py_type_err, DataFusionError};
use crate::errors::{py_datafusion_err, py_runtime_err, py_type_err};
use crate::expr::aggregate_expr::PyAggregateFunction;
use crate::expr::binary_expr::PyBinaryExpr;
use crate::expr::column::PyColumn;
use crate::expr::literal::PyLiteral;
use crate::sql::logical::PyLogicalPlan;

use self::alias::PyAlias;
use self::bool_expr::{
Expand Down Expand Up @@ -557,41 +553,9 @@ impl PyExpr {
}
})
}

pub fn column_name(&self, plan: PyLogicalPlan) -> PyResult<String> {
self._column_name(&plan.plan()).map_err(py_runtime_err)
}
}

impl PyExpr {
pub fn _column_name(&self, plan: &LogicalPlan) -> Result<String, DataFusionError> {
let field = Self::expr_to_field(&self.expr, plan)?;
Ok(field.qualified_column().flat_name())
}

/// Create a [DFField] representing an [Expr], given an input [LogicalPlan] to resolve against
pub fn expr_to_field(
expr: &Expr,
input_plan: &LogicalPlan,
) -> Result<DFField, DataFusionError> {
match expr {
Expr::Sort(Sort { expr, .. }) => {
// DataFusion does not support create_name for sort expressions (since they never
// appear in projections) so we just delegate to the contained expression instead
Self::expr_to_field(expr, input_plan)
}
Expr::Wildcard { .. } => {
// Since * could be any of the valid column names just return the first one
Ok(input_plan.schema().field(0).clone())
}
_ => {
let fields =
exprlist_to_fields(&[expr.clone()], input_plan).map_err(PyErr::from)?;
Ok(fields[0].clone())
}
}
}

fn _types(expr: &Expr) -> PyResult<DataTypeMap> {
match expr {
Expr::BinaryExpr(BinaryExpr {
Expand Down

0 comments on commit abe09a2

Please sign in to comment.