-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-21786][SQL] When acquiring 'compressionCodecClassName' in 'ParquetOptions', parquet.compression needs to be considered.
#20076
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
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9bbfe6e
[SPARK-21786][SQL] When acquiring 'compressionCodecClassName' in 'Par…
fjh100456 48cf108
[SPARK-21786][SQL] When acquiring 'compressionCodecClassName' in 'Par…
fjh100456 5dbd3ed
spark.sql.parquet.compression.codec[SPARK-21786][SQL] When acquiring …
fjh100456 5124f1b
spark.sql.parquet.compression.codec[SPARK-21786][SQL] When acquiring …
fjh100456 1b087df
Fix scala style
fjh100456 05e52b6
Change compressionCodecClassName to compressionCodecName
fjh100456 0c0f55d
Resume a mistaken.
fjh100456 4ab7ecb
Change the compression description
fjh100456 3cf0c04
update compressionCodecClassName to compressionCodecName
fjh100456 10e5462
Use ParquetOptions in test, so change to pulbic
fjh100456 2ab2d29
Update test
fjh100456 845dda7
1 Resume the renaming
fjh100456 e510b48
Rename the test file name and class name
fjh100456 9229e6f
Fix scala style
fjh100456 37fe65e
Mode doc describtion
fjh100456 253b2a2
Add test case and change the package level
fjh100456 d60dcd1
Add test case and change the package level
fjh100456 b5cd809
Revive `private[parquet]`
fjh100456 26c1c61
Fix scala style
fjh100456 9466797
Change the describtion of spark.sql.parquet.compression
fjh100456 1a8c654
Change describtion
fjh100456 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...ache/spark/sql/execution/datasources/parquet/ParquetCompressionCodecPrecedenceSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * 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.execution.datasources.parquet | ||
|
|
||
| import java.io.File | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
|
|
||
| import org.apache.hadoop.fs.Path | ||
| import org.apache.parquet.hadoop.ParquetOutputFormat | ||
|
|
||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.test.SharedSQLContext | ||
|
|
||
| class ParquetCompressionCodecPrecedenceSuite extends ParquetTest with SharedSQLContext { | ||
| test("Test `spark.sql.parquet.compression.codec` config") { | ||
| Seq("NONE", "UNCOMPRESSED", "SNAPPY", "GZIP", "LZO").foreach { c => | ||
| withSQLConf(SQLConf.PARQUET_COMPRESSION.key -> c) { | ||
| val expected = if (c == "NONE") "UNCOMPRESSED" else c | ||
| val option = new ParquetOptions(Map.empty[String, String], spark.sessionState.conf) | ||
| assert(option.compressionCodecClassName == expected) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("[SPARK-21786] Test Acquiring 'compressionCodecClassName' for parquet in right order.") { | ||
| // When "compression" is configured, it should be the first choice. | ||
| withSQLConf(SQLConf.PARQUET_COMPRESSION.key -> "snappy") { | ||
| val props = Map("compression" -> "uncompressed", ParquetOutputFormat.COMPRESSION -> "gzip") | ||
| val option = new ParquetOptions(props, spark.sessionState.conf) | ||
| assert(option.compressionCodecClassName == "UNCOMPRESSED") | ||
| } | ||
|
|
||
| // When "compression" is not configured, "parquet.compression" should be the preferred choice. | ||
| withSQLConf(SQLConf.PARQUET_COMPRESSION.key -> "snappy") { | ||
| val props = Map(ParquetOutputFormat.COMPRESSION -> "gzip") | ||
| val option = new ParquetOptions(props, spark.sessionState.conf) | ||
| assert(option.compressionCodecClassName == "GZIP") | ||
| } | ||
|
|
||
| // When both "compression" and "parquet.compression" are not configured, | ||
| // spark.sql.parquet.compression.codec should be the right choice. | ||
| withSQLConf(SQLConf.PARQUET_COMPRESSION.key -> "snappy") { | ||
| val props = Map.empty[String, String] | ||
| val option = new ParquetOptions(props, spark.sessionState.conf) | ||
| assert(option.compressionCodecClassName == "SNAPPY") | ||
| } | ||
| } | ||
|
|
||
| private def getTableCompressionCodec(path: String): Seq[String] = { | ||
| val hadoopConf = spark.sessionState.newHadoopConf() | ||
| val codecs = for { | ||
| footer <- readAllFootersWithoutSummaryFiles(new Path(path), hadoopConf) | ||
| block <- footer.getParquetMetadata.getBlocks.asScala | ||
| column <- block.getColumns.asScala | ||
| } yield column.getCodec.name() | ||
| codecs.distinct | ||
| } | ||
|
|
||
| private def createTableWithCompression( | ||
| tableName: String, | ||
| isPartitioned: Boolean, | ||
| compressionCodec: String, | ||
| rootDir: File): Unit = { | ||
| val options = | ||
| s""" | ||
| |OPTIONS('path'='${rootDir.toURI.toString.stripSuffix("/")}/$tableName', | ||
| |'parquet.compression'='$compressionCodec') | ||
| """.stripMargin | ||
| val partitionCreate = if (isPartitioned) "PARTITIONED BY (p)" else "" | ||
| sql( | ||
| s""" | ||
| |CREATE TABLE $tableName USING Parquet $options $partitionCreate | ||
| |AS SELECT 1 AS col1, 2 AS p | ||
| """.stripMargin) | ||
| } | ||
|
|
||
| private def checkCompressionCodec(compressionCodec: String, isPartitioned: Boolean): Unit = { | ||
| withTempDir { tmpDir => | ||
| val tempTableName = "TempParquetTable" | ||
| withTable(tempTableName) { | ||
| createTableWithCompression(tempTableName, isPartitioned, compressionCodec, tmpDir) | ||
| val partitionPath = if (isPartitioned) "p=2" else "" | ||
| val path = s"${tmpDir.getPath.stripSuffix("/")}/$tempTableName/$partitionPath" | ||
| val realCompressionCodecs = getTableCompressionCodec(path) | ||
| assert(realCompressionCodecs.forall(_ == compressionCodec)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("Create parquet table with compression") { | ||
| Seq(true, false).foreach { isPartitioned => | ||
| Seq("UNCOMPRESSED", "SNAPPY", "GZIP").foreach { compressionCodec => | ||
| checkCompressionCodec(compressionCodec, isPartitioned) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("Create table with unknown compression") { | ||
| Seq(true, false).foreach { isPartitioned => | ||
| val exception = intercept[IllegalArgumentException] { | ||
| checkCompressionCodec("aa", isPartitioned) | ||
| } | ||
| assert(exception.getMessage.contains("Codec [aa] is not available")) | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change
compressionCodecClassNametocompressionCodecinstead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HyukjinKwon Seems you're right.
@gatorsmile Are we mistaken, shouldn't we change ParquetOptions's
compressionCodectocompressionCodecClassName? BecauseOrcOptionsandTextOptionsare all usingcompressionCodec.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compressionCodecClassNameis a better name. We should change all the others to this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could alternatively say
compressionCodecNamehere. It's rather names likeUNCOMPRESSED,LZO, etc in this case. For the text based sources, they are canonical class names so I am okay withcompressionCodecClassNamebut for ORC and Parquet these are not classes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compressionCodecNameis also fine to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, change all
compressionCodecClassNameandcompressionCodectocompressionCodecName? InTextOptions,JSONOptionsandCSVOptionstoo ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile @HyukjinKwon
In
TextOptions,JSONOptionsandCSVOptions, it's "Option[String]", but inOrcOptionsandParquetOptions, it's a "String".Just change
compressionCodecClassNameinOrcOptionsandParquetOptionstocompressionCodecNameis ok ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do Parquet and ORC ones here for now if that's also fine to @gatorsmile.