-
Notifications
You must be signed in to change notification settings - Fork 138
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
add when column method #220
Conversation
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.
LGTM!
object when { | ||
/** Non-Aggregate function: Evaluates a list of conditions and returns one of multiple | ||
* possible result expressions. If none match, otherwise is returned | ||
* |
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.
can we add an example here?
@imarios yet again thanks for your review! Comments addressed. |
Hey @frosforever So I played a bit with the code and came up with what I believe is a simplified implementation. ... rest of NonAggregateFunctions
/** Non-Aggregate function: Evaluates a list of conditions and returns one of multiple
* possible result expressions. If none match, otherwise is returned
* {{{
* when(ds('boolField), ds('a))
* .when(ds('otherBoolField), lit(123))
* .otherwise(ds('b))
* }}}
* apache/spark
*/
def when[T, A](condition: TypedColumn[T, Boolean], value: TypedColumn[T, A]): When[T, A] =
new When[T, A](untyped.when(condition.untyped, value.untyped))
}
private[functions] class When[T, A](untypedC: Column) {
def when(condition: TypedColumn[T, Boolean], value: TypedColumn[T, A]): When[T, A] = new When[T, A](
untypedC.when(condition.untyped, value.untyped)
)
def otherwise(value: TypedColumn[T, A]): TypedColumn[T, A] =
new TypedColumn[T, A](untypedC.otherwise(value.untyped))(value.uencoder)
} What do you think? |
@imarios Ha! that's nearly identical to a version I had earlier! Swapped it out for the one I pushed up for some reason that I can't seem to recall anymore... |
The #218 merge created some conflicts 😕 |
@frosforever can you resolve conflicts rebase/squash? I will merge as soon as everything clears from CI. |
b7f57d7
to
60f0df0
Compare
Thanks for the reviews @imarios and @OlivierBlanvillain! Conflicts resolved |
@frosforever Thanks for the PR! 👍 |
connects to #164
Differs from the spark implementation in that it requires an
otherwise
and will not default tonull
.