[ https://issues.apache.org/jira/browse/HUDI-2234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17445622#comment-17445622 ]
Raymond Xu commented on HUDI-2234: ---------------------------------- {code:java} create table if not exists h1 (id int, name string, price double, ts long) using hudi location '/tmp/hudi/tb1' options (type='cow', primaryKey='id', precombineField='ts'); create table if not exists h2 (id int, name string, price double, ts long) using hudi location '/tmp/hudi/tb2' options (type='cow', primaryKey='id', precombineField='ts'); insert into h1 select 3, 'AMZN', 300, 120; insert into h1 select 2, 'UBER', 300, 120; insert into h1 select 4, 'GOOG', 300, 120; insert into h2 select 2, 'UBER', 200, 120; merge into h1 as target using (select id, name, price, ts from h2) source on target.name = source.name when matched then update set * when not matched then insert *;{code} verified this with spark 3.1.2 using 0.10.0 SNAPSHOT, the merge into worked with non-primary key. > MERGE INTO works only ON primary key > ------------------------------------ > > Key: HUDI-2234 > URL: https://issues.apache.org/jira/browse/HUDI-2234 > Project: Apache Hudi > Issue Type: Sub-task > Components: Spark Integration > Reporter: Sagar Sumit > Assignee: Yann Byron > Priority: Blocker > Fix For: 0.10.0 > > > {code:sql} > drop table if exists hudi_gh_ext_fixed; > create table hudi_gh_ext_fixed (id int, name string, price double, ts long) > using hudi options(primaryKey = 'id', precombineField = 'ts') location > 'file:///tmp/hudi-h4-fixed'; > insert into hudi_gh_ext_fixed values(3, 'AMZN', 300, 120); > insert into hudi_gh_ext_fixed values(2, 'UBER', 300, 120); > insert into hudi_gh_ext_fixed values(4, 'GOOG', 300, 120); > update hudi_gh_ext_fixed set price = 150.0 where name = 'UBER'; > drop table if exists hudi_fixed; > create table hudi_fixed (id int, name string, price double, ts long) using > hudi options(primaryKey = 'id', precombineField = 'ts') partitioned by (ts) > location 'file:///tmp/hudi-h4-part-fixed'; > insert into hudi_fixed values(2, 'UBER', 200, 120); > MERGE INTO hudi_fixed > USING (select id, name, price, ts from hudi_gh_ext_fixed) updates > ON hudi_fixed.name = updates.name > WHEN MATCHED THEN > UPDATE SET * > WHEN NOT MATCHED > THEN INSERT *; > -- java.lang.IllegalArgumentException: Merge Key[name] is not Equal to the > defined primary key[id] in table hudi_fixed > -- at > org.apache.spark.sql.hudi.command.MergeIntoHoodieTableCommand.buildMergeIntoConfig(MergeIntoHoodieTableCommand.scala:425) > -- at > org.apache.spark.sql.hudi.command.MergeIntoHoodieTableCommand.run(MergeIntoHoodieTableCommand.scala:146) > -- at > org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult$lzycompute(commands.scala:70) > -- at > org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult(commands.scala:68) > -- at > org.apache.spark.sql.execution.command.ExecutedCommandExec.executeCollect(commands.scala:79) > -- at > org.apache.spark.sql.Dataset.$anonfun$logicalPlan$1(Dataset.scala:229) > {code} -- This message was sent by Atlassian Jira (v8.20.1#820001)