Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ConfigOptions to ScalarFunctionArgs #13527

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion datafusion-examples/examples/composed_extension_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ async fn main() {

// deserialize proto back to execution plan
let runtime = ctx.runtime_env();
let config_options = ctx.state().config_options().clone();
let result_exec_plan: Arc<dyn ExecutionPlan> = proto
.try_into_physical_plan(&ctx, runtime.deref(), &composed_codec)
.try_into_physical_plan(
&ctx,
Arc::new(config_options),
runtime.deref(),
&composed_codec,
)
.expect("from proto");

// assert that the original and deserialized execution plans are equal
Expand Down
13 changes: 11 additions & 2 deletions datafusion-examples/examples/expr_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use datafusion::functions_aggregate::first_last::first_value_udaf;
use datafusion::optimizer::simplify_expressions::ExprSimplifier;
use datafusion::physical_expr::{analyze, AnalysisContext, ExprBoundaries};
use datafusion::prelude::*;
use datafusion_common::config::ConfigOptions;
use datafusion_common::tree_node::{Transformed, TreeNode};
use datafusion_common::{ScalarValue, ToDFSchema};
use datafusion_expr::execution_props::ExecutionProps;
Expand Down Expand Up @@ -356,8 +357,13 @@ fn type_coercion_demo() -> Result<()> {

// Evaluation with an expression that has not been type coerced cannot succeed.
let props = ExecutionProps::default();
let physical_expr =
datafusion_physical_expr::create_physical_expr(&expr, &df_schema, &props)?;
let config_options = Arc::new(ConfigOptions::default());
let physical_expr = datafusion_physical_expr::create_physical_expr(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems somewhat inevitable that creating a physical expr will require the config options

However, I also think threading through the config options down through to the physical creation will (finally) permit people to pass things from the session down to function implementations (I think @cisaacson also was trying to do this in the past)

&expr,
&df_schema,
&props,
Arc::clone(&config_options),
)?;
let e = physical_expr.evaluate(&batch).unwrap_err();
assert!(e
.find_root()
Expand All @@ -377,6 +383,7 @@ fn type_coercion_demo() -> Result<()> {
&coerced_expr,
&df_schema,
&props,
Arc::clone(&config_options),
)?;
assert!(physical_expr.evaluate(&batch).is_ok());

Expand All @@ -389,6 +396,7 @@ fn type_coercion_demo() -> Result<()> {
&coerced_expr,
&df_schema,
&props,
Arc::clone(&config_options),
)?;
assert!(physical_expr.evaluate(&batch).is_ok());

Expand Down Expand Up @@ -417,6 +425,7 @@ fn type_coercion_demo() -> Result<()> {
&coerced_expr,
&df_schema,
&props,
Arc::clone(&config_options),
)?;
assert!(physical_expr.evaluate(&batch).is_ok());

Expand Down
5 changes: 4 additions & 1 deletion datafusion-examples/examples/pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use datafusion::execution::context::ExecutionProps;
use datafusion::physical_expr::create_physical_expr;
use datafusion::physical_optimizer::pruning::{PruningPredicate, PruningStatistics};
use datafusion::prelude::*;
use datafusion_common::config::ConfigOptions;
use std::collections::HashSet;
use std::sync::Arc;

Expand Down Expand Up @@ -187,7 +188,9 @@ impl PruningStatistics for MyCatalog {
fn create_pruning_predicate(expr: Expr, schema: &SchemaRef) -> PruningPredicate {
let df_schema = DFSchema::try_from(schema.as_ref().clone()).unwrap();
let props = ExecutionProps::new();
let physical_expr = create_physical_expr(&expr, &df_schema, &props).unwrap();
let config_options = Arc::new(ConfigOptions::default());
let physical_expr =
create_physical_expr(&expr, &df_schema, &props, config_options).unwrap();
PruningPredicate::try_new(physical_expr, schema.clone()).unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion datafusion/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ config_namespace! {
}

/// A key value pair, with a corresponding description
#[derive(Debug)]
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct ConfigEntry {
/// A unique string to identify this config value
pub key: String,
Expand Down
9 changes: 8 additions & 1 deletion datafusion/core/src/datasource/listing/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use futures::stream::FuturesUnordered;
use futures::{stream::BoxStream, StreamExt, TryStreamExt};
use log::{debug, trace};

use datafusion_common::config::ConfigOptions;
use datafusion_common::tree_node::{TreeNode, TreeNodeRecursion};
use datafusion_common::{Column, DFSchema, DataFusionError};
use datafusion_expr::{Expr, Volatility};
Expand Down Expand Up @@ -283,10 +284,16 @@ async fn prune_partitions(

// TODO: Plumb this down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This todo may have now be complete

let props = ExecutionProps::new();
let config_options = Arc::new(ConfigOptions::default());

// Applies `filter` to `batch` returning `None` on error
let do_filter = |filter| -> Result<ArrayRef> {
let expr = create_physical_expr(filter, &df_schema, &props)?;
let expr = create_physical_expr(
filter,
&df_schema,
&props,
Arc::clone(&config_options),
)?;
expr.evaluate(&batch)?.into_array(partitions.len())
};

Expand Down
1 change: 1 addition & 0 deletions datafusion/core/src/datasource/listing/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ impl TableProvider for ListingTable {
&expr,
&table_df_schema,
state.execution_props(),
Arc::new(state.config_options().clone()),
)?;
Some(filters)
}
Expand Down
1 change: 1 addition & 0 deletions datafusion/core/src/datasource/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl TableProvider for MemTable {
sort_exprs,
&df_schema,
state.execution_props(),
Arc::new(state.config_options().clone()),
)
})
.collect::<Result<Vec<_>>>()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,10 @@ fn create_output_array(

#[cfg(test)]
mod tests {
use arrow_array::Int32Array;

use super::*;
use crate::{test::columns, test_util::aggr_test_schema};
use arrow_array::Int32Array;
use datafusion_common::config::ConfigOptions;

#[test]
fn physical_plan_config_no_projection() {
Expand Down Expand Up @@ -1121,6 +1121,7 @@ mod tests {
&expr,
&DFSchema::try_from(table_schema.as_ref().clone())?,
&ExecutionProps::default(),
Arc::new(ConfigOptions::default()),
)
})
.collect::<Result<Vec<_>>>()?,
Expand Down
7 changes: 6 additions & 1 deletion datafusion/core/src/execution/session_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,12 @@ impl SessionState {
.transform_up(|expr| rewrite.rewrite(expr, df_schema, config_options))?
.data;
}
create_physical_expr(&expr, df_schema, self.execution_props())
create_physical_expr(
&expr,
df_schema,
self.execution_props(),
Arc::new(config_options.clone()),
)
}

/// Return the session ID
Expand Down
4 changes: 4 additions & 0 deletions datafusion/core/src/physical_optimizer/projection_pushdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,7 @@ mod tests {
)),
],
DataType::Int32,
Arc::new(ConfigOptions::default()),
)),
Arc::new(CaseExpr::try_new(
Some(Arc::new(Column::new("d", 2))),
Expand Down Expand Up @@ -1482,6 +1483,7 @@ mod tests {
)),
],
DataType::Int32,
Arc::new(ConfigOptions::default()),
)),
Arc::new(CaseExpr::try_new(
Some(Arc::new(Column::new("d", 3))),
Expand Down Expand Up @@ -1550,6 +1552,7 @@ mod tests {
)),
],
DataType::Int32,
Arc::new(ConfigOptions::default()),
)),
Arc::new(CaseExpr::try_new(
Some(Arc::new(Column::new("d", 2))),
Expand Down Expand Up @@ -1615,6 +1618,7 @@ mod tests {
)),
],
DataType::Int32,
Arc::new(ConfigOptions::default()),
)),
Arc::new(CaseExpr::try_new(
Some(Arc::new(Column::new("d_new", 3))),
Expand Down
Loading
Loading