-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12871][SQL] Support to specify the option for compression codec. #10805
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 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
06774ad
Support for compress option
HyukjinKwon 5e1611d
Correct Scala style and add an alias for codec as compression.
HyukjinKwon d154f02
Move back some codes changed unintentionally.
HyukjinKwon 5b57fc2
Remove Hadoop 1.x configurations
HyukjinKwon e7ebddd
Look up compression first.
HyukjinKwon f4ffbf6
Resolve conflicts
HyukjinKwon adb9eb2
Support for shorten names and change the variable from codec to compr…
HyukjinKwon 432da5d
Correct several nits and validate class names.
HyukjinKwon 4388fe5
Add a newline between function and variables
HyukjinKwon 6400b76
Remove whitespace
HyukjinKwon 56316a8
Several nits and reduce complexity
HyukjinKwon c9217be
Update exception message
HyukjinKwon 0245eea
Simply add a space after comma.
HyukjinKwon cd9f742
Update exception message and get rid of Option.
HyukjinKwon 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,10 @@ package org.apache.spark.sql.execution.datasources.csv | |
|
|
||
| import java.nio.charset.Charset | ||
|
|
||
| import org.apache.hadoop.io.compress._ | ||
|
|
||
| import org.apache.spark.Logging | ||
| import org.apache.spark.util.Utils | ||
|
|
||
| private[sql] case class CSVParameters(@transient parameters: Map[String, String]) extends Logging { | ||
|
|
||
|
|
@@ -35,7 +38,7 @@ private[sql] case class CSVParameters(@transient parameters: Map[String, String] | |
|
|
||
| private def getBool(paramName: String, default: Boolean = false): Boolean = { | ||
| val param = parameters.getOrElse(paramName, default.toString) | ||
| if (param.toLowerCase() == "true") { | ||
| if (param.toLowerCase == "true") { | ||
| true | ||
| } else if (param.toLowerCase == "false") { | ||
| false | ||
|
|
@@ -73,6 +76,11 @@ private[sql] case class CSVParameters(@transient parameters: Map[String, String] | |
|
|
||
| val nullValue = parameters.getOrElse("nullValue", "") | ||
|
|
||
| val compressionCodec: Option[String] = { | ||
| val name = parameters.get("compression").orElse(parameters.get("codec")) | ||
| name.map(CSVCompressionCodecs.getCodecClassName) | ||
| } | ||
|
|
||
| val maxColumns = 20480 | ||
|
|
||
| val maxCharsPerColumn = 100000 | ||
|
|
@@ -85,7 +93,6 @@ private[sql] case class CSVParameters(@transient parameters: Map[String, String] | |
| } | ||
|
|
||
| private[csv] object ParseModes { | ||
|
|
||
| val PERMISSIVE_MODE = "PERMISSIVE" | ||
| val DROP_MALFORMED_MODE = "DROPMALFORMED" | ||
| val FAIL_FAST_MODE = "FAILFAST" | ||
|
|
@@ -107,3 +114,28 @@ private[csv] object ParseModes { | |
| true // We default to permissive is the mode string is not valid | ||
| } | ||
| } | ||
|
|
||
| private[csv] object CSVCompressionCodecs { | ||
| private val shortCompressionCodecNames = Map( | ||
| "bzip2" -> classOf[BZip2Codec].getName, | ||
| "gzip" -> classOf[GzipCodec].getName, | ||
| "lz4" -> classOf[Lz4Codec].getName, | ||
| "snappy" -> classOf[SnappyCodec].getName) | ||
|
|
||
| /** | ||
| * Return the full version of the given codec class. | ||
| * If it is already a class name, just return it. | ||
| */ | ||
| def getCodecClassName(name: String): String = { | ||
| val codecName = shortCompressionCodecNames.getOrElse(name.toLowerCase, name) | ||
| val codecClassName = try { | ||
| // Validate the codec name | ||
| Utils.classForName(codecName) | ||
| Some(codecName) | ||
| } catch { | ||
| case e: ClassNotFoundException => None | ||
| } | ||
| codecClassName.getOrElse(throw new IllegalArgumentException(s"Codec [$codecName] " + | ||
| s"is not available. Available codecs are ${shortCompressionCodecNames.keys.mkString(", ")}.")) | ||
|
Contributor
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. Probably change Available -> Known (since there may be more available) |
||
| } | ||
| } | ||
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
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.
should just put this throw inside the catch block and not bother with the Option stuff