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

Revert "make ArchiveRecord a trait (#175)" #181

Merged
merged 1 commit into from
Mar 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,7 @@ import io.archivesunleashed.io.ArchiveRecordWritable.ArchiveFormat
import io.archivesunleashed.spark.matchbox.ExtractDate.DateComponent
import io.archivesunleashed.spark.matchbox.{RemoveHttpHeader, ExtractDate, ExtractDomain}

object ArchiveRecord {
val ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX")
}

trait ArchiveRecord extends Serializable {
def getCrawlDate: String

def getCrawlMonth: String

def getContentBytes: Array[Byte]

def getContentString: String

def getMimeType: String

def getUrl: String

def getDomain: String

def getImageBytes: Array[Byte]
}

class ArchiveRecordImpl(r: SerializableWritable[ArchiveRecordWritable]) extends ArchiveRecord {
import ArchiveRecord._

class ArchiveRecord(r: SerializableWritable[ArchiveRecordWritable]) extends Serializable {
var arcRecord: ARCRecord = null
var warcRecord: WARCRecord = null

Expand All @@ -62,6 +38,9 @@ class ArchiveRecordImpl(r: SerializableWritable[ArchiveRecordWritable]) extends
else if (r.t.getFormat == ArchiveFormat.WARC)
warcRecord = r.t.getRecord.asInstanceOf[WARCRecord]


val ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX")

val getCrawlDate: String = {
if (r.t.getFormat == ArchiveFormat.ARC) {
ExtractDate(arcRecord.getMetaData.getDate, DateComponent.YYYYMMDD)
Expand All @@ -88,15 +67,15 @@ class ArchiveRecordImpl(r: SerializableWritable[ArchiveRecordWritable]) extends

val getContentString: String = new String(getContentBytes)

val getMimeType: String = {
val getMimeType = {
if (r.t.getFormat == ArchiveFormat.ARC) {
arcRecord.getMetaData.getMimetype
} else {
WarcRecordUtils.getWarcResponseMimeType(getContentBytes)
}
}

val getUrl: String = {
val getUrl = {
if (r.t.getFormat == ArchiveFormat.ARC) {
arcRecord.getMetaData.getUrl
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.json4s.jackson.JsonMethods._
import io.archivesunleashed.io.ArchiveRecordWritable.ArchiveFormat
import io.archivesunleashed.io.ArchiveRecordWritable
import io.archivesunleashed.mapreduce.WacInputFormat
import io.archivesunleashed.spark.archive.io._
import io.archivesunleashed.spark.archive.io.ArchiveRecord
import io.archivesunleashed.spark.rdd.RecordRDD._

object RecordLoader {
Expand All @@ -34,7 +34,7 @@ object RecordLoader {
sc.newAPIHadoopFile(path, classOf[WacInputFormat], classOf[LongWritable], classOf[ArchiveRecordWritable])
.filter(r => (r._2.getFormat == ArchiveFormat.ARC) ||
((r._2.getFormat == ArchiveFormat.WARC) && r._2.getRecord.getHeader.getHeaderValue("WARC-Type").equals("response")))
.map(r => new ArchiveRecordImpl(new SerializableWritable(r._2)))
.map(r => new ArchiveRecord(new SerializableWritable(r._2)))

if (keepValidPages) rdd.keepValidPages() else rdd
}
Expand Down