diff options
author | Xiao Li <gatorsmile@gmail.com> | 2017-04-20 11:13:48 +0100 |
---|---|---|
committer | Sean Owen <sowen@cloudera.com> | 2017-04-20 11:13:48 +0100 |
commit | 55bea56911a958f6d3ec3ad96fb425cc71ec03f4 (patch) | |
tree | 08e8eb3d8f9fe1b473a90cea5bacee5f77e5ffa0 /sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala | |
parent | 46c5749768fefd976097c7d5612ec184a4cfe1b9 (diff) | |
download | spark-55bea56911a958f6d3ec3ad96fb425cc71ec03f4.tar.gz spark-55bea56911a958f6d3ec3ad96fb425cc71ec03f4.tar.bz2 spark-55bea56911a958f6d3ec3ad96fb425cc71ec03f4.zip |
[SPARK-20156][SQL][FOLLOW-UP] Java String toLowerCase "Turkish locale bug" in Database and Table DDLs
### What changes were proposed in this pull request?
Database and Table names conform the Hive standard ("[a-zA-z_0-9]+"), i.e. if this name only contains characters, numbers, and _.
When calling `toLowerCase` on the names, we should add `Locale.ROOT` to the `toLowerCase`for avoiding inadvertent locale-sensitive variation in behavior (aka the "Turkish locale problem").
### How was this patch tested?
Added a test case
Author: Xiao Li <gatorsmile@gmail.com>
Closes #17655 from gatorsmile/locale.
Diffstat (limited to 'sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala')
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala b/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala index 6a4cc95d36..b5ad73b746 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala @@ -20,7 +20,7 @@ package org.apache.spark.sql.test import java.io.File import java.net.URI import java.nio.file.Files -import java.util.UUID +import java.util.{Locale, UUID} import scala.language.implicitConversions import scala.util.control.NonFatal @@ -229,6 +229,32 @@ private[sql] trait SQLTestUtils } /** + * Drops database `dbName` after calling `f`. + */ + protected def withDatabase(dbNames: String*)(f: => Unit): Unit = { + try f finally { + dbNames.foreach { name => + spark.sql(s"DROP DATABASE IF EXISTS $name") + } + } + } + + /** + * Enables Locale `language` before executing `f`, then switches back to the default locale of JVM + * after `f` returns. + */ + protected def withLocale(language: String)(f: => Unit): Unit = { + val originalLocale = Locale.getDefault + try { + // Add Locale setting + Locale.setDefault(new Locale(language)) + f + } finally { + Locale.setDefault(originalLocale) + } + } + + /** * Activates database `db` before executing `f`, then switches back to `default` database after * `f` returns. */ |