Skip to content

Commit 5ef54de

Browse files
committed
relax validation for primary key
1 parent 9110040 commit 5ef54de

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/HoodieOptionConfig.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ object HoodieOptionConfig {
199199
.map(_.split(",").filter(_.length > 0))
200200
ValidationUtils.checkArgument(primaryKeys.nonEmpty, "No `primaryKey` is specified.")
201201
primaryKeys.get.foreach { primaryKey =>
202-
ValidationUtils.checkArgument(schema.exists(f => resolver(f.name, primaryKey)),
202+
ValidationUtils.checkArgument(schema.exists(f => resolver(f.name, getRootLevelFieldName(primaryKey))),
203203
s"Can't find primaryKey `$primaryKey` in ${schema.treeString}.")
204204
}
205205

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -664,15 +664,14 @@ class TestInsertTable extends HoodieSparkSqlTestBase {
664664
}
665665
}
666666

667-
test("Test nested field as preCombineField") {
667+
test("Test nested field as primaryKey and preCombineField") {
668668
withTempDir { tmp =>
669669
Seq("cow", "mor").foreach { tableType =>
670670
val tableName = generateTableName
671671
// create table
672672
spark.sql(
673673
s"""
674674
|create table $tableName (
675-
| id int,
676675
| name string,
677676
| price double,
678677
| ts long,
@@ -681,18 +680,18 @@ class TestInsertTable extends HoodieSparkSqlTestBase {
681680
| location '${tmp.getCanonicalPath}/$tableName'
682681
| options (
683682
| type = '$tableType',
684-
| primaryKey = 'id',
683+
| primaryKey = 'nestedcol.a1',
685684
| preCombineField = 'nestedcol.a2.b2.c2'
686685
| )
687686
""".stripMargin)
688687
// insert data to table
689688
spark.sql(
690689
s"""insert into $tableName values
691-
|(0, 'name_1', 10, 1000, struct('a', struct('b', struct('c', 999)))),
692-
|(0, 'name_2', 20, 2000, struct('a', struct('b', struct('c', 333))))
690+
|('name_1', 10, 1000, struct('a', struct('b', struct('c', 999)))),
691+
|('name_2', 20, 2000, struct('a', struct('b', struct('c', 333))))
693692
|""".stripMargin)
694-
checkAnswer(s"select id, name, price, ts, nestedcol, nestedcol.a2.b2.c2 from $tableName")(
695-
Seq(0, "name_1", 10.0, 1000, "{\"a1\":\"a\",\"a2\":{\"b1\":\"b\",\"b2\":{\"c1\":\"c\",\"c2\":999}}}, 999")
693+
checkAnswer(s"select name, price, ts, nestedcol.a1, nestedcol.a2.b2.c2 from $tableName")(
694+
Seq("name_1", 10.0, 1000, "a", 999)
696695
)
697696
}
698697
}

0 commit comments

Comments
 (0)