Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix libsvm and text too
  • Loading branch information
HyukjinKwon committed Oct 28, 2017
commit 5ce9895d24a372fda8b18778b915c0c522ee21e1
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ import org.apache.spark.util.SerializableConfiguration
private[libsvm] class LibSVMOutputWriter(
path: String,
dataSchema: StructType,
lineSeparator: Option[String],
lineSeparator: String,
context: TaskAttemptContext)
extends OutputWriter {

private val lineSep = lineSeparator.getOrElse("\n")

private val writer = CodecStreams.createOutputStreamWriter(context, new Path(path))

// This `asInstanceOf` is safe because it's guaranteed by `LibSVMFileFormat.verifySchema`
Expand All @@ -60,7 +58,7 @@ private[libsvm] class LibSVMOutputWriter(
writer.write(s" ${i + 1}:$v")
}

writer.write(lineSep)
writer.write(lineSeparator)
}

override def close(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ object MLUtils extends Logging {
private[spark] def parseLibSVMFile(
sparkSession: SparkSession,
paths: Seq[String],
lineSep: Option[String]): RDD[(Double, Array[Int], Array[Double])] = {
val textOptions = lineSep
.map(sep => Map(TextOptions.LINE_SEPARATOR -> sep))
.getOrElse(Map.empty[String, String])
lineSeparator: String): RDD[(Double, Array[Int], Array[Double])] = {
val textOptions = Map(TextOptions.LINE_SEPARATOR -> lineSeparator)

val lines = sparkSession.baseRelationToDataFrame(
DataSource.apply(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SimpleTextSource extends TextBasedFileFormat with DataSourceRegister {
val projection = new InterpretedProjection(outputAttributes, inputAttributes)

val unsafeRowIterator =
new HadoopFileLinesReader(file, None, broadcastedHadoopConf.value.value).map { line =>
new HadoopFileLinesReader(file, "\n", broadcastedHadoopConf.value.value).map { line =>
val record = line.toString
new GenericInternalRow(record.split(",", -1).zip(fieldTypes).map {
case (v, dataType) =>
Expand Down