-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21839][SQL] Support SQL config for ORC compression #19055
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
Changes from 5 commits
f3ccfec
5998c29
afbb6f2
437d181
aafbfbb
8aebcd3
94e624e
34e2845
4c0300c
9620e46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,30 +20,33 @@ package org.apache.spark.sql.hive.orc | |||||||||||
| import java.util.Locale | ||||||||||||
|
|
||||||||||||
| import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap | ||||||||||||
| import org.apache.spark.sql.internal.SQLConf | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Options for the ORC data source. | ||||||||||||
| */ | ||||||||||||
| private[orc] class OrcOptions(@transient private val parameters: CaseInsensitiveMap[String]) | ||||||||||||
| private[orc] class OrcOptions( | ||||||||||||
| @transient private val parameters: CaseInsensitiveMap[String], | ||||||||||||
| @transient private val sqlConf: SQLConf) | ||||||||||||
| extends Serializable { | ||||||||||||
|
|
||||||||||||
| import OrcOptions._ | ||||||||||||
|
|
||||||||||||
| def this(parameters: Map[String, String]) = this(CaseInsensitiveMap(parameters)) | ||||||||||||
| def this(parameters: Map[String, String], sqlConf: SQLConf) = | ||||||||||||
| this(CaseInsensitiveMap(parameters), sqlConf) | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Compression codec to use. By default snappy compression. | ||||||||||||
| * Compression codec to use. | ||||||||||||
| * Acceptable values are defined in [[shortOrcCompressionCodecNames]]. | ||||||||||||
| */ | ||||||||||||
| val compressionCodec: String = { | ||||||||||||
| // `orc.compress` is a ORC configuration. So, here we respect this as an option but | ||||||||||||
| // `compression` has higher precedence than `orc.compress`. It means if both are set, | ||||||||||||
| // we will use `compression`. | ||||||||||||
| // `compression`, `orc.compress`, and `spark.sql.orc.compression.codec` is used in order. | ||||||||||||
| val orcCompressionConf = parameters.get(OrcRelation.ORC_COMPRESSION) | ||||||||||||
| val codecName = parameters | ||||||||||||
| .get("compression") | ||||||||||||
| .orElse(orcCompressionConf) | ||||||||||||
| .getOrElse("snappy").toLowerCase(Locale.ROOT) | ||||||||||||
| .getOrElse(sqlConf.orcCompressionCodec) | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we update the default values for consistency with Parquet one? :
spark/python/pyspark/sql/readwriter.py Line 855 in 51620e2
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value is snappy, isn't it?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking like: spark/python/pyspark/sql/readwriter.py Lines 751 to 753 in 51620e2
Wouldn't we use the value set in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I thought the purpose of this configuration is rather for setting the default compression codec for ORC datasource ..
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. This is the priority. If
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main purpose of this PR is to support users to control ORC compression by using SQLConf, too.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default codec is unchanged and the priority is the same. Also, all previous user-given options are respected.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, it looks I had to be clear. I meant fixing the comment for default value from
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I'll fix that. |
||||||||||||
| .toLowerCase(Locale.ROOT) | ||||||||||||
| if (!shortOrcCompressionCodecNames.contains(codecName)) { | ||||||||||||
| val availableCodecs = shortOrcCompressionCodecNames.keys.map(_.toLowerCase(Locale.ROOT)) | ||||||||||||
| throw new IllegalArgumentException(s"Codec [$codecName] " + | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,13 @@ | |
| package org.apache.spark.sql.hive.orc | ||
|
|
||
| import java.io.File | ||
| import java.util.Locale | ||
|
||
|
|
||
| import org.scalatest.BeforeAndAfterAll | ||
|
|
||
| import org.apache.spark.sql.{QueryTest, Row} | ||
| import org.apache.spark.sql.hive.HiveExternalCatalog | ||
| import org.apache.spark.sql.hive.test.TestHiveSingleton | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.sources._ | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.util.Utils | ||
|
|
@@ -149,7 +150,8 @@ abstract class OrcSuite extends QueryTest with TestHiveSingleton with BeforeAndA | |
| } | ||
|
|
||
| test("SPARK-18433: Improve DataSource option keys to be more case-insensitive") { | ||
| assert(new OrcOptions(Map("Orc.Compress" -> "NONE")).compressionCodec == "NONE") | ||
| val conf = sqlContext.sessionState.conf | ||
| assert(new OrcOptions(Map("Orc.Compress" -> "NONE"), conf).compressionCodec == "NONE") | ||
| } | ||
|
|
||
| test("SPARK-19459/SPARK-18220: read char/varchar column written by Hive") { | ||
|
|
@@ -194,6 +196,33 @@ abstract class OrcSuite extends QueryTest with TestHiveSingleton with BeforeAndA | |
| Utils.deleteRecursively(location) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-21839: Add SQL config for ORC compression") { | ||
| val conf = sqlContext.sessionState.conf | ||
| // Test if the default of spark.sql.orc.compression.codec is snappy | ||
| assert(new OrcOptions(Map.empty[String, String], conf).compressionCodec == "SNAPPY") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment here to explain the test scenario.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
|
|
||
| // OrcOptions's parameters have a higher priority than SQL configuration. | ||
| // `compression` -> `orc.compression` -> `spark.sql.orc.compression.codec` | ||
| withSQLConf(SQLConf.ORC_COMPRESSION.key -> "uncompressed") { | ||
| assert(new OrcOptions(Map.empty[String, String], conf).compressionCodec == "NONE") | ||
| val map1 = Map("orc.compress" -> "zlib") | ||
| val map2 = Map("orc.compress" -> "zlib", "compression" -> "lzo") | ||
| assert(new OrcOptions(map1, conf).compressionCodec == "ZLIB") | ||
| assert(new OrcOptions(map2, conf).compressionCodec == "LZO") | ||
| } | ||
|
|
||
| // Test all the valid options of spark.sql.orc.compression.codec | ||
| Seq("NONE", "UNCOMPRESSED", "SNAPPY", "ZLIB", "LZO").foreach { c => | ||
| withSQLConf(SQLConf.ORC_COMPRESSION.key -> c) { | ||
| if (c == "UNCOMPRESSED") { | ||
|
||
| assert(new OrcOptions(Map.empty[String, String], conf).compressionCodec == "NONE") | ||
| } else { | ||
| assert(new OrcOptions(Map.empty[String, String], conf).compressionCodec == c) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class OrcSourceSuite extends OrcSuite { | ||
|
|
||
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.
is used in order->are in order of precedence from highest to lowest