parthchandra commented on code in PR #3611:
URL: https://github.com/apache/datafusion-comet/pull/3611#discussion_r3061403915
##########
spark/src/main/scala/org/apache/comet/serde/arrays.scala:
##########
@@ -569,6 +569,98 @@ object CometArrayFilter extends
CometExpressionSerde[ArrayFilter] {
}
}
+object CometArrayExists extends CometExpressionSerde[ArrayExists] {
+
+ /** Check if a lambda body contains nested lambda expressions (e.g., nested
exists calls). */
+ private def containsNestedLambda(expr: Expression, currentVar:
NamedLambdaVariable): Boolean = {
Review Comment:
Does `currentVar` get used?
##########
spark/src/test/resources/sql-tests/expressions/array/array_exists.sql:
##########
@@ -0,0 +1,98 @@
+-- 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.
+
+-- ConfigMatrix: parquet.enable.dictionary=false,true
+
+statement
+CREATE TABLE test_array_exists(arr_int array<int>, arr_str array<string>,
arr_double array<double>, arr_bool array<boolean>, arr_long array<bigint>,
threshold int) USING parquet
+
+statement
+INSERT INTO test_array_exists VALUES (array(1, 2, 3), array('a', 'bb', 'ccc'),
array(1.5, 2.5, 3.5), array(false, false, true), array(100, 200, 300), 2),
(array(1, 2), array('a', 'b'), array(0.5, 1.5), array(false, false), array(10,
20), 5), (array(), array(), array(), array(), array(), 0), (NULL, NULL, NULL,
NULL, NULL, 1), (array(1, NULL, 3), array('a', NULL, 'ccc'), array(1.0, NULL,
3.0), array(true, NULL, false), array(100, NULL, 300), 2)
+
+-- basic: element satisfies predicate
+query
+SELECT exists(arr_int, x -> x > 2) FROM test_array_exists
+
+-- no match
+query
+SELECT exists(arr_int, x -> x > 100) FROM test_array_exists
+
+-- empty array returns false
+query
+SELECT exists(arr_int, x -> x > 0) FROM test_array_exists
+
+-- null array returns null
+query
+SELECT exists(arr_int, x -> x > 0) FROM test_array_exists WHERE arr_int IS NULL
+
+-- predicate referencing outer column
+query
+SELECT exists(arr_int, x -> x > threshold) FROM test_array_exists
+
+-- three-valued logic: null elements with no match -> null
+query
+SELECT exists(arr_int, x -> x > 5) FROM test_array_exists
+
+-- null elements but match exists -> true
+query
+SELECT exists(arr_int, x -> x > 2) FROM test_array_exists
+
+-- string type
+query
+SELECT exists(arr_str, x -> length(x) > 2) FROM test_array_exists
+
+-- double type
+query
+SELECT exists(arr_double, x -> x > 2.0) FROM test_array_exists
+
+-- boolean type
+query
+SELECT exists(arr_bool, x -> x) FROM test_array_exists
+
+-- long type
+query
+SELECT exists(arr_long, x -> x > 250) FROM test_array_exists
+
Review Comment:
Should we add a case for TimeStamp/TimestampNTZ?
##########
spark/src/test/resources/sql-tests/expressions/array/array_exists.sql:
##########
@@ -0,0 +1,98 @@
+-- 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.
+
+-- ConfigMatrix: parquet.enable.dictionary=false,true
+
+statement
+CREATE TABLE test_array_exists(arr_int array<int>, arr_str array<string>,
arr_double array<double>, arr_bool array<boolean>, arr_long array<bigint>,
threshold int) USING parquet
+
+statement
+INSERT INTO test_array_exists VALUES (array(1, 2, 3), array('a', 'bb', 'ccc'),
array(1.5, 2.5, 3.5), array(false, false, true), array(100, 200, 300), 2),
(array(1, 2), array('a', 'b'), array(0.5, 1.5), array(false, false), array(10,
20), 5), (array(), array(), array(), array(), array(), 0), (NULL, NULL, NULL,
NULL, NULL, 1), (array(1, NULL, 3), array('a', NULL, 'ccc'), array(1.0, NULL,
3.0), array(true, NULL, false), array(100, NULL, 300), 2)
+
Review Comment:
Might be worth adding a test for `exists(array(0, null, 2, 3, null), x -> x
IS NULL)`. i.e. null elements but the predicate returns a non null value.
--
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]