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) {