Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode Character Tests #1

Merged
merged 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions src/it/scala/com/exasol/spark/BaseDockerSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ trait BaseDockerSuite extends ForAllTestContainer { self: Suite =>
def runExaQuery(queryString: String): Unit =
runExaQuery(Seq(queryString))

// scalastyle:off
def createDummyTable(): Unit = {
runExaQuery(s"DROP SCHEMA IF EXISTS $EXA_SCHEMA CASCADE")
runExaQuery(s"CREATE SCHEMA $EXA_SCHEMA")
Expand All @@ -40,22 +41,24 @@ trait BaseDockerSuite extends ForAllTestContainer { self: Suite =>
| NAME VARCHAR(100) UTF8,
| CITY VARCHAR(2000) UTF8,
| DATE_INFO DATE,
| UPDATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
| UPDATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
| UNICODE_COL VARCHAR(100) UTF8
|)""".stripMargin)
runExaQuery(s"""
|INSERT INTO $EXA_SCHEMA.$EXA_TABLE (name, city, date_info)
| VALUES ('Germany', 'Berlin', '2017-12-31')
|INSERT INTO $EXA_SCHEMA.$EXA_TABLE (name, city, date_info, unicode_col)
| VALUES ('Germany', 'Berlin', '2017-12-31', 'öäüß')
| """.stripMargin)
runExaQuery(s"""
|INSERT INTO $EXA_SCHEMA.$EXA_TABLE (name, city, date_info)
| VALUES ('France', 'Paris', '2018-01-01')
|INSERT INTO $EXA_SCHEMA.$EXA_TABLE (name, city, date_info, unicode_col)
| VALUES ('France', 'Paris', '2018-01-01','\u00d6')
| """.stripMargin)
runExaQuery(s"""
|INSERT INTO $EXA_SCHEMA.$EXA_TABLE (name, city, date_info)
| VALUES ('Portugal', 'Lisbon', '2018-10-01')
|INSERT INTO $EXA_SCHEMA.$EXA_TABLE (name, city, date_info, unicode_col)
| VALUES ('Portugal', 'Lisbon', '2018-10-01','\u00d9')
| """.stripMargin)
runExaQuery("commit")
}
// scalastyle:on

def createAllTypesTable(): Unit = {
runExaQuery(s"DROP SCHEMA IF EXISTS $EXA_SCHEMA CASCADE")
Expand Down
36 changes: 35 additions & 1 deletion src/it/scala/com/exasol/spark/LoadSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class LoadSuite extends FunSuite with BaseDockerSuite with DataFrameSuiteBase {

val schema = df2.schema
assert(schema.exists(f => f.name == "NAME"))
assert(schema.map(_.name).toSet === Set("ID", "NAME", "CITY", "DATE_INFO", "UPDATED_AT"))
assert(
schema.map(_.name).toSet ===
Set("ID", "UNICODE_COL", "NAME", "CITY", "DATE_INFO", "UPDATED_AT")
)

val typeSet = schema.map(_.dataType).toSet
assert(typeSet === Set(LongType, StringType, StringType, DateType, TimestampType))
Expand Down Expand Up @@ -157,4 +160,35 @@ class LoadSuite extends FunSuite with BaseDockerSuite with DataFrameSuiteBase {
assert(df.collect().map(_(0)).toSet === Set("Berlin", "Lisbon", "Paris"))
}

test("load unicode data from exasol") {
createDummyTable()

val sparkConf = new SparkConf()
.setMaster("local[*]")
.set("spark.exasol.port", s"${container.port}")
.set("spark.exasol.host", container.host)
.set("spark.exasol.max_nodes", "200")

val sparkSession = SparkSession
.builder()
.config(sparkConf)
.getOrCreate()

val df = sparkSession.read
.format("exasol")
.option(
"query",
s"SELECT UNICODE_COL FROM $EXA_SCHEMA.$EXA_TABLE " +
s" WHERE UNICODE_COL IS NOT NULL"
)
.option("port", s"falsePortNumber")
.option("host", s"falseHostName")
.load()

assert(df.count() === 3)
// scalastyle:off
assert(df.collect().map(_(0)).toSet === Set("öäüß", "Ö", "Ù"))
// scalastyle:on
}

}