Re: [PR] Optimize `replace_params_with_values` [datafusion]

2024-11-10 Thread via GitHub


alamb merged PR #13308:
URL: https://github.com/apache/datafusion/pull/13308


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



Re: [PR] Optimize `replace_params_with_values` [datafusion]

2024-11-09 Thread via GitHub


askalt commented on code in PR #13308:
URL: https://github.com/apache/datafusion/pull/13308#discussion_r1835336179


##
datafusion/expr/src/logical_plan/plan.rs:
##
@@ -1423,18 +1423,22 @@ impl LogicalPlan {
 let schema = Arc::clone(plan.schema());
 let name_preserver = NamePreserver::new(&plan);
 plan.map_expressions(|e| {
-let original_name = name_preserver.save(&e);
-let transformed_expr =
-e.infer_placeholder_types(&schema)?.transform_up(|e| {
+let (e, has_placeholder) = e.infer_placeholder_types(&schema)?;
+if !has_placeholder {

Review Comment:
   Applied, thank you!



##
datafusion/core/benches/expr.rs:
##
@@ -0,0 +1,88 @@
+// 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 std::sync::Arc;
+
+use arrow_array::{Array, Int32Array, RecordBatch};
+use arrow_schema::{Field, Schema, SchemaRef};
+use criterion::{criterion_group, criterion_main, Criterion};
+use datafusion::prelude::SessionContext;
+use datafusion_common::ScalarValue;
+use tokio::runtime::Runtime;
+
+const COLUMNS_NUM: usize = 200;
+

Review Comment:
   Moved.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



Re: [PR] Optimize `replace_params_with_values` [datafusion]

2024-11-08 Thread via GitHub


alamb commented on code in PR #13308:
URL: https://github.com/apache/datafusion/pull/13308#discussion_r1835021038


##
datafusion/expr/src/logical_plan/plan.rs:
##
@@ -1423,18 +1423,22 @@ impl LogicalPlan {
 let schema = Arc::clone(plan.schema());
 let name_preserver = NamePreserver::new(&plan);
 plan.map_expressions(|e| {
-let original_name = name_preserver.save(&e);
-let transformed_expr =
-e.infer_placeholder_types(&schema)?.transform_up(|e| {
+let (e, has_placeholder) = e.infer_placeholder_types(&schema)?;
+if !has_placeholder {

Review Comment:
   I think the rationale may not be obvious to a future reader. Here is a 
suggestion:
   
   ```suggestion
   // Performance optimization: avoid NamePreserver  copy if no 
placeholders
   if !has_placeholder {
   ```



##
datafusion/core/benches/expr.rs:
##
@@ -0,0 +1,88 @@
+// 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 std::sync::Arc;
+
+use arrow_array::{Array, Int32Array, RecordBatch};
+use arrow_schema::{Field, Schema, SchemaRef};
+use criterion::{criterion_group, criterion_main, Criterion};
+use datafusion::prelude::SessionContext;
+use datafusion_common::ScalarValue;
+use tokio::runtime::Runtime;
+
+const COLUMNS_NUM: usize = 200;
+

Review Comment:
   I recommend putting this in 
https://github.com/apache/datafusion/blob/main/datafusion/core/benches/sql_planner.rs
 so that it gets run more regularly / show up when we are looking at potential 
impacts on planning speed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



Re: [PR] Optimize `replace_params_with_values` [datafusion]

2024-11-08 Thread via GitHub


jonahgao commented on code in PR #13308:
URL: https://github.com/apache/datafusion/pull/13308#discussion_r1834440329


##
datafusion/expr/src/expr.rs:
##
@@ -1598,7 +1598,11 @@ impl Expr {
 ///
 /// For example, gicen an expression like ` = $0` will infer `$0` to
 /// have type `int32`.
-pub fn infer_placeholder_types(self, schema: &DFSchema) -> Result {
+///
+/// Returns transformed expression and flag that is true if expression 
contains
+/// at least one placeholder.

Review Comment:
   👍



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



Re: [PR] Optimize `replace_params_with_values` [datafusion]

2024-11-08 Thread via GitHub


askalt commented on PR #13308:
URL: https://github.com/apache/datafusion/pull/13308#issuecomment-2464701970

   @jonahgao Could you please take a look at this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org



Re: [PR] Optimize `replace_params_with_values` [datafusion]

2024-11-08 Thread via GitHub


askalt commented on PR #13308:
URL: https://github.com/apache/datafusion/pull/13308#issuecomment-2464461845

   I am working on tests.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org