Github user lw-lin commented on a diff in the pull request: https://github.com/apache/spark/pull/13575#discussion_r66466672 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/json/JsonFileFormat.scala --- @@ -146,16 +173,53 @@ class JsonFileFormat extends FileFormat with DataSourceRegister { } } - override def toString: String = "JSON" - override def hashCode(): Int = getClass.hashCode() override def equals(other: Any): Boolean = other.isInstanceOf[JsonFileFormat] } -private[json] class JsonOutputWriter( - path: String, - bucketId: Option[Int], +/** + * A factory for generating [[OutputWriter]]s for writing json files. This is implemented different + * from the 'batch' JsonOutputWriter as this does not use any [[OutputCommitter]]. It simply + * writes the data to the path used to generate the output writer. Callers of this factory + * has to ensure which files are to be considered as committed. + */ +private[json] class StreamingJsonOutputWriterFactory( + sqlConf: SQLConf, + dataSchema: StructType, + hadoopConf: Configuration, + options: Map[String, String]) extends StreamingOutputWriterFactory { + + private val serializableConf = { + val conf = Job.getInstance(hadoopConf).getConfiguration + JsonFileFormat.prepareConfForWriting(conf, options) + new SerializableConfiguration(conf) + } + + /** + * Returns a [[OutputWriter]] that writes data to the give path without using an + * [[OutputCommitter]]. + */ + override private[sql] def newWriter(path: String): OutputWriter = { + val hadoopTaskAttempId = new TaskAttemptID(new TaskID(new JobID, TaskType.MAP, 0), 0) + val hadoopAttemptContext = + new TaskAttemptContextImpl(serializableConf.value, hadoopTaskAttempId) + // Returns a 'streaming' JsonOutputWriter + new JsonOutputWriterBase(dataSchema, hadoopAttemptContext) { + override private[json] val recordWriter: RecordWriter[NullWritable, Text] = + createNoCommitterTextRecordWriter( + path, + hadoopAttemptContext, + (c: TaskAttemptContext, ext: String) => { new Path(s"$path.json$ext") }) + } + } +} + +/** + * Base JsonOutputWriter class for 'batch' JsonOutputWriter and 'streaming' JsonOutputWriter. The + * writing logic to a single file resides in this base class. + */ +private[json] abstract class JsonOutputWriterBase( --- End diff -- This `JsonOutputWriterBase` is basically the original `JsonOutputWriter`
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org