From 8b6ba5a2e0e8067008cb75a631c94af67624e4e5 Mon Sep 17 00:00:00 2001 From: JiaKe Date: Wed, 4 Jan 2023 08:56:29 +0000 Subject: [PATCH] Fix the result mismatch for right expression (#107) --- velox/functions/prestosql/StringFunctions.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/velox/functions/prestosql/StringFunctions.h b/velox/functions/prestosql/StringFunctions.h index 00c71690be08a..7c47fda704e99 100644 --- a/velox/functions/prestosql/StringFunctions.h +++ b/velox/functions/prestosql/StringFunctions.h @@ -349,6 +349,13 @@ struct SubstrFunction { if (start < 0) { start = numCharacters + start + 1; } + + // Following vanilla spark semantics. When the start is 0 after adjusing start, + // Keep the origin input. + if (start <= 0) { + start = 1; + length = numCharacters; + } // Following Presto semantics if (start <= 0 || start > numCharacters || length <= 0) {