Github user yhuai commented on a diff in the pull request:
https://github.com/apache/spark/pull/6090#discussion_r30249859
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/parquet/fsBasedParquet.scala ---
@@ -0,0 +1,565 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.parquet
+
+import java.util.{List => JList}
+
+import scala.collection.JavaConversions._
+import scala.util.Try
+
+import com.google.common.base.Objects
+import org.apache.hadoop.fs.{FileStatus, FileSystem, Path}
+import org.apache.hadoop.io.Writable
+import org.apache.hadoop.mapreduce._
+import org.apache.hadoop.mapreduce.lib.input.FileInputFormat
+import parquet.filter2.predicate.FilterApi
+import parquet.format.converter.ParquetMetadataConverter
+import parquet.hadoop._
+import parquet.hadoop.metadata.CompressionCodecName
+import parquet.hadoop.util.ContextUtil
+
+import org.apache.spark.deploy.SparkHadoopUtil
+import org.apache.spark.rdd.RDD._
+import org.apache.spark.rdd.{NewHadoopPartition, NewHadoopRDD, RDD}
+import org.apache.spark.sql.sources._
+import org.apache.spark.sql.types.{DataType, StructType}
+import org.apache.spark.sql.{Row, SQLConf, SQLContext}
+import org.apache.spark.{Logging, Partition => SparkPartition,
SparkException}
+
+private[sql] class DefaultSource extends FSBasedRelationProvider {
+ override def createRelation(
+ sqlContext: SQLContext,
+ paths: Array[String],
+ schema: Option[StructType],
+ partitionColumns: Option[StructType],
+ parameters: Map[String, String]): FSBasedRelation = {
+ val partitionSpec = partitionColumns.map(PartitionSpec(_, Seq.empty))
+ new FSBasedParquetRelation(paths, schema, partitionSpec,
parameters)(sqlContext)
+ }
+}
+
+// NOTE: This class is instantiated and used on executor side only, no
need to be serializable.
+private[sql] class ParquetOutputWriter extends OutputWriter {
+ private var recordWriter: RecordWriter[Void, Row] = _
+ private var taskAttemptContext: TaskAttemptContext = _
+
+ override def init(
+ path: String,
+ dataSchema: StructType,
+ context: TaskAttemptContext): Unit = {
+ val conf = context.getConfiguration
+ val outputFormat = {
+ // When appending new Parquet files to an existing Parquet file
directory, to avoid
+ // overwriting existing data files, we need to find out the max task
ID encoded in these data
+ // file names.
+ // TODO Make this snippet a utility function for other data source
developers
+ val maxExistingTaskId = {
+ // Note that `path` may point to a temporary location. Here we
retrieve the real
+ // destination path from the configuration
+ val outputPath = new
Path(conf.get("spark.sql.sources.output.path"))
+ val fs = outputPath.getFileSystem(conf)
+
+ if (fs.exists(outputPath)) {
+ // Pattern used to match task ID in part file names, e.g.:
+ //
+ // part-r-00001.gz.part
+ // ^~~~~
+ val partFilePattern = """part-.-(\d{1,}).*""".r
+
+ fs.listStatus(outputPath).map(_.getPath.getName).map {
+ case partFilePattern(id) => id.toInt
+ case name if name.startsWith("_") => 0
+ case name if name.startsWith(".") => 0
+ case name => sys.error(
+ s"""Trying to write Parquet files to directory $outputPath,
+ |but found items with illegal name "$name"
+ """.stripMargin.replace('\n', ' ').trim)
+ }.reduceOption(_ max _).getOrElse(0)
+ } else {
+ 0
+ }
+ }
+
+ new ParquetOutputFormat[Row]() {
+ // Here we override `getDefaultWorkFile` for two reasons:
+ //
+ // 1. To allow appending. We need to generate output file name
based on the max available
+ // task ID computed above.
+ //
+ // 2. To allow dynamic partitioning. Default
`getDefaultWorkFile` uses
+ // `FileOutputCommitter.getWorkPath()`, which points to the
base directory of all
--- End diff --
Seems this comment is outdated?
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]