aboutsummaryrefslogtreecommitdiff
path: root/sql/hive/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sql/hive/src/test')
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala45
1 files changed, 45 insertions, 0 deletions
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
index 951e070414..f313db641b 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
@@ -147,6 +147,51 @@ class HiveDDLSuite
}
}
+ test("create Hive-serde table and view with unicode columns and comment") {
+ val catalog = spark.sessionState.catalog
+ val tabName = "tab1"
+ val viewName = "view1"
+ // scalastyle:off
+ // non ascii characters are not allowed in the source code, so we disable the scalastyle.
+ val colName1 = "和"
+ val colName2 = "尼"
+ val comment = "庙"
+ // scalastyle:on
+ withTable(tabName) {
+ sql(s"""
+ |CREATE TABLE $tabName(`$colName1` int COMMENT '$comment')
+ |COMMENT '$comment'
+ |PARTITIONED BY (`$colName2` int)
+ """.stripMargin)
+ sql(s"INSERT OVERWRITE TABLE $tabName partition (`$colName2`=2) SELECT 1")
+ withView(viewName) {
+ sql(
+ s"""
+ |CREATE VIEW $viewName(`$colName1` COMMENT '$comment', `$colName2`)
+ |COMMENT '$comment'
+ |AS SELECT `$colName1`, `$colName2` FROM $tabName
+ """.stripMargin)
+ val tableMetadata = catalog.getTableMetadata(TableIdentifier(tabName, Some("default")))
+ val viewMetadata = catalog.getTableMetadata(TableIdentifier(viewName, Some("default")))
+ assert(tableMetadata.comment == Option(comment))
+ assert(viewMetadata.comment == Option(comment))
+
+ assert(tableMetadata.schema.fields.length == 2 && viewMetadata.schema.fields.length == 2)
+ val column1InTable = tableMetadata.schema.fields.head
+ val column1InView = viewMetadata.schema.fields.head
+ assert(column1InTable.name == colName1 && column1InView.name == colName1)
+ assert(column1InTable.getComment() == Option(comment))
+ assert(column1InView.getComment() == Option(comment))
+
+ assert(tableMetadata.schema.fields(1).name == colName2 &&
+ viewMetadata.schema.fields(1).name == colName2)
+
+ checkAnswer(sql(s"SELECT `$colName1`, `$colName2` FROM $tabName"), Row(1, 2) :: Nil)
+ checkAnswer(sql(s"SELECT `$colName1`, `$colName2` FROM $viewName"), Row(1, 2) :: Nil)
+ }
+ }
+ }
+
test("create table: partition column names exist in table definition") {
val e = intercept[AnalysisException] {
sql("CREATE TABLE tbl(a int) PARTITIONED BY (a string)")