the-other-tim-brown commented on code in PR #18098:
URL: https://github.com/apache/hudi/pull/18098#discussion_r2957151720
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/ddl/TestCreateTable.scala:
##########
@@ -1996,4 +1997,105 @@ class TestCreateTable extends HoodieSparkSqlTestBase {
HoodieSparkSqlTestBase.enableComplexKeygenValidation(spark, tableName)
checkAnswer(query)(expectedRowsAfter: _*)
}
+
+ test("test create table with BLOB column") {
+ withTempDir { tmp =>
+ val tableName = generateTableName
+ spark.sql(
+ s"""
+ |CREATE TABLE $tableName (
+ | id BIGINT,
+ | video BLOB COMMENT 'Product demonstration video'
+ |) USING hudi
+ |LOCATION '${tmp.getCanonicalPath}'
+ |TBLPROPERTIES (
+ | primaryKey = 'id'
+ |)
+ """.stripMargin)
+
+ // Verify schema has hudi_blob metadata
+ val schema = spark.table(tableName).schema
+ val videoField = schema.find(_.name == "video").get
+
assertTrue(videoField.metadata.contains(HoodieSchema.TYPE_METADATA_FIELD))
+ assertEquals(HoodieSchemaType.BLOB.name(),
videoField.metadata.getString(HoodieSchema.TYPE_METADATA_FIELD))
+ assertEquals("Product demonstration video",
videoField.metadata.getString("comment"))
+
+ // Verify structure matches blob schema
+ assertTrue(videoField.dataType.isInstanceOf[StructType])
+ assertEquals(BlobType(), videoField.dataType)
+ }
+ }
+
+ test("test create table with multiple BLOB columns") {
+ withTempDir { tmp =>
+ val tableName = generateTableName
+ spark.sql(
+ s"""
+ |CREATE TABLE $tableName (
+ | id BIGINT,
+ | video BLOB,
+ | thumbnail blob,
+ | metadata MAP<STRING, STRING>,
+ | audio BLOB NOT NULL
+ |) USING hudi
+ |LOCATION '${tmp.getCanonicalPath}'
+ |TBLPROPERTIES (
+ | primaryKey = 'id'
+ |)
+ """.stripMargin)
+
+ val schema = spark.table(tableName).schema
+
+ // Verify all BLOB columns have the metadata
+ val blobColumns = Seq("video", "thumbnail", "audio")
+ blobColumns.foreach { colName =>
+ val field = schema.find(_.name == colName).get
+ assertTrue(field.metadata.contains(HoodieSchema.TYPE_METADATA_FIELD))
+ assertEquals(HoodieSchemaType.BLOB.name(),
field.metadata.getString(HoodieSchema.TYPE_METADATA_FIELD))
+ assertTrue(field.dataType.isInstanceOf[StructType])
+
+ if (colName == "audio") {
+ assertFalse(field.nullable)
+ } else {
+ assertTrue(field.nullable)
+ }
+
+ val blobStruct = field.dataType.asInstanceOf[StructType]
+ assertEquals(BlobType(), blobStruct)
+ }
+ }
+ }
+
+ test("test BLOB in nested struct") {
+ withTempDir { tmp =>
+ val tableName = generateTableName
+ spark.sql(
+ s"""
+ |CREATE TABLE $tableName (
+ | id BIGINT,
+ | media STRUCT<title: STRING, content: BLOB>
+ |) USING hudi
+ |LOCATION '${tmp.getCanonicalPath}'
+ |TBLPROPERTIES (
+ | primaryKey = 'id'
+ |)
+ """.stripMargin)
+
+ val schema = spark.table(tableName).schema
+ val mediaField = schema.find(_.name == "media").get
+ assertTrue(mediaField.dataType.isInstanceOf[StructType])
+
+ val mediaStruct = mediaField.dataType.asInstanceOf[StructType]
+ val contentField = mediaStruct.find(_.name == "content").get
+
+ // Verify nested BLOB has metadata
+
assertTrue(contentField.metadata.contains(HoodieSchema.TYPE_METADATA_FIELD))
+ assertEquals(HoodieSchemaType.BLOB.name(),
contentField.metadata.getString(HoodieSchema.TYPE_METADATA_FIELD))
+
+ // Verify structure
+ assertTrue(contentField.dataType.isInstanceOf[StructType])
+ val blobStruct = contentField.dataType.asInstanceOf[StructType]
+ assertEquals(BlobType(), blobStruct)
+ }
+ }
Review Comment:
I'll see if this is easy to support. If not, we can move it to a follow up.
We'll likely want to optimize this to just use the length in the struct itself
instead of reading the bytes from the files
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]