|
| 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.hive.orc |
| 19 | + |
| 20 | +import java.io.File |
| 21 | + |
| 22 | +import org.apache.spark.sql.execution.datasources.orc.OrcHadoopFsRelationSuite |
| 23 | + |
| 24 | +class HiveOrcHadoopFsRelationSuite extends OrcHadoopFsRelationSuite { |
| 25 | + import testImplicits._ |
| 26 | + |
| 27 | + override val dataSourceName: String = |
| 28 | + classOf[org.apache.spark.sql.hive.orc.OrcFileFormat].getCanonicalName |
| 29 | + |
| 30 | + test("SPARK-13543: Support for specifying compression codec for ORC via option()") { |
| 31 | + withTempPath { dir => |
| 32 | + val path = s"${dir.getCanonicalPath}/table1" |
| 33 | + val df = (1 to 5).map(i => (i, (i % 2).toString)).toDF("a", "b") |
| 34 | + df.write |
| 35 | + .option("compression", "ZlIb") |
| 36 | + .orc(path) |
| 37 | + |
| 38 | + // Check if this is compressed as ZLIB. |
| 39 | + val maybeOrcFile = new File(path).listFiles().find { f => |
| 40 | + !f.getName.startsWith("_") && f.getName.endsWith(".zlib.orc") |
| 41 | + } |
| 42 | + assert(maybeOrcFile.isDefined) |
| 43 | + val orcFilePath = maybeOrcFile.get.toPath.toString |
| 44 | + val expectedCompressionKind = |
| 45 | + OrcFileOperator.getFileReader(orcFilePath).get.getCompression |
| 46 | + assert("ZLIB" === expectedCompressionKind.name()) |
| 47 | + |
| 48 | + val copyDf = spark |
| 49 | + .read |
| 50 | + .orc(path) |
| 51 | + checkAnswer(df, copyDf) |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + test("Default compression codec is snappy for ORC compression") { |
| 56 | + withTempPath { file => |
| 57 | + spark.range(0, 10).write |
| 58 | + .orc(file.getCanonicalPath) |
| 59 | + val expectedCompressionKind = |
| 60 | + OrcFileOperator.getFileReader(file.getCanonicalPath).get.getCompression |
| 61 | + assert("SNAPPY" === expectedCompressionKind.name()) |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments