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

Put try..catch in read files #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 20 additions & 7 deletions src/main/scala/ignition/core/jobs/utils/SparkContextUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ object SparkContextUtils {
} catch {
case NonFatal(ex) =>
println(s"Failed to read resource from '$path': ${ex.getMessage} -- ${ex.getFullStackTraceString}")
throw new Exception(s"Failed to read resource from '$path': ${ex.getMessage} -- ${ex.getFullStackTraceString}")
ArrayBuffer()
} finally {
close(inputStream, path)
}
Expand Down Expand Up @@ -333,7 +333,8 @@ object SparkContextUtils {
AutoCloseableIterator.wrap(finalLines, () => close(inputStream, s"${file.path}, slice $slice"))
} catch {
case NonFatal(e) =>
throw new Exception(s"Error on read compressed big file, slice=$slice, file=$file", e)
println(s"Error on read compressed big file, slice=$slice, file=$file \n $e")
AutoCloseableIterator.empty
}
}
}
Expand All @@ -348,13 +349,25 @@ object SparkContextUtils {
"mapreduce.input.fileinputformat.split.maxsize" -> maxSplitSize.toString))
.foldLeft(new Configuration()) { case (acc, (k, v)) => acc.set(k, v); acc }

def read(file: HadoopFile, conf: Configuration) = sc.newAPIHadoopFile[LongWritable, Text, TextInputFormat](conf = conf, fClass = classOf[TextInputFormat],
kClass = classOf[LongWritable], vClass = classOf[Text], path = file.path).map(pair => pair._2.toString)
def read(file: HadoopFile, conf: Configuration) = {

val confUncompressed = confWith(maxBytesPerPartition)

val union = new UnionRDD(sc, bigFiles.map { file =>
try {
sc.newAPIHadoopFile[LongWritable, Text, TextInputFormat](
conf = conf,
fClass = classOf[TextInputFormat],
kClass = classOf[LongWritable],
vClass = classOf[Text],
path = file.path)
.map(pair => pair._2.toString)
} catch {
case NonFatal(e) =>
println(s"Error on read file=$file\n $e")
sc.emptyRDD[String]
}
}

val confUncompressed = confWith(maxBytesPerPartition)
val union: UnionRDD[String] = new UnionRDD(sc, bigFiles.map { file =>
if (sizeBasedFileHandling.isCompressed(file))
readCompressedBigFile(file, maxBytesPerPartition, minPartitions, sizeBasedFileHandling)
else
Expand Down