Skip to content

Commit

Permalink
fixes for SNAP-2307 (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanthmeka committed Aug 3, 2018
1 parent 77cd2f5 commit 8d7e7f0
Showing 1 changed file with 84 additions and 5 deletions.
Expand Up @@ -17,10 +17,89 @@
package org.apache.spark.sql

import org.apache.spark.sql.sources.TableScanSuite
import org.apache.spark.sql.test.SharedSnappySessionContext
import org.apache.spark.sql.test.{SharedSnappySessionContext, SnappySparkTestUtil}

class SnappyTableScanSuite extends TableScanSuite with SharedSnappySessionContext{
// SimpleScanSource, an external source is not found while
// creating internal table. changing it to external
override val tableTypes = Seq("TEMPORARY VIEW", "EXTERNAL TABLE")
class SnappyTableScanSuite
extends TableScanSuite
with SharedSnappySessionContext
with SnappySparkTestUtil {

// all tests in TableScanSuite will run except for below tests
// read comments above each test for desc on fixes
override def excluded: Seq[String] = Seq(
"exceptions",
"read the data source tables that do not extend SchemaRelationProvider",
"SPARK-5196 schema field with comment"
)

// SimpleScanSource is external to snappy. changed 'TABLE' to 'EXTERNAL TABLE'
test("SD:exceptions") {
// Make sure we do throw correct exception when users use a relation provider that
// only implements the RelationProvider or the SchemaRelationProvider.
Seq("TEMPORARY VIEW", "EXTERNAL TABLE").foreach { tableType =>
val schemaNotAllowed = intercept[Exception] {
sql(
s"""
|CREATE $tableType relationProvierWithSchema (i int)
|USING org.apache.spark.sql.sources.SimpleScanSource
|OPTIONS (
| From '1',
| To '10'
|)
""".stripMargin)
}
assert(schemaNotAllowed.getMessage.contains("does not allow user-specified schemas"))

val schemaNeeded = intercept[Exception] {
sql(
s"""
|CREATE $tableType schemaRelationProvierWithoutSchema
|USING org.apache.spark.sql.sources.AllDataTypesScanSource
|OPTIONS (
| From '1',
| To '10'
|)
""".stripMargin)
}
assert(schemaNeeded.getMessage.contains("A schema needs to be specified when using"))
}
}

// SimpleScanSource is external to snappy. changed 'TABLE' to 'EXTERNAL TABLE'
test("SD:read the data source tables that do not extend SchemaRelationProvider") {
Seq("TEMPORARY VIEW", "EXTERNAL TABLE").foreach { tableType =>
val tableName = "relationProvierWithSchema"
withTable(tableName) {
sql(
s"""
|CREATE $tableType $tableName
|USING org.apache.spark.sql.sources.SimpleScanSource
|OPTIONS (
| From '1',
| To '10'
|)
""".stripMargin)
checkAnswer(spark.table(tableName), spark.range(1, 11).toDF())
}
}
}

// according to snappy implementation comment desc needs ' not "
test("SD:SPARK-5196 schema field with comment") {
sql(
"""
|CREATE TEMPORARY VIEW student(name string comment 'SN', age int comment 'SA', grade int)
|USING org.apache.spark.sql.sources.AllDataTypesScanSource
|OPTIONS (
| from '1',
| to '10',
| option_with_underscores 'someval',
| option.with.dots 'someval'
|)
""".stripMargin)

val planned = sql("SELECT * FROM student").queryExecution.executedPlan
val comments = planned.schema.fields.map(_.getComment().getOrElse("NO_COMMENT")).mkString(",")
assert(comments === "SN,SA,NO_COMMENT")
}
}

0 comments on commit 8d7e7f0

Please sign in to comment.