Apache DataFusion SQL Query Engine
refactor: relax the signature of register_* in SessionContext (#4612)
Ruihang Xiada0de9d2d60b
diff --git a/datafusion-examples/examples/simple_udf.rs b/datafusion-examples/examples/simple_udf.rsindex 7f5fe4a279..c9044a87ab 100644--- a/datafusion-examples/examples/simple_udf.rs+++ b/datafusion-examples/examples/simple_udf.rs@@ -59,7 +59,7 @@ fn create_context() -> Result<SessionContext> {/// In this example we will declare a single-type, single return type UDF that exponentiates f64, a^b#[tokio::main]async fn main() -> Result<()> {- let mut ctx = create_context()?;+ let ctx = create_context()?;// First, declare the actual implementation of the calculationlet pow = |args: &[ArrayRef]| {diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rsindex 759cc79a8b..a73a95401d 100644--- a/datafusion/core/src/execution/context.rs+++ b/datafusion/core/src/execution/context.rs@@ -571,7 +571,7 @@ impl SessionContext {/// Registers a variable provider within this context.pub fn register_variable(- &mut self,+ &self,variable_type: VarType,provider: Arc<dyn VarProvider + Send + Sync>,) {@@ -588,7 +588,7 @@ impl SessionContext {////// `SELECT MY_FUNC(x)...` will look for a function named `"my_func"`/// `SELECT "my_FUNC"(x)` will look for a function named `"my_FUNC"`- pub fn register_udf(&mut self, f: ScalarUDF) {+ pub fn register_udf(&self, f: ScalarUDF) {self.state.write().scalar_functions@@ -602,7 +602,7 @@ impl SessionContext {////// `SELECT MY_UDAF(x)...` will look for an aggregate named `"my_udaf"`/// `SELECT "my_UDAF"(x)` will look for an aggregate named `"my_UDAF"`- pub fn register_udaf(&mut self, f: AggregateUDF) {+ pub fn register_udaf(&self, f: AggregateUDF) {self.state.write().aggregate_functions@@ -638,7 +638,7 @@ impl SessionContext {/// Creates a [`DataFrame`] for reading an Json data source.pub async fn read_json(- &mut self,+ &self,table_path: impl AsRef<str>,options: NdJsonReadOptions<'_>,) -> Result<Arc<DataFrame>> {@@ -2085,7 +2085,7 @@ mod tests {async fn create_variable_expr() -> Result<()> {let tmp_dir = TempDir::new()?;let partition_count = 4;- let mut ctx = create_ctx(&tmp_dir, partition_count).await?;+ let ctx = create_ctx(&tmp_dir, partition_count).await?;let variable_provider = test::variable::SystemVar::new();ctx.register_variable(VarType::System, Arc::new(variable_provider));@@ -2143,7 +2143,7 @@ mod tests {#[tokio::test]async fn case_sensitive_identifiers_user_defined_functions() -> Result<()> {- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();ctx.register_table("t", test::table_with_sequence(1, 1).unwrap()).unwrap();@@ -2184,7 +2184,7 @@ mod tests {#[tokio::test]async fn case_sensitive_identifiers_user_defined_aggregates() -> Result<()> {- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();ctx.register_table("t", test::table_with_sequence(1, 1).unwrap()).unwrap();diff --git a/datafusion/core/src/physical_plan/file_format/json.rs b/datafusion/core/src/physical_plan/file_format/json.rsindex e507c7d6d8..fac394ee37 100644--- a/datafusion/core/src/physical_plan/file_format/json.rs+++ b/datafusion/core/src/physical_plan/file_format/json.rs@@ -303,7 +303,7 @@ mod tests {file_compression_type: FileCompressionType,store: Arc<dyn ObjectStore>,) {- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();ctx.runtime_env().register_object_store("file", "", store.clone());let filename = "1.json";diff --git a/datafusion/core/tests/sql/mod.rs b/datafusion/core/tests/sql/mod.rsindex 1e13076723..1075041c24 100644--- a/datafusion/core/tests/sql/mod.rs+++ b/datafusion/core/tests/sql/mod.rs@@ -138,7 +138,7 @@ where}fn create_ctx() -> SessionContext {- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();// register a custom UDFctx.register_udf(create_udf(diff --git a/datafusion/core/tests/sql/udf.rs b/datafusion/core/tests/sql/udf.rsindex b71a13cdda..3a150dc7c8 100644--- a/datafusion/core/tests/sql/udf.rs+++ b/datafusion/core/tests/sql/udf.rs@@ -53,7 +53,7 @@ async fn scalar_udf() -> Result<()> {],)?;- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();ctx.register_batch("t", batch)?;@@ -138,7 +138,7 @@ async fn simple_udaf() -> Result<()> {vec![Arc::new(Int32Array::from_slice([4, 5]))],)?;- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();let provider = MemTable::try_new(Arc::new(schema), vec![vec![batch1], vec![batch2]])?;ctx.register_table("t", Arc::new(provider))?;@@ -205,7 +205,7 @@ fn udaf_as_window_func() -> Result<()> {Arc::new(vec![DataType::Int32]),);- let mut context = SessionContext::new();+ let context = SessionContext::new();context.register_table("my_table",Arc::new(datafusion::datasource::empty::EmptyTable::new(Arc::new(diff --git a/datafusion/proto/src/bytes/mod.rs b/datafusion/proto/src/bytes/mod.rsindex 005b76a567..1eb946bd50 100644--- a/datafusion/proto/src/bytes/mod.rs+++ b/datafusion/proto/src/bytes/mod.rs@@ -553,7 +553,7 @@ mod test {scalar_fn,);- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();ctx.register_udf(udf);ctxdiff --git a/datafusion/proto/src/lib.rs b/datafusion/proto/src/lib.rsindex 5f5975a900..ecafbed3aa 100644--- a/datafusion/proto/src/lib.rs+++ b/datafusion/proto/src/lib.rs@@ -1256,7 +1256,7 @@ mod roundtrip_tests {filter: Some(Box::new(lit(true))),};- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();ctx.register_udaf(dummy_agg);roundtrip_expr_test(test_expr, ctx);@@ -1281,7 +1281,7 @@ mod roundtrip_tests {args: vec![lit("")],};- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();ctx.register_udf(udf);roundtrip_expr_test(test_expr, ctx);diff --git a/datafusion/proto/src/physical_plan/mod.rs b/datafusion/proto/src/physical_plan/mod.rsindex f890c3ece6..f6b6a0bfe8 100644--- a/datafusion/proto/src/physical_plan/mod.rs+++ b/datafusion/proto/src/physical_plan/mod.rs@@ -1558,7 +1558,7 @@ mod roundtrip_tests {let project =ProjectionExec::try_new(vec![(Arc::new(expr), "a".to_string())], input)?;- let mut ctx = SessionContext::new();+ let ctx = SessionContext::new();ctx.register_udf(udf);