-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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-6994] Allow to fetch field values by name in sql.Row #5573
Conversation
496cd36
to
10ae4d8
Compare
|
||
object RowImplicits { | ||
|
||
implicit class RowWithNamedFields[K, V](sqlRow: Row) { |
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.
why don't we just add this to Row itself?
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.
👍 if so, I guess I should rename getValue[T]
into an overloaded getAs[T](fieldName: String)
to be consistent with an existing method getAs
? (I remember overloading didn't work with implicits...)
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.
yup sounds good
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.
For the new method to be convenient to use it should go into Row
.
However, the schema is not always defined for a Row
, so Row.getAs[T](fieldName: String)
with throw an UnsupportedOperationException
.
GenericRowWithSchema
will implement the case when schema exists.
d823862
to
49698a4
Compare
49698a4
to
a9a8854
Compare
moved the changes to the also got rid of dependency on HiveTest. |
a9a8854
to
0a2b8b0
Compare
- add fieldIndex(name: String) - add getAs[T](fieldName: String) - add getValuesMap[T] returning a map of values for the requested fieldNames
0a2b8b0
to
6145ae3
Compare
it's slightly weird that there exists a P.S. isn't jenkins supposted to run tests on this PR? |
ok to test |
Test build #30611 has finished for PR 5573 at commit
|
Thanks, merged to master. |
It looked weird that up to now there was no way in Spark's Scala API to access fields of `DataFrame/sql.Row` by name, only by their index. This tries to solve this issue. Author: vidmantas zemleris <[email protected]> Closes apache#5573 from vidma/features/row-with-named-fields and squashes the following commits: 6145ae3 [vidmantas zemleris] [SPARK-6994][SQL] Allow to fetch field values by name on Row 9564ebb [vidmantas zemleris] [SPARK-6994][SQL] Add fieldIndex to schema (StructType)
It looked weird that up to now there was no way in Spark's Scala API to access fields of
DataFrame/sql.Row
by name, only by their index.This tries to solve this issue.