[HUDI-4079] Supports showing table comment for hudi with spark3 (#5546)
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
package org.apache.spark.sql.hudi
|
package org.apache.spark.sql.hudi
|
||||||
|
|
||||||
import org.apache.hudi.DataSourceWriteOptions._
|
import org.apache.hudi.DataSourceWriteOptions._
|
||||||
|
import org.apache.hudi.HoodieSparkUtils
|
||||||
import org.apache.hudi.common.model.HoodieRecord
|
import org.apache.hudi.common.model.HoodieRecord
|
||||||
import org.apache.hudi.common.table.{HoodieTableConfig, HoodieTableMetaClient}
|
import org.apache.hudi.common.table.{HoodieTableConfig, HoodieTableMetaClient}
|
||||||
import org.apache.hudi.config.HoodieWriteConfig
|
import org.apache.hudi.config.HoodieWriteConfig
|
||||||
@@ -641,4 +642,26 @@ class TestCreateTable extends HoodieSparkSqlTestBase {
|
|||||||
|""".stripMargin
|
|""".stripMargin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HoodieSparkUtils.gteqSpark3_2) {
|
||||||
|
test("Test create table with comment") {
|
||||||
|
val tableName = generateTableName
|
||||||
|
spark.sql(
|
||||||
|
s"""
|
||||||
|
| create table $tableName (
|
||||||
|
| id int,
|
||||||
|
| name string,
|
||||||
|
| price double,
|
||||||
|
| ts long
|
||||||
|
| ) using hudi
|
||||||
|
| comment "This is a simple hudi table"
|
||||||
|
| tblproperties (
|
||||||
|
| primaryKey = 'id',
|
||||||
|
| preCombineField = 'ts'
|
||||||
|
| )
|
||||||
|
""".stripMargin)
|
||||||
|
val shown = spark.sql(s"show create table $tableName").head.getString(0)
|
||||||
|
assertResult(true)(shown.contains("COMMENT 'This is a simple hudi table'"))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,20 +89,22 @@ class HoodieCatalog extends DelegatingCatalogExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
override def loadTable(ident: Identifier): Table = {
|
override def loadTable(ident: Identifier): Table = {
|
||||||
try {
|
|
||||||
super.loadTable(ident) match {
|
super.loadTable(ident) match {
|
||||||
case v1: V1Table if sparkAdapter.isHoodieTable(v1.catalogTable) =>
|
case V1Table(catalogTable0) if sparkAdapter.isHoodieTable(catalogTable0) =>
|
||||||
|
val catalogTable = catalogTable0.comment match {
|
||||||
|
case Some(v) =>
|
||||||
|
val newProps = catalogTable0.properties + (TableCatalog.PROP_COMMENT -> v)
|
||||||
|
catalogTable0.copy(properties = newProps)
|
||||||
|
case _ =>
|
||||||
|
catalogTable0
|
||||||
|
}
|
||||||
HoodieInternalV2Table(
|
HoodieInternalV2Table(
|
||||||
spark,
|
spark = spark,
|
||||||
v1.catalogTable.location.toString,
|
path = catalogTable.location.toString,
|
||||||
catalogTable = Some(v1.catalogTable),
|
catalogTable = Some(catalogTable),
|
||||||
tableIdentifier = Some(ident.toString))
|
tableIdentifier = Some(ident.toString))
|
||||||
case o => o
|
case o => o
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
case e: Exception =>
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override def createTable(ident: Identifier,
|
override def createTable(ident: Identifier,
|
||||||
|
|||||||
Reference in New Issue
Block a user