Skip to content

Commit 753ed82

Browse files
committed
[HUDI-4079] Supports showing table comment for hudi with spark3
1 parent 52fe1c9 commit 753ed82

2 files changed

Lines changed: 38 additions & 14 deletions

File tree

hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestCreateTable.scala

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import org.apache.hudi.common.table.{HoodieTableConfig, HoodieTableMetaClient}
2323
import org.apache.hudi.config.HoodieWriteConfig
2424
import org.apache.hudi.hadoop.realtime.HoodieParquetRealtimeInputFormat
2525
import org.apache.hudi.keygen.{ComplexKeyGenerator, NonpartitionedKeyGenerator, SimpleKeyGenerator}
26+
import org.apache.spark.SPARK_VERSION
2627
import org.apache.spark.sql.SaveMode
2728
import org.apache.spark.sql.catalyst.TableIdentifier
2829
import org.apache.spark.sql.catalyst.catalog.CatalogTableType
2930
import org.apache.spark.sql.types._
30-
3131
import scala.collection.JavaConverters._
3232

3333
class TestCreateTable extends HoodieSparkSqlTestBase {
@@ -641,4 +641,26 @@ class TestCreateTable extends HoodieSparkSqlTestBase {
641641
|""".stripMargin
642642
)
643643
}
644+
645+
if (SPARK_VERSION.startsWith("3")) {
646+
test("Test create table with comment") {
647+
val tableName = generateTableName
648+
spark.sql(
649+
s"""
650+
| create table $tableName (
651+
| id int,
652+
| name string,
653+
| price double,
654+
| ts long
655+
| ) using hudi
656+
| comment "This is a simple hudi table"
657+
| tblproperties (
658+
| primaryKey = 'id',
659+
| preCombineField = 'ts'
660+
| )
661+
""".stripMargin)
662+
val shown = spark.sql(s"show create table $tableName").head.getString(0)
663+
assertResult(true)(shown.contains("COMMENT 'This is a simple hudi table'"))
664+
}
665+
}
644666
}

hudi-spark-datasource/hudi-spark3/src/main/scala/org/apache/spark/sql/hudi/catalog/HoodieCatalog.scala

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,21 @@ class HoodieCatalog extends DelegatingCatalogExtension
8989
}
9090

9191
override def loadTable(ident: Identifier): Table = {
92-
try {
93-
super.loadTable(ident) match {
94-
case v1: V1Table if sparkAdapter.isHoodieTable(v1.catalogTable) =>
95-
HoodieInternalV2Table(
96-
spark,
97-
v1.catalogTable.location.toString,
98-
catalogTable = Some(v1.catalogTable),
99-
tableIdentifier = Some(ident.toString))
100-
case o => o
101-
}
102-
} catch {
103-
case e: Exception =>
104-
throw e
92+
super.loadTable(ident) match {
93+
case V1Table(catalogTable0) if sparkAdapter.isHoodieTable(catalogTable0) =>
94+
val catalogTable = catalogTable0.comment match {
95+
case Some(v) =>
96+
val newProps = catalogTable0.properties + (TableCatalog.PROP_COMMENT -> v)
97+
catalogTable0.copy(properties = newProps)
98+
case _ =>
99+
catalogTable0
100+
}
101+
HoodieInternalV2Table(
102+
spark = spark,
103+
path = catalogTable.location.toString,
104+
catalogTable = Some(catalogTable),
105+
tableIdentifier = Some(ident.toString))
106+
case o => o
105107
}
106108
}
107109

0 commit comments

Comments
 (0)