This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new e3e64fe8c1 test: port strpos test in physical_expr/src/functions to
sqllogictest (#9439)
e3e64fe8c1 is described below
commit e3e64fe8c1a5969622d39f4caf2a18cb19196a35
Author: SteveLauC <[email protected]>
AuthorDate: Sat Mar 9 06:17:37 2024 +0800
test: port strpos test in physical_expr/src/functions to sqllogictest
(#9439)
---
datafusion/physical-expr/src/functions.rs | 151 +-------------------------
datafusion/sqllogictest/test_files/scalar.slt | 75 +++++++++++++
2 files changed, 76 insertions(+), 150 deletions(-)
diff --git a/datafusion/physical-expr/src/functions.rs
b/datafusion/physical-expr/src/functions.rs
index 5838d9c74e..db53ac986d 100644
--- a/datafusion/physical-expr/src/functions.rs
+++ b/datafusion/physical-expr/src/functions.rs
@@ -892,7 +892,7 @@ mod tests {
use arrow::{
array::{
Array, ArrayRef, BinaryArray, BooleanArray, Float32Array,
Float64Array,
- Int32Array, Int64Array, StringArray, UInt64Array,
+ Int32Array, StringArray, UInt64Array,
},
datatypes::Field,
record_batch::RecordBatch,
@@ -2310,155 +2310,6 @@ mod tests {
BooleanArray
);
#[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("abc"), lit("c"),],
- Ok(Some(3)),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("abc"), lit("d")],
- Ok(Some(0)),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("abc"), lit("")],
- Ok(Some(1)),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("Helloworld"), lit("world")],
- Ok(Some(6)),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("Helloworld"), lit(ScalarValue::Utf8(None))],
- Ok(None),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit(ScalarValue::Utf8(None)), lit("Hello")],
- Ok(None),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[
- lit(ScalarValue::LargeUtf8(Some("Helloworld".to_string()))),
- lit(ScalarValue::LargeUtf8(Some("world".to_string())))
- ],
- Ok(Some(6)),
- i64,
- Int64,
- Int64Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[
- lit(ScalarValue::LargeUtf8(None)),
- lit(ScalarValue::LargeUtf8(Some("world".to_string())))
- ],
- Ok(None),
- i64,
- Int64,
- Int64Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[
- lit(ScalarValue::LargeUtf8(Some("Helloworld".to_string()))),
- lit(ScalarValue::LargeUtf8(None))
- ],
- Ok(None),
- i64,
- Int64,
- Int64Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("josé"), lit("é"),],
- Ok(Some(4)),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("joséésoj"), lit("so"),],
- Ok(Some(6)),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("joséésoj"), lit("abc"),],
- Ok(Some(0)),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit(ScalarValue::Utf8(None)), lit("abc"),],
- Ok(None),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
- test_function!(
- Strpos,
- &[lit("joséésoj"), lit(ScalarValue::Utf8(None)),],
- Ok(None),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(not(feature = "unicode_expressions"))]
- test_function!(
- Strpos,
- &[
- lit("joséésoj"),
- lit(ScalarValue::Utf8(None)),
- ],
- internal_err!(
- "function strpos requires compilation with feature flag:
unicode_expressions."
- ),
- i32,
- Int32,
- Int32Array
- );
- #[cfg(feature = "unicode_expressions")]
test_function!(
Substr,
&[lit("alphabet"), lit(ScalarValue::Int64(Some(0))),],
diff --git a/datafusion/sqllogictest/test_files/scalar.slt
b/datafusion/sqllogictest/test_files/scalar.slt
index a64fcbbdbc..a77a2bf405 100644
--- a/datafusion/sqllogictest/test_files/scalar.slt
+++ b/datafusion/sqllogictest/test_files/scalar.slt
@@ -2089,3 +2089,78 @@ select position('' in '')
query error DataFusion error: Error during planning: The STRPOS/INSTR/POSITION
function can only accept strings, but got Int64.
select position(1 in 1)
+
+
+query I
+select strpos('abc', 'c');
+----
+3
+
+query I
+select strpos('abc', 'd');
+----
+0
+
+
+query I
+select strpos('abc', '');
+----
+1
+
+query I
+select strpos('helloworld', 'world');
+----
+6
+
+query I
+select strpos('helloworld', arrow_cast(null, 'Utf8'));
+----
+NULL
+
+query I
+select strpos(arrow_cast(null, 'Utf8'), 'hello');
+----
+NULL
+
+query I
+select strpos(arrow_cast('Helloworld', 'LargeUtf8'), arrow_cast('world',
'LargeUtf8'));
+----
+6
+
+query I
+select strpos(arrow_cast(null, 'LargeUtf8'), arrow_cast('world', 'LargeUtf8'));
+----
+NULL
+
+query I
+select strpos(arrow_cast('Helloworld', 'LargeUtf8'), arrow_cast(null,
'LargeUtf8'));
+----
+NULL
+
+query I
+select strpos('josé', 'é');
+----
+4
+
+query I
+select strpos('joséésoj', 'so');
+----
+6
+
+
+query I
+select strpos('joséésoj', 'abc');
+----
+0
+
+query I
+select strpos(arrow_cast(null, 'Utf8'), 'abc');
+----
+NULL
+
+query I
+select strpos('joséésoj', arrow_cast(null, 'Utf8'));
+----
+NULL
+
+