-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
[SPARK-16024] [SQL] [TEST] Verify Column Comment for Data Source Tables #13764
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import org.apache.spark.sql.hive.{HiveUtils, MetastoreRelation} | |
import org.apache.spark.sql.hive.test.TestHive._ | ||
import org.apache.spark.sql.hive.test.TestHive.implicits._ | ||
import org.apache.spark.sql.internal.SQLConf | ||
import org.apache.spark.sql.types.{IntegerType, MetadataBuilder, StructField, StructType} | ||
|
||
case class AllDataTypesWithNonPrimitiveType( | ||
stringField: String, | ||
|
@@ -462,4 +463,27 @@ class OrcQuerySuite extends QueryTest with BeforeAndAfterAll with OrcTest { | |
} | ||
} | ||
} | ||
|
||
test("column nullability and comment - write and then read") { | ||
val schema = StructType( | ||
StructField("cl1", IntegerType, nullable = false, | ||
new MetadataBuilder().putString("comment", "test").build()) :: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm, is this the official way to add column comment when create table using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. : ) It is a little bit hacky. Maybe we should add a new API for users to add comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I am afraid it is. I just grepped through the code base and there are a few places where we do this, for example: +1 for adding a convenience method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want me to submit a new PR for this? Or add it into this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can open a new PR and move this test there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, let me remove it and submit a new PR soon. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hvanhovell @cloud-fan The new methods are added in the PR: #13860 Could you please review it? Thanks! |
||
StructField("cl2", IntegerType, nullable = true) :: | ||
StructField("cl3", IntegerType, nullable = true) :: Nil) | ||
val row = Row(3, null, 4) | ||
val df = spark.createDataFrame(sparkContext.parallelize(row :: Nil), schema) | ||
|
||
val tableName = "tab" | ||
withTable(tableName) { | ||
df.write.format("orc").mode("overwrite").saveAsTable(tableName) | ||
// Verify the DDL command result: DESCRIBE TABLE | ||
checkAnswer( | ||
sql(s"desc $tableName").select("col_name", "comment").where($"comment" === "test"), | ||
Row("cl1", "test") :: Nil) | ||
// Verify the schema | ||
val expectedFields = schema.fields.map(f => f.copy(nullable = true)) | ||
assert(spark.table(tableName).schema == schema.copy(fields = expectedFields)) | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also remove this test, let's focus on SQL CREATE TABLE in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me change it. Thanks!