@@ -654,10 +654,10 @@ public InsertRowsResponse get() throws Throwable {
654654 "Invoking insertRows API for channel:{}, streamingBuffer:{}" ,
655655 this .channel .getFullyQualifiedName (),
656656 this .insertRowsStreamingBuffer );
657- Pair <List <Map <String , Object >>, List <Long >> recordsAndOffsets =
657+ Pair <List <Map <String , Object >>, List <SinkRecord >> recordsAndOriginalSinkRecords =
658658 this .insertRowsStreamingBuffer .getData ();
659- List <Map <String , Object >> records = recordsAndOffsets .getKey ();
660- List <Long > offsets = recordsAndOffsets .getValue ();
659+ List <Map <String , Object >> records = recordsAndOriginalSinkRecords .getKey ();
660+ List <SinkRecord > originalSinkRecords = recordsAndOriginalSinkRecords .getValue ();
661661 InsertValidationResponse finalResponse = new InsertValidationResponse ();
662662 boolean needToResetOffset = false ;
663663 if (!enableSchemaEvolution ) {
@@ -671,14 +671,18 @@ public InsertRowsResponse get() throws Throwable {
671671 // For schema evolution, we need to call the insertRows API row by row in order to
672672 // preserve the original order, for anything after the first schema mismatch error we will
673673 // retry after the evolution
674- InsertValidationResponse response =
675- this .channel .insertRow (records .get (idx ), Long .toString (offsets .get (idx )));
674+ SinkRecord originalSinkRecord = originalSinkRecords .get (idx );
675+ InsertValidationResponse response = this .channel .insertRow (
676+ records .get (idx ), Long .toString (originalSinkRecord .kafkaOffset ())
677+ );
676678 if (response .hasErrors ()) {
677679 InsertValidationResponse .InsertError insertError = response .getInsertErrors ().get (0 );
678680 List <String > extraColNames = insertError .getExtraColNames ();
679681 List <String > nonNullableColumns = insertError .getMissingNotNullColNames ();
680- long originalSinkRecordIdx =
681- offsets .get (idx ) - this .insertRowsStreamingBuffer .getFirstOffset ();
682+
683+ // TODO : originalSinkRecordIdx can be replaced by idx
684+ long originalSinkRecordIdx = originalSinkRecord .kafkaOffset ()
685+ - this .insertRowsStreamingBuffer .getFirstOffset ();
682686 if (extraColNames == null && nonNullableColumns == null ) {
683687 InsertValidationResponse .InsertError newInsertError =
684688 new InsertValidationResponse .InsertError (
@@ -694,7 +698,8 @@ public InsertRowsResponse get() throws Throwable {
694698 this .channel .getTableName (),
695699 nonNullableColumns ,
696700 extraColNames ,
697- this .insertRowsStreamingBuffer .getSinkRecord (originalSinkRecordIdx ));
701+ originalSinkRecord
702+ );
698703 // Offset reset needed since it's possible that we successfully ingested partial batch
699704 needToResetOffset = true ;
700705 break ;
@@ -1251,7 +1256,7 @@ protected long getApproxSizeOfRecordInBytes(SinkRecord kafkaSinkRecord) {
12511256 */
12521257 @ VisibleForTesting
12531258 protected class StreamingBuffer
1254- extends PartitionBuffer <Pair <List <Map <String , Object >>, List <Long >>> {
1259+ extends PartitionBuffer <Pair <List <Map <String , Object >>, List <SinkRecord >>> {
12551260 // Records coming from Kafka
12561261 private final List <SinkRecord > sinkRecords ;
12571262
@@ -1285,9 +1290,9 @@ public void insert(SinkRecord kafkaSinkRecord) {
12851290 * @return A pair that contains the records and their corresponding offsets
12861291 */
12871292 @ Override
1288- public Pair <List <Map <String , Object >>, List <Long >> getData () {
1293+ public Pair <List <Map <String , Object >>, List <SinkRecord >> getData () {
12891294 final List <Map <String , Object >> records = new ArrayList <>();
1290- final List <Long > offsets = new ArrayList <>();
1295+ final List <SinkRecord > filteredOriginalSinkRecords = new ArrayList <>();
12911296 for (SinkRecord kafkaSinkRecord : sinkRecords ) {
12921297 SinkRecord snowflakeRecord = getSnowflakeSinkRecordFromKafkaRecord (kafkaSinkRecord );
12931298
@@ -1313,7 +1318,7 @@ public Pair<List<Map<String, Object>>, List<Long>> getData() {
13131318 Map <String , Object > tableRow =
13141319 recordService .getProcessedRecordForStreamingIngest (snowflakeRecord );
13151320 records .add (tableRow );
1316- offsets .add (snowflakeRecord . kafkaOffset () );
1321+ filteredOriginalSinkRecords .add (kafkaSinkRecord );
13171322 } catch (JsonProcessingException e ) {
13181323 LOGGER .warn (
13191324 "Record has JsonProcessingException offset:{}, topic:{}" ,
@@ -1329,7 +1334,7 @@ public Pair<List<Map<String, Object>>, List<Long>> getData() {
13291334 getBufferSizeBytes (),
13301335 getFirstOffset (),
13311336 getLastOffset ());
1332- return new Pair <>(records , offsets );
1337+ return new Pair <>(records , filteredOriginalSinkRecords );
13331338 }
13341339
13351340 @ Override
0 commit comments