diff --git a/velox/functions/prestosql/StringFunctions.h b/velox/functions/prestosql/StringFunctions.h index c99480199af1..c0e5cae6b329 100644 --- a/velox/functions/prestosql/StringFunctions.h +++ b/velox/functions/prestosql/StringFunctions.h @@ -325,6 +325,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) {