Skip to content

Commit e22b014

Browse files
viiryadongjoon-hyun
authored andcommitted
[SPARK-36670][SQL][TEST] Add FileSourceCodecSuite
This patch mainly proposes to add some e2e test cases in Spark for codec used by main datasources. 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. No Added tests. Closes apache#33912 from viirya/SPARK-36670. Authored-by: Liang-Chi Hsieh <viirya@gmail.com> Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com> (cherry picked from commit 5a0ae69) Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
1 parent 5cf7fd6 commit e22b014

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
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", "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", "lzo")
75+
}

0 commit comments

Comments
 (0)