Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/7534#discussion_r35070553
--- Diff:
unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java ---
@@ -165,6 +165,18 @@ public UTF8String substring(final int start, final int
until) {
return fromBytes(bytes);
}
+ public UTF8String substringSQL(int pos, int length) {
+ // Information regarding the pos calculation:
+ // Hive and SQL use one-based indexing for SUBSTR arguments but also
accept zero and
+ // negative indices for start positions. If a start index i is greater
than 0, it
+ // refers to element i-1 in the sequence. If a start index i is less
than 0, it refers
+ // to the -ith element before the end of the sequence. If a start
index i is 0, it
+ // refers to the first element.
+ int start = (pos > 0) ? pos -1 : ((pos < 0) ? numChars() + pos : 0);
--- End diff --
cc @davies also
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]