Apache DataFusion SQL Query Engine
[Bug][Datafusion] fix TaskContext session_config bug (#2070)
gaojun204804da6a6d9ff7
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.ymlindex 106e988a69..5f18846de9 100644--- a/.github/workflows/rust.yml+++ b/.github/workflows/rust.yml@@ -131,6 +131,8 @@ jobs:cargo run --example csv_sqlcargo run --example parquet_sqlcargo run --example avro_sql --features=datafusion/avro+ cd ../ballista-examples+ cargo run --example test_sql --features=ballista/standaloneenv:CARGO_HOME: "/github/home/.cargo"CARGO_TARGET_DIR: "/github/home/target"diff --git a/ballista-examples/Cargo.toml b/ballista-examples/Cargo.tomlindex 198a7883e8..a053e073e7 100644--- a/ballista-examples/Cargo.toml+++ b/ballista-examples/Cargo.toml@@ -28,6 +28,12 @@ edition = "2021"publish = falserust-version = "1.59"++[[example]]+name = "test_sql"+path = "examples/test_sql.rs"+required-features = ["ballista/standalone"]+[dependencies]ballista = { path = "../ballista/rust/client", version = "0.6.0" }datafusion = { path = "../datafusion" }diff --git a/ballista-examples/examples/test_sql.rs b/ballista-examples/examples/test_sql.rsnew file mode 100644index 0000000000..136f4f4abb--- /dev/null+++ b/ballista-examples/examples/test_sql.rs@@ -0,0 +1,46 @@+// Licensed to the Apache Software Foundation (ASF) under one+// or more contributor license agreements. See the NOTICE file+// distributed with this work for additional information+// regarding copyright ownership. The ASF licenses this file+// to you under the Apache License, Version 2.0 (the+// "License"); you may not use this file except in compliance+// with the License. You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing,+// software distributed under the License is distributed on an+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+// KIND, either express or implied. See the License for the+// specific language governing permissions and limitations+// under the License.++use ballista::prelude::{BallistaConfig, BallistaContext, Result};+use datafusion::prelude::CsvReadOptions;++/// This example show the udf plugin is work+///+#[tokio::main]+async fn main() -> Result<()> {+ let config = BallistaConfig::builder()+ .set("ballista.shuffle.partitions", "1")+ .build()?;++ let ctx = BallistaContext::standalone(&config, 10).await.unwrap();++ let testdata = datafusion::test_util::arrow_test_data();++ // register csv file with the execution context+ ctx.register_csv(+ "aggregate_test_100",+ &format!("{}/csv/aggregate_test_100.csv", testdata),+ CsvReadOptions::new(),+ )+ .await?;++ // test udf+ let df = ctx.sql("select count(1) from aggregate_test_100").await?;++ df.show().await?;+ Ok(())+}diff --git a/datafusion/src/execution/context.rs b/datafusion/src/execution/context.rsindex 7242683659..5aebe99070 100644--- a/datafusion/src/execution/context.rs+++ b/datafusion/src/execution/context.rs@@ -1340,27 +1340,31 @@ impl TaskContext {match task_props {TaskProperties::KVPairs(props) => {let session_config = SessionConfig::new();- session_config- .with_batch_size(props.get(BATCH_SIZE).unwrap().parse().unwrap())- .with_target_partitions(- props.get(TARGET_PARTITIONS).unwrap().parse().unwrap(),- )- .with_repartition_joins(- props.get(REPARTITION_JOINS).unwrap().parse().unwrap(),- )- .with_repartition_aggregations(- props- .get(REPARTITION_AGGREGATIONS)- .unwrap()- .parse()- .unwrap(),- )- .with_repartition_windows(- props.get(REPARTITION_WINDOWS).unwrap().parse().unwrap(),- )- .with_parquet_pruning(- props.get(PARQUET_PRUNING).unwrap().parse().unwrap(),- )+ if props.is_empty() {+ session_config+ } else {+ session_config+ .with_batch_size(props.get(BATCH_SIZE).unwrap().parse().unwrap())+ .with_target_partitions(+ props.get(TARGET_PARTITIONS).unwrap().parse().unwrap(),+ )+ .with_repartition_joins(+ props.get(REPARTITION_JOINS).unwrap().parse().unwrap(),+ )+ .with_repartition_aggregations(+ props+ .get(REPARTITION_AGGREGATIONS)+ .unwrap()+ .parse()+ .unwrap(),+ )+ .with_repartition_windows(+ props.get(REPARTITION_WINDOWS).unwrap().parse().unwrap(),+ )+ .with_parquet_pruning(+ props.get(PARQUET_PRUNING).unwrap().parse().unwrap(),+ )+ }}TaskProperties::SessionConfig(session_config) => session_config.clone(),}