Skip to content

Commit

Permalink
Split out CommonFileDataSourceSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
bozhang2820 committed Feb 11, 2022
1 parent a743482 commit 67c2318
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ import org.apache.spark.sql.types._
import org.apache.spark.sql.v2.avro.AvroScan
import org.apache.spark.util.Utils

abstract class AvroSuite
abstract class AvroSuiteBase
extends QueryTest
with SharedSparkSession
with CommonFileDataSourceSuite
with NestedDataSourceSuiteBase {

import testImplicits._

override protected def dataSourceFormat = "avro"
override val nestedDataSources = Seq("avro")
val episodesAvro = testFile("episodes.avro")
val testAvro = testFile("test.avro")
Expand Down Expand Up @@ -95,6 +91,11 @@ abstract class AvroSuite
}
}, new GenericDatumReader[Any]()).getSchema.toString(false)
}
}

abstract class AvroSuite extends AvroSuiteBase {

import testImplicits._

private def getResourceAvroFilePath(name: String): String = {
Thread.currentThread().getContextClassLoader.getResource(name).toString
Expand Down Expand Up @@ -2434,3 +2435,21 @@ class AvroV2Suite extends AvroSuite with ExplainSuiteHelper {
}
}
}

class AvroV1SuiteWithCommonFileSourceCheck extends AvroSuiteBase with CommonFileDataSourceSuite {
override protected def sparkConf: SparkConf =
super
.sparkConf
.set(SQLConf.USE_V1_SOURCE_LIST, "avro")

override protected def dataSourceFormat = "avro"
}

class AvroV2SuiteWithCommonFileSourceCheck extends AvroSuiteBase with CommonFileDataSourceSuite {
override protected def sparkConf: SparkConf =
super
.sparkConf
.set(SQLConf.USE_V1_SOURCE_LIST, "")

override protected def dataSourceFormat = "avro"
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,9 @@ import org.apache.spark.sql.execution.datasources.CommonFileDataSourceSuite
import org.apache.spark.sql.types.{DoubleType, StructField, StructType}
import org.apache.spark.util.Utils

class LibSVMRelationSuite
abstract class LibSVMRelationSuiteBase
extends SparkFunSuite
with MLlibTestSparkContext
with CommonFileDataSourceSuite {

override protected def dataSourceFormat = "libsvm"
override protected def inputDataset = {
val rawData = new java.util.ArrayList[Row]()
rawData.add(Row(1.0, Vectors.sparse(1, Seq((0, 1.0)))))
val struct = new StructType()
.add("labelFoo", DoubleType, false)
.add("featuresBar", VectorType, false)
spark.createDataFrame(rawData, struct)
}
with MLlibTestSparkContext {

// Path for dataset
var path: String = _
Expand Down Expand Up @@ -78,6 +67,9 @@ class LibSVMRelationSuite
super.afterAll()
}
}
}

class LibSVMRelationSuite extends LibSVMRelationSuiteBase {

test("select as sparse vector") {
val df = spark.read.format("libsvm").load(path)
Expand Down Expand Up @@ -226,3 +218,17 @@ class LibSVMRelationSuite
}
}
}

class LibSVMRelationSuiteWithCommonFileSourceCheck
extends LibSVMRelationSuiteBase with CommonFileDataSourceSuite {

override protected def dataSourceFormat = "libsvm"
override protected def inputDataset = {
val rawData = new java.util.ArrayList[Row]()
rawData.add(Row(1.0, Vectors.sparse(1, Seq((0, 1.0)))))
val struct = new StructType()
.add("labelFoo", DoubleType, false)
.add("featuresBar", VectorType, false)
spark.createDataFrame(rawData, struct)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ CREATE TABLE default.tbl (
b STRING,
c INT)
USING parquet
LOCATION 'file:/path/to/table'
LOCATION 'file:///path/to/table'


-- !query
Expand Down Expand Up @@ -110,7 +110,7 @@ CREATE TABLE default.tbl (
b STRING,
c INT)
USING parquet
LOCATION 'file:/path/to/table'
LOCATION 'file:///path/to/table'


-- !query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@ class DataSourceV2SQLSuite
val properties = table.properties
assert(properties.get(TableCatalog.PROP_PROVIDER) == "parquet")
assert(properties.get(TableCatalog.PROP_COMMENT) == "This is a comment")
assert(properties.get(TableCatalog.PROP_LOCATION) == "file:/tmp")
assert(properties.get(TableCatalog.PROP_LOCATION) == "file:///tmp")
assert(properties.containsKey(TableCatalog.PROP_OWNER))
assert(properties.get(TableCatalog.PROP_EXTERNAL) == "true")
assert(properties.get(s"${TableCatalog.OPTION_PREFIX}from") == "0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ShowCreateTableSuite extends command.ShowCreateTableSuiteBase with Command
"'via' = '2')",
"PARTITIONED BY (a)",
"COMMENT 'This is a comment'",
"LOCATION 'file:/tmp'",
"LOCATION 'file:///tmp'",
"TBLPROPERTIES (",
"'prop1' = '1',",
"'prop2' = '2',",
Expand Down

0 comments on commit 67c2318

Please sign in to comment.