-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[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 3 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. | ||||||||||||
|
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.
|
||||||||||||
| 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 | ||
|
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. Looks unused in this test.
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. Oops. Thanks! |
||
|
|
||
| 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,24 @@ 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 | ||
| 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. | ||
| withSQLConf(SQLConf.ORC_COMPRESSION.key -> "uncompressed") { | ||
| assert(new OrcOptions(Map.empty[String, String], conf).compressionCodec == "NONE") | ||
| assert( | ||
| new OrcOptions(Map("orc.compress" -> "zlib"), conf).compressionCodec == "ZLIB") | ||
|
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. Also please add another scenario when users specify |
||
| } | ||
|
|
||
| Seq("NONE", "SNAPPY", "ZLIB").foreach { c => | ||
| withSQLConf(SQLConf.ORC_COMPRESSION.key -> c) { | ||
| assert(new OrcOptions(Map.empty[String, String], conf).compressionCodec == c) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class OrcSourceSuite extends OrcSuite { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
@dongjoon-hyun, I think my only main concern is inconsistency between
compressionoption and this config. Iflzois an unknown key and it directly throws an exception (or even this was not there in the first place), I would have been okay but it looks attempting to findorg.apache.hadoop.hive.ql.io.orc.LzoCodec:... case LZO: try { Class<? extends CompressionCodec> lzo = (Class<? extends CompressionCodec>) JavaUtils.loadClass("org.apache.hadoop.hive.ql.io.orc.LzoCodec"); return lzo.newInstance(); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("LZO is not available.", e); } catch (InstantiationException e) { throw new IllegalArgumentException("Problem initializing LZO", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Insufficient access to LZO", e); } ...This appears that if we provide
org.apache.hadoop.hive.ql.io.orc.LzoCodecanyhow in the classpath (as an extream case, the one implemented by an user), it should work, if I read this correctly. This should be almost seldom though.Does your set of ORC related PRs eventually support
lzocorrectly?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.
I see. You mean user-provided hive or libraries. It makes sense. I will add lzo too here. Thank you for pointing out that.