aboutsummaryrefslogtreecommitdiff
path: root/sql/hive-thriftserver
diff options
context:
space:
mode:
authorbomeng <bmeng@us.ibm.com>2017-03-29 18:57:35 -0700
committerReynold Xin <rxin@databricks.com>2017-03-29 18:57:35 -0700
commit22f07fefe11f0147f1e8d83d9b77707640d5dc97 (patch)
tree5db43dc4e059142a9844f3e404e084afc30480bd /sql/hive-thriftserver
parentdd2e7d528cb7468cdc077403f314c7ee0f214ac5 (diff)
downloadspark-22f07fefe11f0147f1e8d83d9b77707640d5dc97.tar.gz
spark-22f07fefe11f0147f1e8d83d9b77707640d5dc97.tar.bz2
spark-22f07fefe11f0147f1e8d83d9b77707640d5dc97.zip
[SPARK-20146][SQL] fix comment missing issue for thrift server
## What changes were proposed in this pull request? The column comment was missing while constructing the Hive TableSchema. This fix will preserve the original comment. ## How was this patch tested? I have added a new test case to test the column with/without comment. Author: bomeng <bmeng@us.ibm.com> Closes #17470 from bomeng/SPARK-20146.
Diffstat (limited to 'sql/hive-thriftserver')
-rw-r--r--sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperation.scala2
-rw-r--r--sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperationSuite.scala14
2 files changed, 14 insertions, 2 deletions
diff --git a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperation.scala b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperation.scala
index 517b01f183..ff3784cab9 100644
--- a/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperation.scala
+++ b/sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperation.scala
@@ -292,7 +292,7 @@ object SparkExecuteStatementOperation {
def getTableSchema(structType: StructType): TableSchema = {
val schema = structType.map { field =>
val attrTypeString = if (field.dataType == NullType) "void" else field.dataType.catalogString
- new FieldSchema(field.name, attrTypeString, "")
+ new FieldSchema(field.name, attrTypeString, field.getComment.getOrElse(""))
}
new TableSchema(schema.asJava)
}
diff --git a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperationSuite.scala b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperationSuite.scala
index 32ded0d254..06e3980662 100644
--- a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperationSuite.scala
+++ b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperationSuite.scala
@@ -18,7 +18,7 @@
package org.apache.spark.sql.hive.thriftserver
import org.apache.spark.SparkFunSuite
-import org.apache.spark.sql.types.{NullType, StructField, StructType}
+import org.apache.spark.sql.types.{IntegerType, NullType, StringType, StructField, StructType}
class SparkExecuteStatementOperationSuite extends SparkFunSuite {
test("SPARK-17112 `select null` via JDBC triggers IllegalArgumentException in ThriftServer") {
@@ -30,4 +30,16 @@ class SparkExecuteStatementOperationSuite extends SparkFunSuite {
assert(columns.get(0).getType() == org.apache.hive.service.cli.Type.NULL_TYPE)
assert(columns.get(1).getType() == org.apache.hive.service.cli.Type.NULL_TYPE)
}
+
+ test("SPARK-20146 Comment should be preserved") {
+ val field1 = StructField("column1", StringType).withComment("comment 1")
+ val field2 = StructField("column2", IntegerType)
+ val tableSchema = StructType(Seq(field1, field2))
+ val columns = SparkExecuteStatementOperation.getTableSchema(tableSchema).getColumnDescriptors()
+ assert(columns.size() == 2)
+ assert(columns.get(0).getType() == org.apache.hive.service.cli.Type.STRING_TYPE)
+ assert(columns.get(0).getComment() == "comment 1")
+ assert(columns.get(1).getType() == org.apache.hive.service.cli.Type.INT_TYPE)
+ assert(columns.get(1).getComment() == "")
+ }
}