Skip to content

Commit

Permalink
try using ?Sized
Browse files Browse the repository at this point in the history
  • Loading branch information
yyy1000 committed Feb 9, 2024
1 parent 0c9acdd commit 56b71ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions datafusion-examples/examples/return_types_udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use datafusion::{arrow::datatypes::DataType, logical_expr::Volatility};
use datafusion::error::Result;
use datafusion::prelude::*;
use datafusion_common::{
internal_err, DFSchema, DataFusionError, ScalarValue, ToDFSchema,
internal_err, DataFusionError, ExprSchema, ScalarValue, ToDFSchema
};
use datafusion_expr::{
expr::ScalarFunction, ColumnarValue, ExprSchemable, ScalarUDF, ScalarUDFImpl,
Expand Down Expand Up @@ -63,7 +63,7 @@ impl ScalarUDFImpl for UDFWithExprReturn {
fn return_type_from_exprs(
&self,
arg_exprs: &[Expr],
schema: &DFSchema,
schema: &dyn ExprSchema,
) -> Result<DataType> {
if arg_exprs.len() != 3 {
return internal_err!("The size of the args must be 3.");
Expand Down
8 changes: 4 additions & 4 deletions datafusion/expr/src/expr_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::sync::Arc;
/// trait to allow expr to typable with respect to a schema
pub trait ExprSchemable {
/// given a schema, return the type of the expr
fn get_type<S: ExprSchema>(&self, schema: &S) -> Result<DataType>;
fn get_type<S: ExprSchema + ?Sized>(&self, schema: &S) -> Result<DataType>;

/// given a schema, return the nullability of the expr
fn nullable<S: ExprSchema>(&self, input_schema: &S) -> Result<bool>;
Expand Down Expand Up @@ -90,7 +90,7 @@ impl ExprSchemable for Expr {
/// expression refers to a column that does not exist in the
/// schema, or when the expression is incorrectly typed
/// (e.g. `[utf8] + [bool]`).
fn get_type<S: ExprSchema>(&self, schema: &S) -> Result<DataType> {
fn get_type<S: ExprSchema + ?Sized>(&self, schema: &S) -> Result<DataType> {
match self {
Expr::Alias(Alias { expr, name, .. }) => match &**expr {
Expr::Placeholder(Placeholder { data_type, .. }) => match &data_type {
Expand Down Expand Up @@ -136,7 +136,7 @@ impl ExprSchemable for Expr {
fun.return_type(&arg_data_types)
}
ScalarFunctionDefinition::UDF(fun) => {
Ok(fun.return_type(&arg_data_types)?)
fun.return_type_from_exprs(args, schema)
}
ScalarFunctionDefinition::Name(_) => {
internal_err!("Function `Expr` with name should be resolved.")
Expand Down Expand Up @@ -394,7 +394,7 @@ impl ExprSchemable for Expr {
}

/// return the schema [`Field`] for the type referenced by `get_indexed_field`
fn field_for_index<S: ExprSchema>(
fn field_for_index<S: ExprSchema + ?Sized>(
expr: &Expr,
field: &GetFieldAccess,
schema: &S,
Expand Down
6 changes: 3 additions & 3 deletions datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
ScalarFunctionImplementation, Signature,
};
use arrow::datatypes::DataType;
use datafusion_common::{DFSchema, Result};
use datafusion_common::{DFSchema, ExprSchema, Result};
use std::any::Any;
use std::fmt;
use std::fmt::Debug;
Expand Down Expand Up @@ -159,7 +159,7 @@ impl ScalarUDF {
pub fn return_type_from_exprs(
&self,
args: &[Expr],
schema: &DFSchema,
schema: &dyn ExprSchema,
) -> Result<DataType> {
self.inner.return_type_from_exprs(args, schema)
}
Expand Down Expand Up @@ -266,7 +266,7 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
fn return_type_from_exprs(
&self,
arg_exprs: &[Expr],
schema: &DFSchema,
schema: &dyn ExprSchema,
) -> Result<DataType> {
// provide default implementation that calls `self.return_type()`
// so that people don't have to implement `return_type_from_exprs` if they dont want to
Expand Down

0 comments on commit 56b71ae

Please sign in to comment.