2010YOUY01 opened a new pull request, #12383: URL: https://github.com/apache/datafusion/pull/12383
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> N.A. ## Rationale for this change Recently native `StringView` type support is implemented on `substr()` string function, but its behaviour is not consistent with the older implementation on `StringArray` string physical column type The function semantics on the origina `StringArray` type is consistent with postgres https://www.postgresql.org/docs/9.1/functions-string.html The postgres version of `substr(s, start, count)`'s behavior is: `start` is 1-indexed, then we have a maybe out of bounds , and 0-indexed character range `[start-1, start-1+count)` , the valid char range is `[0, s.chars().count())`, and this function will take the intersection of two. They handle negative start index differently and also handle invalid range differently ``` DataFusion CLI v41.0.0 > select substr('foo', -2,4), substr(arrow_cast('foo', 'Utf8View'), -2, 4); +----------------------------------------+---------------------------------------------------------------------+ | substr(Utf8("foo"),Int64(-2),Int64(4)) | substr(arrow_cast(Utf8("foo"),Utf8("Utf8View")),Int64(-2),Int64(4)) | +----------------------------------------+---------------------------------------------------------------------+ | f | foo | +----------------------------------------+---------------------------------------------------------------------+ 1 row(s) fetched. Elapsed 0.104 seconds. > select substr('', -10, 5)='', substr(arrow_cast('', 'Utf8View'), -10, 5)=''; +-------------------------------------------------+------------------------------------------------------------------------------+ | substr(Utf8(""),Int64(-10),Int64(5)) = Utf8("") | substr(arrow_cast(Utf8(""),Utf8("Utf8View")),Int64(-10),Int64(5)) = Utf8("") | +-------------------------------------------------+------------------------------------------------------------------------------+ | true | | +-------------------------------------------------+------------------------------------------------------------------------------+ 1 row(s) fetched. Elapsed 0.010 seconds. ``` <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? `substr`'s behavior is already consistent with postgres if input is `StringArray` This PR changes implementation to keep `StringView` version also consistent with postgres <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? Added more sqllogictests <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org