-
Notifications
You must be signed in to change notification settings - Fork 234
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
Add test cases for ORC writing according to options orc.compress and compression [databricks] #8785
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
20b10ff
Add test cases for ORC writing according to options orc.compress and …
7f0fee2
Fix 321cdh and 330cdh compile error; Refactor
fe408d6
Merge branch-23.08
cb42932
Fix compile error
0da9194
Fix Merge conflict
a38b750
Fix nits
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 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 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 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -18,13 +18,23 @@ package com.nvidia.spark.rapids | |||||
|
||||||
import java.io.File | ||||||
|
||||||
import scala.collection.mutable.ListBuffer | ||||||
|
||||||
import com.nvidia.spark.rapids.Arm.withResourceIfAllowed | ||||||
import org.apache.hadoop.conf.Configuration | ||||||
import org.apache.hadoop.fs.FileUtil.fullyDelete | ||||||
import org.apache.hadoop.fs.Path | ||||||
import org.apache.orc.OrcFile | ||||||
|
||||||
import org.apache.spark.{SparkConf, SparkContext} | ||||||
import org.apache.spark.sql.{DataFrame, Row, SparkSession} | ||||||
import org.apache.spark.sql.rapids.{MyDenseVector, MyDenseVectorUDT} | ||||||
import org.apache.spark.sql.types._ | ||||||
|
||||||
/** | ||||||
* This corresponds to the Spark class: | ||||||
* org.apache.spark.sql.execution.datasources.orc.OrcQueryTest | ||||||
*/ | ||||||
class OrcQuerySuite extends SparkQueryCompareTestSuite { | ||||||
|
||||||
private def getSchema: StructType = new StructType(Array( | ||||||
|
@@ -92,4 +102,76 @@ class OrcQuerySuite extends SparkQueryCompareTestSuite { | |||||
) { | ||||||
frame => frame | ||||||
} | ||||||
|
||||||
private def getOrcFilePostfix(compression: String): String = | ||||||
if (Seq("NONE", "UNCOMPRESSED").contains(compression)) { | ||||||
".orc" | ||||||
} else { | ||||||
s".${compression.toLowerCase()}.orc" | ||||||
} | ||||||
|
||||||
def checkCompressType(compression: Option[String], orcCompress: Option[String]): Unit = { | ||||||
withGpuSparkSession { spark => | ||||||
withTempPath { file => | ||||||
var writer = spark.range(0, 10).write | ||||||
writer = compression.map(t => writer.option("compression", t)).getOrElse(writer) | ||||||
writer = orcCompress.map(t => writer.option("orc.compress", t)).getOrElse(writer) | ||||||
// write ORC file on GPU | ||||||
writer.orc(file.getCanonicalPath) | ||||||
|
||||||
// expectedType: first use compression, then orc.compress | ||||||
var expectedType = compression.getOrElse(orcCompress.get) | ||||||
// ORC use NONE for UNCOMPRESSED | ||||||
if (expectedType == "UNCOMPRESSED") expectedType = "NONE" | ||||||
val maybeOrcFile = file.listFiles() | ||||||
.find(_.getName.endsWith(getOrcFilePostfix(expectedType))) | ||||||
assert(maybeOrcFile.isDefined) | ||||||
|
||||||
// check the compress type using ORC jar | ||||||
val orcFilePath = new Path(maybeOrcFile.get.getAbsolutePath) | ||||||
val conf = OrcFile.readerOptions(new Configuration()) | ||||||
|
||||||
// the reader is not a AutoCloseable for Spark CDH, so use `withResourceIfAllowed` | ||||||
// 321cdh uses lower ORC: orc-core-1.5.1.7.1.7.1000-141.jar | ||||||
// 330cdh uses lower ORC: orc-core-1.5.1.7.1.8.0-801.jar | ||||||
withResourceIfAllowed(OrcFile.createReader(orcFilePath, conf)) { reader => | ||||||
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. This is a useful utility. It makes the code quite streamlined. |
||||||
// check | ||||||
assert(expectedType === reader.getCompressionKind.name) | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
private val supportedWriteCompressTypes = { | ||||||
// GPU ORC writing does not support ZLIB, LZ4, refer to GpuOrcFileFormat | ||||||
val supportedWriteCompressType = ListBuffer("UNCOMPRESSED", "NONE", "ZSTD", "SNAPPY") | ||||||
// Cdh321, Cdh330 does not support ZSTD, refer to the Cdh Class: | ||||||
// org.apache.spark.sql.execution.datasources.orc.OrcOptions | ||||||
// Spark 31x do not support lz4, zstd | ||||||
if (isCdh321 || isCdh330 || !VersionUtils.isSpark320OrLater) { | ||||||
supportedWriteCompressType -= "ZSTD" | ||||||
} | ||||||
supportedWriteCompressType | ||||||
} | ||||||
|
||||||
test("SPARK-16610: Respect orc.compress (i.e., OrcConf.COMPRESS) when compression is unset") { | ||||||
// Respect `orc.compress` (i.e., OrcConf.COMPRESS). | ||||||
supportedWriteCompressTypes.foreach { orcCompress => | ||||||
checkCompressType(None, Some(orcCompress)) | ||||||
} | ||||||
|
||||||
// make paris, e.g.: [("UNCOMPRESSED", "NONE"), ("NONE", "SNAPPY"), ("SNAPPY", "ZSTD") ... ] | ||||||
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.
Suggested change
|
||||||
val pairs = supportedWriteCompressTypes.sliding(2).toList.map(pair => (pair.head, pair.last)) | ||||||
|
||||||
// "compression" overwrite "orc.compress" | ||||||
pairs.foreach { case (compression, orcCompress) => | ||||||
checkCompressType(Some(compression), Some(orcCompress)) | ||||||
} | ||||||
} | ||||||
|
||||||
test("Compression options for writing to an ORC file (SNAPPY, ZLIB and NONE)") { | ||||||
supportedWriteCompressTypes.foreach { compression => | ||||||
checkCompressType(Some(compression), None) | ||||||
} | ||||||
} | ||||||
} |
This file contains 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.