I am facing a problem processing 4TB of Twitter data. I am essentially extracting some information from a DataFrame, then transforming it and finally saving into a directory. The data processing seems to be fine, but for some reason I am getting the issue: Output directory already exists.
This is the output I see when the job failed:
16/05/01 19:55:35 INFO Client: Application report for application_1462042673186_0116 (state: RUNNING) 16/05/01 19:55:36 INFO Client: Application report for application_1462042673186_0116 (state: RUNNING) 16/05/01 19:55:37 INFO Client: Application report for application_1462042673186_0116 (state: RUNNING) 16/05/01 19:55:38 INFO Client: Application report for application_1462042673186_0116 (state: RUNNING) 16/05/01 19:55:39 INFO Client: Application report for application_1462042673186_0116 (state: RUNNING) 16/05/01 19:55:40 INFO Client: Application report for application_1462042673186_0116 (state: RUNNING) 16/05/01 19:55:41 INFO Client: Application report for application_1462042673186_0116 (state: FINISHED) 16/05/01 19:55:41 INFO Client: client token: Token { kind: YARN_CLIENT_TOKEN, service: } diagnostics: N/A ApplicationMaster host: 192.168.43.87 ApplicationMaster RPC port: 0 queue: root.dfb3 start time: 1462142262096 final status: FAILED Exception in thread "main" org.apache.spark.SparkException: Application application_1462042673186_0116 finished with failed status at org.apache.spark.deploy.ya.Client.run(Client.scala:940) at org.apache.spark.deploy.ya.Client$.main(Client.scala:986) at org.apache.spark.deploy.ya.Client.main(Client.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:672) at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180) at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205) at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120) at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) 16/05/01 19:55:41 INFO ShutdownHookManager: Shutdown hook called 16/05/01 19:55:41 INFO ShutdownHookManager: Deleting directory /tmp/spark-4060c9c7-7e35-4f38-9d74-a88cfdc2883b
Here is the function:
def extract(sqlContext: SQLContext, df: DataFrame, outputPath : String) = {
// Selecting only required fields
val socialProfileDF : DataFrame = df.select(
df("actor.id").as("actorTwitterId"), // Twitter id of the actor 0
df("actor.preferredUseame").as("preferredUseame"), // Actor nickname 1
df("postedTime").as("postedTime"), // Time which the account was created 2
df("actor.displayName").as("displayName"), // Name of the actor 3
df("body").as("body"), // get location from Body 4
df("actor.summary").as("summary"), // get location and email from Summary 5
df("actor.location.displayName").as("profileLocation") // get location from Profile 6
)
val socials = socialProfileDF.map(record => {
// actor Name
var name = record.getString(3) match {
case null => ""
case _ => record.getString(3)
}
// Todo: See how many tweets has name of the actor (actor.displayName) are nulls
// Checking if the name has more than 2 words ==> in other case in validate_name will throw an exception
name = this.validate_name(name)
// Considering just valid names
// Actor TwitterID
// ToDo: See how many tweets has actorTwitterId null
val actorTwitterId = record.getString(0) match {
case null => ""
case _ => record.getString(0).split(":")(2)
}
// NickName
// ToDo: See how many tweets has nickName null
val nickName = record.getString(1) match {
case null => ""
case _ => record.getString(1)
}
// Posted Time
// ToDo: See how many tweets has postedTime null
val postedTime = record.getString(2) match {
case null => ""
case _ => record.getString(2)
}
// Getting locations from body tweet
// ToDo: See how many tweets have its body null because detect_entities is getting null pointer exception
var loc_in_body : String = record.getString(4) match {
case null => ""
case _ => this.detect_entities(record.getString(4), 0)
}
// Processing locations from Body
if (loc_in_body.length > 0 ) {
val locationsFromBody : Array[String] = loc_in_body.split("\n")
loc_in_body = locationsFromBody.mkString("|")
} else {
loc_in_body = "tNA"
}
// Getting locations from Actor Summary
// ToDo: See how many tweets have its loc_summary null because detect_entities is getting null pointer exception
val summary : String = record.getString(5)
var loc_in_summary : String = record.getString(5) match {
case null => ""
case _ => record.getString(5)
}
// Processing locations from Summary
if (loc_in_summary.length > 0) {
val locationsFromSummary : Array[String] = loc_in_summary.split("\n")
loc_in_summary = locationsFromSummary.mkString("|")
} else {
loc_in_summary = "tNA";
}
// Getting locations from actor location (profile)
// ToDo: See how many tweets have its loc_in_profile null because detect_entities is getting null pointer exception
var loc_in_profile : String = record.getString(6) match {
case null => ""
case _ => record.getString(6)
}
// Processing locations from profile
if (loc_in_profile.length > 0) {
val locationsFromProfile : Array[String] = loc_in_profile.split("\d")
loc_in_profile = locationsFromProfile.mkString("|")
} else {
loc_in_profile = "tNA"
}
// Getting emails
val emails = this.getEmails(loc_in_summary)
if (name.equals("NONE")) {
("NONE", null)
} else {
(actorTwitterId, (actorTwitterId, nickName, postedTime, loc_in_body, loc_in_summary, loc_in_profile, emails, summary))
}
}).groupByKey().map(record => {
if (!record._1.equals("NONE")) {
val valuesArray : Array[(String, String, String, String, String, String, String, String)] = record._2.toArray
var nickNames : String = ""
var postedTime : String = ""
var locs_in_body : String = ""
var locs_in_summary : String = ""
var locs_in_profile : String = ""
var emails : String = ""
var summary : String = ""
for (v <- valuesArray) {
// NickNames
nickNames = nickNames + v._2 + "|"
postedTime = postedTime + v._3 + "|"
locs_in_body = locs_in_body + v._4 + "|"
locs_in_summary = locs_in_summary + v._5 + "|"
locs_in_profile = locs_in_profile + v._6 + "|"
emails = emails + v._7 + "|"
summary = summary + v._8 + "|"
}
nickNames = nickNames.dropRight(1)
postedTime = postedTime.dropRight(1)
locs_in_body = locs_in_body.dropRight(1)
locs_in_summary = locs_in_summary.dropRight(1)
locs_in_profile = locs_in_profile.dropRight(1)
summary = summary.dropRight(1)
(record._1, nickNames, postedTime, locs_in_body, locs_in_body, locs_in_profile, emails, summary)
}
}).saveAsObjectFile(output)
}
I am ruing the job with the following parameters:
/usr/bin/spark-submit --master ya --deploy-mode cluster --num-executors 100 --executor-cores 8 --executor-memory 55G --driver-memory 55G --class com.unstructureddata.Main twitter-spark-1.0-SNAPSHOT.jar Any idea?
