rich7420 commented on code in PR #7456:
URL: https://github.com/apache/datafusion-comet/pull/7456#discussion_r4704557732


##########
native/spark-expr/src/conditional_funcs/case_when.rs:
##########
@@ -467,6 +476,26 @@ fn infallible(expr: &Arc<dyn PhysicalExpr>, input_schema: 
&Schema, parsing: bool
         } else {
             cast.is_infallible(input_schema)
         }
+    } else if let Some(check) = expr.downcast_ref::<CheckOverflow>() {
+        // Without `fail_on_error` a decimal that overflows the precision 
becomes NULL
+        parsing
+            && !check.fail_on_error
+            && matches!(check.data_type, DataType::Decimal128(_, _))
+            && matches!(
+                check.child.data_type(input_schema),
+                Ok(DataType::Decimal128(_, _))
+            )
+    } else if let Some(function) = expr.downcast_ref::<ScalarFunctionExpr>() {
+        // Named as the planner names the functions it builds from Spark's, in
+        // `create_scalar_function_expr`
+        parsing && STRING_FUNCTIONS_THAT_CANNOT_FAIL.contains(&function.name())

Review Comment:
   Could AND/OR skip the new `cannot_fail` cases? With `x AND substring(s, 2, 
4) = '2345'` at 25% pending, I measured 133 µs/batch versus 48 µs with 
`LazyLogical`.



##########
native/spark-expr/benches/null_short_circuit.rs:
##########
@@ -0,0 +1,273 @@
+// 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.
+//! Benchmarks for arithmetic and `concat` whose second operand can fail.
+//!
+//! Each shape runs as `eager`, evaluating both operands over the whole batch, 
and as `lazy`, the
+//! way Comet plans it now, evaluating the second operand only for the rows 
where the first one is
+//! not NULL unless it cannot fail. The data is valid in every row, so both 
forms succeed, and the
+//! difference is the cost of skipping the rows Spark skips.
+
+use arrow::array::{ArrayRef, Decimal128Array, Int64Array, StringArray};
+use arrow::datatypes::{DataType, Field, Schema};
+use arrow::record_batch::RecordBatch;
+use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, 
Throughput};
+use datafusion::common::ScalarValue;
+use datafusion::config::ConfigOptions;
+use datafusion::logical_expr::{Operator, ScalarUDF};
+use datafusion::physical_expr::expressions::{BinaryExpr, Column, Literal};
+use datafusion::physical_expr::{PhysicalExpr, ScalarFunctionExpr};
+use datafusion::prelude::SessionContext;
+use datafusion_comet_spark_expr::{
+    create_comet_physical_fun_with_eval_mode, Cast, CheckOverflow, EvalMode, 
NullShortCircuit,
+    SparkCastOptions, WideDecimalBinaryExpr, WideDecimalOp,
+};
+use datafusion_spark::function::string::concat::SparkConcat;
+use rand::rngs::StdRng;
+use rand::{RngExt, SeedableRng};
+use std::hint::black_box;
+use std::sync::Arc;
+
+const NUM_ROWS: usize = 8192;
+
+const DECIMAL: DataType = DataType::Decimal128(12, 2);
+
+type Expr = Arc<dyn PhysicalExpr>;
+
+/// An expression: its name, how to build it, and whether Comet wraps it in 
`NullShortCircuit`
+type Shape = (&'static str, fn() -> Expr, bool);
+
+/// `a` a long with `null_density` of it NULL, `p` the same as a decimal and 
`q` as a string, and
+/// `b`, `c`, `s`, a long written as a string, and `d`, a decimal, never NULL.
+fn make_batch(null_density: f32) -> RecordBatch {
+    let mut rng = StdRng::seed_from_u64(42);
+    let a: Int64Array = (0..NUM_ROWS)
+        .map(|_| (rng.random::<f32>() >= null_density).then(|| 
rng.random_range(0..1000)))

Review Comment:
   Could `make_batch` make exactly `null_density` of the rows NULL? Seed 42 
gives `nulls_50` 4108 NULLs, which just misses the 50% speculation threshold.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to