Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.apache.parquet.hadoop.api.WriteSupport
import org.apache.parquet.hadoop.api.WriteSupport.WriteContext
import org.apache.parquet.io.api.{Binary, RecordConsumer}

import org.apache.spark.SPARK_VERSION
import org.apache.spark.internal.Logging
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.SpecializedGetters
Expand Down Expand Up @@ -115,6 +116,10 @@ private[parquet] class ParquetWriteSupport extends WriteSupport[InternalRow] wit
}
}

override def getName: String = {
SPARK_VERSION
}

private def writeFields(
row: InternalRow, schema: StructType, fieldWriters: Array[ValueWriter]): Unit = {
var i = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.apache.spark.sql.execution.datasources.parquet

import org.apache.hadoop.fs.{FileSystem, Path}
import org.apache.parquet.format.converter.ParquetMetadataConverter
import org.apache.parquet.hadoop.ParquetFileReader

import org.apache.spark.SparkException
import org.apache.spark.sql.QueryTest
Expand Down Expand Up @@ -56,4 +58,25 @@ class ParquetFileFormatSuite extends QueryTest with ParquetTest with SharedSQLCo
}.getCause
assert(exception.getMessage().contains("Could not read footer for file"))
}

test("read version from parquet file footer metadata") {
withTempDir { dir =>
val config = spark.sessionState.newHadoopConf()
val fs = FileSystem.get(config)
val basePath = dir.getCanonicalPath

val pathToDirectory = new Path(basePath, "path")

spark.range(1).toDF("a").coalesce(1).write.save(pathToDirectory.toString)

val pathToFile = fs.globStatus(new Path(basePath, "path/part*"))(0).getPath

val fileFooter = ParquetFileReader
.readFooter(config, pathToFile, ParquetMetadataConverter.SKIP_ROW_GROUPS)
val fileWriterModelName = fileFooter.getFileMetaData
.getKeyValueMetaData.get("writer.model.name")

assert(fileWriterModelName == spark.version)
}
}
}