Skip to content

Commit

Permalink
[HUDI-4183] Fix using HoodieCatalog to create non-hudi tables (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
leesf authored and yihua committed Jun 7, 2022
1 parent 4e053c0 commit 6db0720
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -781,4 +781,35 @@ class TestCreateTable extends HoodieSparkSqlTestBase {
val tablePath = s"${dbPath}/${tableName}"
assertResult(false)(existsPath(tablePath))
}

test("Test Create Non-Hudi Table(Parquet Table)") {
val databaseName = "test_database"
spark.sql(s"create database if not exists $databaseName")
spark.sql(s"use $databaseName")

val tableName = generateTableName
// Create a managed table
spark.sql(
s"""
| create table $tableName (
| id int,
| name string,
| price double,
| ts long
| ) using parquet
""".stripMargin)
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier(tableName))
assertResult(tableName)(table.identifier.table)
assertResult("parquet")(table.provider.get)
assertResult(CatalogTableType.MANAGED)(table.tableType)
assertResult(
Seq(
StructField("id", IntegerType),
StructField("name", StringType),
StructField("price", DoubleType),
StructField("ts", LongType))
)(table.schema.fields)

spark.sql("use default")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ class HoodieCatalog extends DelegatingCatalogExtension
schema: StructType,
partitions: Array[Transform],
properties: util.Map[String, String]): Table = {
val locUriAndTableType = deduceTableLocationURIAndTableType(ident, properties)
createHoodieTable(ident, schema, locUriAndTableType, partitions, properties,
Map.empty, Option.empty, TableCreationMode.CREATE)
if (sparkAdapter.isHoodieTable(properties)) {
val locUriAndTableType = deduceTableLocationURIAndTableType(ident, properties)
createHoodieTable(ident, schema, locUriAndTableType, partitions, properties,
Map.empty, Option.empty, TableCreationMode.CREATE)
} else {
super.createTable(ident, schema, partitions, properties)
}
}

override def tableExists(ident: Identifier): Boolean = super.tableExists(ident)
Expand Down

0 comments on commit 6db0720

Please sign in to comment.