-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23291][SQL][R] R's substr should not reduce starting position by 1 when calling Scala API #20464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-23291][SQL][R] R's substr should not reduce starting position by 1 when calling Scala API #20464
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,12 +164,18 @@ setMethod("alias", | |
| #' @aliases substr,Column-method | ||
| #' | ||
| #' @param x a Column. | ||
| #' @param start starting position. | ||
| #' @param start starting position. It should be 1-base. | ||
| #' @param stop ending position. | ||
| #' @examples | ||
| #' \dontrun{ | ||
| #' df <- createDataFrame(list(list(a="abcdef"))) | ||
| #' collect(select(df, substr(df$a, 1, 4))) # the result is `abcd`. | ||
| #' collect(select(df, substr(df$a, 2, 4))) # the result is `bcd`. | ||
| #' } | ||
| #' @note substr since 1.4.0 | ||
| setMethod("substr", signature(x = "Column"), | ||
| function(x, start, stop) { | ||
| jc <- callJMethod(x@jc, "substr", as.integer(start - 1), as.integer(stop - start + 1)) | ||
| jc <- callJMethod(x@jc, "substr", as.integer(start), as.integer(stop - start + 1)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should do two things:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you mean 1-base.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to the func doc. |
||
| column(jc) | ||
| }) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concern with changing this. As you can see it's been like this from the very beginning...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API behavior should be considered as wrong and performs inconsistently. Because for starting position 1, we get substring from 1st element, but for position 2, we still get the substring from 1. So we will get the following inconsistent results:
For such change, we might need to add a note in the doc as @HyukjinKwon suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question:
[SPARK-23291][SQL][R] R's substr should not reduce starting position by 1 when calling Scala API #20464 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because I think it is another issue regarding 0/negative indices. I can deal it here if you strongly feel it is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep the behavior when calling substr with 0 as start index?
I think the previous behavior is pretty unreasonable..