-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes
More file actions
37 lines (29 loc) · 1.21 KB
/
notes
File metadata and controls
37 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Dataframes
- Dataset allow to use Options properly
Datasets and options :
- Datasets of Option[CaseClass] always deserialize as Datasets of Some(CaseClass(null, null..)) , Some... . The difference Some/None is lost
So instead of using map , use flatmap that will flatten the options
// With map will build Some() instead of None
recordsDs
.map { record =>
val maybeArticle = unmarshallArticle(record)
if (maybeArticle.isEmpty) {
println(s"Could not parse record $record into an article.")
}
maybeArticle
}
.filter(_.isDefined)
.map(_.get)
.collect().toList
//With flatMap behave properly
recordsDs
.flatMap { record =>
val maybeArticle = unmarshallTwitterArticle(record)
if (maybeArticle.isEmpty) {
//TODO At the moment uses simple print for serialization purpose, need to store those errors somewhere else
println(s"Could not parse record $record into an article.")
}
maybeArticle
}
.collect().toList
TODO : contribute to json4s to detect abstract class Constructor use attempt https://github.com/json4s/json4s/pull/331/commits/627f5474fda8bbe34ee2aaa24e595ff28610a4f0