Skip to content

Commit 5a0ae69

Browse files
committed
[SPARK-36670][SQL][TEST] Add FileSourceCodecSuite
### What changes were proposed in this pull request? This patch mainly proposes to add some e2e test cases in Spark for codec used by main datasources. ### Why are the changes needed? We found there is no e2e test cases available for main datasources like Parquet, Orc. It makes developers harder to identify possible bugs early. We should add such tests in Spark. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Added tests. Closes #33912 from viirya/SPARK-36670. Authored-by: Liang-Chi Hsieh <viirya@gmail.com> Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
1 parent f78d839 commit 5a0ae69

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@
300300
<enabled>false</enabled>
301301
</snapshots>
302302
</repository>
303+
<repository>
304+
<id>jitpack.io</id>
305+
<url>https://jitpack.io</url>
306+
<name>Jitpack.io repository</name>
307+
<!-- needed for brotli-codec -->
308+
</repository>
303309
</repositories>
304310
<pluginRepositories>
305311
<pluginRepository>

project/SparkBuild.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ object SparkBuild extends PomBuild {
274274
"gcs-maven-central-mirror" at "https://maven-central.storage-download.googleapis.com/maven2/",
275275
DefaultMavenRepository,
276276
Resolver.mavenLocal,
277-
Resolver.file("ivyLocal", file(Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns)
277+
Resolver.file("ivyLocal", file(Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns),
278+
// needed for brotli-codec
279+
"jitpack.io" at "https://jitpack.io"
278280
),
279281
externalResolvers := resolvers.value,
280282
otherResolvers := SbtPomKeys.mvnLocalRepository(dotM2 => Seq(Resolver.file("dotM2", dotM2))).value,

sql/core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@
178178
<artifactId>htmlunit-driver</artifactId>
179179
<scope>test</scope>
180180
</dependency>
181+
<dependency>
182+
<groupId>com.github.rdblue</groupId>
183+
<artifactId>brotli-codec</artifactId>
184+
<version>0.1.1</version>
185+
<scope>test</scope>
186+
</dependency>
181187
</dependencies>
182188
<build>
183189
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql.execution.datasources
19+
20+
import org.apache.spark.sql.QueryTest
21+
import org.apache.spark.sql.internal.SQLConf
22+
import org.apache.spark.sql.test.{SharedSparkSession, SQLTestUtils}
23+
24+
trait FileSourceCodecSuite extends QueryTest with SQLTestUtils with SharedSparkSession {
25+
26+
protected def format: String
27+
protected val codecConfigName: String
28+
protected def availableCodecs: Seq[String]
29+
30+
def testWithAllCodecs(name: String)(f: => Unit): Unit = {
31+
for (codec <- availableCodecs) {
32+
test(s"$name - file source $format - codec: $codec") {
33+
withSQLConf(codecConfigName -> codec) {
34+
f
35+
}
36+
}
37+
}
38+
}
39+
40+
testWithAllCodecs("write and read") {
41+
withTempPath { dir =>
42+
testData
43+
.repartition(5)
44+
.write
45+
.format(format)
46+
.save(dir.getCanonicalPath)
47+
48+
val df = spark.read.format(format).load(dir.getCanonicalPath)
49+
checkAnswer(df, testData)
50+
}
51+
}
52+
}
53+
54+
class ParquetCodecSuite extends FileSourceCodecSuite {
55+
56+
override def format: String = "parquet"
57+
override val codecConfigName: String = SQLConf.PARQUET_COMPRESSION.key
58+
// Exclude "lzo" because it is GPL-licenced so not included in Hadoop.
59+
// TODO(SPARK-36669): "lz4" codec fails due to HADOOP-17891.
60+
override protected def availableCodecs: Seq[String] =
61+
if (System.getProperty("os.arch") == "aarch64") {
62+
// Exclude "brotli" due to PARQUET-1975.
63+
Seq("none", "uncompressed", "snappy", "gzip", "zstd")
64+
} else {
65+
Seq("none", "uncompressed", "snappy", "gzip", "brotli", "zstd")
66+
}
67+
}
68+
69+
class OrcCodecSuite extends FileSourceCodecSuite {
70+
71+
override def format: String = "orc"
72+
override val codecConfigName: String = SQLConf.ORC_COMPRESSION.key
73+
override protected def availableCodecs = Seq("none", "uncompressed", "snappy",
74+
"zlib", "zstd", "lz4", "lzo")
75+
}

0 commit comments

Comments
 (0)