Skip to content
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

Changing keepDate to allow multiple dates, would close #108 #161

Merged
merged 2 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/scala/io/archivesunleashed/spark/rdd/RecordRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ object RecordRDD extends java.io.Serializable {
rdd.filter(r => mimeTypes.contains(r.getMimeType))
}

def keepDate(date: String, component: DateComponent = DateComponent.YYYYMMDD) = {
rdd.filter(r => ExtractDate(r.getCrawlDate, component) == date)
def keepDate(dates: List[String], component: DateComponent = DateComponent.YYYYMMDD) = {
rdd.filter(r => dates.contains(ExtractDate(r.getCrawlDate, component)))
}

def keepUrls(urls: Set[String]) = {
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/io/archivesunleashed/spark/ArcTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class ArcTest extends FunSuite with BeforeAndAfter {

test("filter date") {
val four = RecordLoader.loadArchives(arcPath, sc, keepValidPages = false)
.keepDate("200804", DateComponent.YYYYMM)
.keepDate(List("200804","200805"), DateComponent.YYYYMM)
.map(r => r.getCrawlDate)
.collect()

val five = RecordLoader.loadArchives(arcPath, sc, keepValidPages = false)
.keepDate("200805", DateComponent.YYYYMM)
.keepDate(List("200805","200807"), DateComponent.YYYYMM)
.map(r => r.getCrawlDate)
.collect()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RecordRDDTest extends FunSuite with BeforeAndAfter {
val r = base
.filter (x => ExtractDate(x.getCrawlDate, component) == "2008")
.map ( mp => mp.getUrl).take(3)
val r2 = base.keepDate("2008", component)
val r2 = base.keepDate(List("2008"), component)
.map ( mp => mp.getUrl).take(3)
assert (r2.sameElements(r)) }

Expand Down