From 9b6b51254098e3ae72dea161edee547a10d87d44 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 5aa7a10bec472..57781f31318fe 100644 --- a/velox/functions/prestosql/StringFunctions.h +++ b/velox/functions/prestosql/StringFunctions.h @@ -104,6 +104,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) {