-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
170 additions
and
176 deletions.
There are no files selected for viewing
176 changes: 0 additions & 176 deletions
176
sql/hive/src/test/scala/org/apache/spark/sql/hive/orc/NewOrcQuerySuite.scala
This file was deleted.
Oops, something went wrong.
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
82 changes: 82 additions & 0 deletions
82
sql/hive/src/test/scala/org/apache/spark/sql/hive/orc/OrcTest.scala
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.hive.orc | ||
|
||
import java.io.File | ||
|
||
import scala.reflect.ClassTag | ||
import scala.reflect.runtime.universe.TypeTag | ||
|
||
import org.apache.spark.sql.hive.HiveContext | ||
import org.apache.spark.sql.hive.test.TestHive | ||
import org.apache.spark.sql.test.SQLTestUtils | ||
import org.apache.spark.sql._ | ||
|
||
private[sql] trait OrcTest extends SQLTestUtils { | ||
protected def hiveContext = sqlContext.asInstanceOf[HiveContext] | ||
|
||
import sqlContext.sparkContext | ||
import sqlContext.implicits._ | ||
|
||
/** | ||
* Writes `data` to a Orc file, which is then passed to `f` and will be deleted after `f` | ||
* returns. | ||
*/ | ||
protected def withOrcFile[T <: Product: ClassTag: TypeTag] | ||
(data: Seq[T]) | ||
(f: String => Unit): Unit = { | ||
withTempPath { file => | ||
sparkContext.parallelize(data).toDF().write.format("orc").save(file.getCanonicalPath) | ||
f(file.getCanonicalPath) | ||
} | ||
} | ||
|
||
/** | ||
* Writes `data` to a Orc file and reads it back as a [[DataFrame]], | ||
* which is then passed to `f`. The Orc file will be deleted after `f` returns. | ||
*/ | ||
protected def withOrcDataFrame[T <: Product: ClassTag: TypeTag] | ||
(data: Seq[T]) | ||
(f: DataFrame => Unit): Unit = { | ||
withOrcFile(data)(path => f(hiveContext.read.format("orc").load(path))) | ||
} | ||
|
||
/** | ||
* Writes `data` to a Orc file, reads it back as a [[DataFrame]] and registers it as a | ||
* temporary table named `tableName`, then call `f`. The temporary table together with the | ||
* Orc file will be dropped/deleted after `f` returns. | ||
*/ | ||
protected def withOrcTable[T <: Product: ClassTag: TypeTag] | ||
(data: Seq[T], tableName: String) | ||
(f: => Unit): Unit = { | ||
withOrcDataFrame(data) { df => | ||
hiveContext.registerDataFrameAsTable(df, tableName) | ||
withTempTable(tableName)(f) | ||
} | ||
} | ||
|
||
protected def makeOrcFile[T <: Product: ClassTag: TypeTag]( | ||
data: Seq[T], path: File): Unit = { | ||
data.toDF().write.format("orc").mode(SaveMode.Overwrite).save(path.getCanonicalPath) | ||
} | ||
|
||
protected def makeOrcFile[T <: Product: ClassTag: TypeTag]( | ||
df: DataFrame, path: File): Unit = { | ||
df.write.format("orc").mode(SaveMode.Overwrite).save(path.getCanonicalPath) | ||
} | ||
} |