Skip to content
Snippets Groups Projects
Commit 22f07fef authored by bomeng's avatar bomeng Committed by Reynold Xin
Browse files

[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.
parent dd2e7d52
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
......
......@@ -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() == "")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment