From f8c623fe045d70a87eac8dc8620b74ff73be56d5 Mon Sep 17 00:00:00 2001 From: Jonah Gao Date: Sat, 27 Apr 2024 02:30:09 +0800 Subject: [PATCH] fix: no longer support the `substring` function (#10242) * fix: no longer support the `substring` function * enable from-for format * update test comment * review feedback * review feedback Co-authored-by: Jeffrey Vo --------- Co-authored-by: Jeffrey Vo --- datafusion/sql/src/expr/mod.rs | 2 +- datafusion/sqllogictest/test_files/expr.slt | 29 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/datafusion/sql/src/expr/mod.rs b/datafusion/sql/src/expr/mod.rs index 0d1db8a29cce..13f559a0ebc7 100644 --- a/datafusion/sql/src/expr/mod.rs +++ b/datafusion/sql/src/expr/mod.rs @@ -467,7 +467,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { expr, substring_from, substring_for, - special: false, + special: _, } => self.sql_substring_to_expr( expr, substring_from, diff --git a/datafusion/sqllogictest/test_files/expr.slt b/datafusion/sqllogictest/test_files/expr.slt index adc577f12f91..ff63416b3a10 100644 --- a/datafusion/sqllogictest/test_files/expr.slt +++ b/datafusion/sqllogictest/test_files/expr.slt @@ -1871,6 +1871,17 @@ SELECT digest('','blake3'); ---- af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262 + +query T +SELECT substring('alphabet', 1) +---- +alphabet + +query T +SELECT substring('alphabet', 3, 2) +---- +ph + query T SELECT substring('alphabet' from 2 for 1); ---- @@ -1886,6 +1897,24 @@ SELECT substring('alphabet' for 1); ---- a +# The 'from' and 'for' parameters don't support string types, because they should be treated as +# regular expressions, which we have not implemented yet. +query error DataFusion error: Error during planning: No function matches the given name and argument types +SELECT substring('alphabet' FROM '3') + +query error DataFusion error: Error during planning: No function matches the given name and argument types +SELECT substring('alphabet' FROM '3' FOR '2') + +query error DataFusion error: Error during planning: No function matches the given name and argument types +SELECT substring('alphabet' FROM '3' FOR 2) + +query error DataFusion error: Error during planning: No function matches the given name and argument types +SELECT substring('alphabet' FROM 3 FOR '2') + +query error DataFusion error: Error during planning: No function matches the given name and argument types +SELECT substring('alphabet' FOR '2') + + ##### csv_query_nullif_divide_by_0