-
Notifications
You must be signed in to change notification settings - Fork 138
Add a typed 'substr' column method #263
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -471,6 +471,31 @@ abstract class AbstractTypedColumn[T, U] | |
| def cast[A: TypedEncoder](implicit c: CatalystCast[U, A]): ThisType[T, A] = | ||
| typed(self.untyped.cast(TypedEncoder[A].catalystRepr)) | ||
|
|
||
| /** | ||
| * An expression that returns a substring | ||
| * {{{ | ||
| * df.select(df('a).substr(0, 5)) | ||
| * }}} | ||
| * | ||
| * @param startPos starting position | ||
| * @param len length of the substring | ||
| */ | ||
| def substr(startPos: Int, len: Int)(implicit ev: U =:= String): ThisType[T, String] = | ||
| typed(self.untyped.substr(startPos, len)) | ||
|
|
||
| /** | ||
| * An expression that returns a substring | ||
| * {{{ | ||
| * df.select(df('a).substr(df('b), df('c))) | ||
| * }}} | ||
| * | ||
| * @param startPos expression for the starting position | ||
| * @param len expression for the length of the substring | ||
| */ | ||
| def substr[TT, W](startPos: ThisType[TT, Int], len: ThisType[TT, Int]) | ||
|
||
| (implicit ev: U =:= String, w: With.Aux[T, TT, W]): ThisType[W, String] = | ||
| typed(self.untyped.substr(startPos.untyped, len.untyped)) | ||
|
|
||
| /** String contains another string literal. | ||
| * {{{ | ||
| * df.filter ( df.col('a).contains("foo") ) | ||
|
|
||
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: in Spark, is it possible to we mix literals and columns? (
.substr(0, df('a)))Uh oh!
There was an error while loading. Please reload this page.
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.
nope, there are only
substr(startPos: Int, len: Int)andsubstr(startPos: Column, len: Column)