Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more test case
  • Loading branch information
gatorsmile committed Jun 21, 2016
commit 3007fe66d03a6a40dc530c13d44c27030118a8a4
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSQLContext with Be
}

test("illegal format name") {
val e = intercept[AnalysisException] {
val e = intercept[ClassNotFoundException] {
spark.read.format("illegal").load("/test")
}
assert(e.getMessage.contains("Failed to find data source: illegal"))
Expand All @@ -231,12 +231,10 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSQLContext with Be
test("prevent all column partitioning") {
withTempDir { dir =>
val path = dir.getCanonicalPath
intercept[AnalysisException] {
val e = intercept[AnalysisException] {
spark.range(10).write.format("parquet").mode("overwrite").partitionBy("id").save(path)
}
intercept[AnalysisException] {
spark.range(10).write.format("orc").mode("overwrite").partitionBy("id").save(path)
}
}.getMessage
assert(e.contains("Cannot use all columns for partition columns"))
}
}

Expand Down Expand Up @@ -318,9 +316,10 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSQLContext with Be
val schema = df.schema

// Reader, without user specified schema
intercept[AnalysisException] {
val e = intercept[IllegalArgumentException] {
testRead(spark.read.json(), Seq.empty, schema)
}
}.getMessage
assert(e.contains("'path' is not specified"))
testRead(spark.read.json(dir), data, schema)
testRead(spark.read.json(dir, dir), data ++ data, schema)
testRead(spark.read.json(Seq(dir, dir): _*), data ++ data, schema)
Expand All @@ -344,9 +343,10 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSQLContext with Be
val schema = df.schema

// Reader, without user specified schema
intercept[AnalysisException] {
val e = intercept[IllegalArgumentException] {
testRead(spark.read.parquet(), Seq.empty, schema)
}
}.getMessage
assert(e.contains("'path' is not specified"))
testRead(spark.read.parquet(dir), data, schema)
testRead(spark.read.parquet(dir, dir), data ++ data, schema)
testRead(spark.read.parquet(Seq(dir, dir): _*), data ++ data, schema)
Expand All @@ -363,23 +363,6 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSQLContext with Be
spark.read.schema(userSchema).parquet(Seq(dir, dir): _*), expData ++ expData, userSchema)
}

/**
* This only tests whether API compiles, but does not run it as orc()
* cannot be run without Hive classes.
*/
ignore("orc - API") {
// Reader, with user specified schema
// Refer to csv-specific test suites for behavior without user specified schema
spark.read.schema(userSchema).orc()
spark.read.schema(userSchema).orc(dir)
spark.read.schema(userSchema).orc(dir, dir, dir)
spark.read.schema(userSchema).orc(Seq(dir, dir): _*)
Option(dir).map(spark.read.schema(userSchema).orc)

// Writer
spark.range(10).write.orc(dir)
}

private def testRead(
df: => DataFrame,
expectedResult: Seq[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.io.File

import org.scalatest.BeforeAndAfterAll

import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
import org.apache.spark.sql._
import org.apache.spark.sql.hive.test.TestHiveSingleton
import org.apache.spark.sql.sources._
import org.apache.spark.sql.test.SQLTestUtils
Expand Down Expand Up @@ -197,6 +197,8 @@ abstract class OrcSuite extends QueryTest
}

class OrcSourceSuite extends OrcSuite {
import spark.implicits._

override def beforeAll(): Unit = {
super.beforeAll()

Expand All @@ -217,6 +219,49 @@ class OrcSourceSuite extends OrcSuite {
""".stripMargin)
}

test("orc - API") {
val userSchema = new StructType().add("s", StringType)
val data = Seq("1", "2", "3")
val dir = Utils.createTempDir(namePrefix = "input").getCanonicalPath

// Writer
spark.createDataset(data).toDF("str").write.mode(SaveMode.Overwrite).orc(dir)
val df = spark.read.orc(dir)
checkAnswer(df, spark.createDataset(data).toDF())
val schema = df.schema

// Reader, without user specified schema
intercept[IllegalArgumentException] {
testRead(spark.read.orc(), Seq.empty, schema)
}
testRead(spark.read.orc(dir), data, schema)
testRead(spark.read.orc(dir, dir), data ++ data, schema)
testRead(spark.read.orc(Seq(dir, dir): _*), data ++ data, schema)
// Test explicit calls to single arg method - SPARK-16009
testRead(Option(dir).map(spark.read.orc).get, data, schema)

// Reader, with user specified schema, should just apply user schema on the file data
testRead(spark.read.schema(userSchema).orc(), Seq.empty, userSchema)
spark.read.schema(userSchema).orc(dir).printSchema()

spark.read.schema(userSchema).orc(dir).explain(true)

spark.read.schema(userSchema).orc().show()
spark.read.schema(userSchema).orc(dir).show()
val expData = Seq[String](null, null, null)
testRead(spark.read.schema(userSchema).orc(dir), expData, userSchema)
testRead(spark.read.schema(userSchema).orc(dir, dir), expData ++ expData, userSchema)
testRead(spark.read.schema(userSchema).orc(Seq(dir, dir): _*), expData ++ expData, userSchema)

}
private def testRead(
df: => DataFrame,
expectedResult: Seq[String],
expectedSchema: StructType): Unit = {
checkAnswer(df, spark.createDataset(expectedResult).toDF())
assert(df.schema === expectedSchema)
}

test("SPARK-12218 Converting conjunctions into ORC SearchArguments") {
// The `LessThan` should be converted while the `StringContains` shouldn't
val schema = new StructType(
Expand Down