@@ -61,7 +61,11 @@ class UpsertWriterImpl extends AbstractTableWriter implements UpsertWriter {
6161 WriterClient writerClient ) {
6262 super (tablePath , tableInfo , writerClient );
6363 RowType rowType = tableInfo .getRowType ();
64- sanityCheck (rowType , tableInfo .getPrimaryKeys (), partialUpdateColumns );
64+ sanityCheck (
65+ rowType ,
66+ tableInfo .getPrimaryKeys (),
67+ tableInfo .getSchema ().getAutoIncrementColumnNames (),
68+ partialUpdateColumns );
6569
6670 this .targetColumns = partialUpdateColumns ;
6771 DataLakeFormat lakeFormat = tableInfo .getTableConfig ().getDataLakeFormat ().orElse (null );
@@ -80,9 +84,20 @@ class UpsertWriterImpl extends AbstractTableWriter implements UpsertWriter {
8084 }
8185
8286 private static void sanityCheck (
83- RowType rowType , List <String > primaryKeys , @ Nullable int [] targetColumns ) {
87+ RowType rowType ,
88+ List <String > primaryKeys ,
89+ List <String > autoIncrementColumnNames ,
90+ @ Nullable int [] targetColumns ) {
8491 // skip check when target columns is null
8592 if (targetColumns == null ) {
93+ if (!autoIncrementColumnNames .isEmpty ()) {
94+ throw new IllegalArgumentException (
95+ String .format (
96+ "This table has auto increment column %s."
97+ + "Explicitly specifying values for an auto increment column is not allowed."
98+ + "Please specify non-auto-increment columns as target columns using partialUpdate first." ,
99+ autoIncrementColumnNames ));
100+ }
86101 return ;
87102 }
88103 BitSet targetColumnsSet = new BitSet ();
@@ -116,6 +131,16 @@ private static void sanityCheck(
116131 }
117132 }
118133 }
134+
135+ // explicitly specifying values for an auto increment column is not allowed
136+ for (String autoIncrementColumnName : autoIncrementColumnNames ) {
137+ if (targetColumnsSet .get (rowType .getFieldIndex (autoIncrementColumnName ))) {
138+ throw new IllegalArgumentException (
139+ String .format (
140+ "Explicitly specifying values for the auto increment column %s is not allowed." ,
141+ autoIncrementColumnName ));
142+ }
143+ }
119144 }
120145
121146 /**
0 commit comments