lordcheng10 commented on code in PR #8238:
URL: https://github.com/apache/inlong/pull/8238#discussion_r1229147191
##########
inlong-sort/sort-flink/sort-flink-v1.13/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/multiple/IcebergSingleStreamWriter.java:
##########
@@ -142,10 +152,62 @@ public void prepareSnapshotPreBarrier(long checkpointId)
throws Exception {
this.writer = taskWriterFactory.create();
}
+ public static RowData removeField(RowData rowData, int fieldIndex, RowType
rowType) {
+ GenericRowData newRowData = new GenericRowData(rowType.getFieldCount()
- 1);
+
+ for (int i = 0, j = 0; i < rowType.getFieldCount(); i++) {
+ if (i != fieldIndex) {
+ newRowData.setField(j++, rowData.getRawValue(i));
+ }
+ }
+
+ return newRowData;
+ }
+
+ public void switchToUpsert() throws Exception {
+ if (taskWriterFactory.isAppendMode()) {
+ taskWriterFactory.switchToUpsert();
+ prepareSnapshotPreBarrier(0);
+ }
+ }
+
+ public void switchToAppend() throws Exception {
+ if (taskWriterFactory.isAppendMode())
+ return;
+
+ taskWriterFactory.switchToAppend();
+ prepareSnapshotPreBarrier(0);
+ }
+
@Override
public void processElement(T value) throws Exception {
try {
- writer.write(value);
+ if (!multipleSink) {
+ RowData rowData = (RowData) value;
+ boolean incremental = false;
+ RowType rowType = (RowType)
tableSchema.toRowDataType().getLogicalType();
+ List<RowType.RowField> fields = rowType.getFields();
+ int fieldIndex = 0;
+ for (int i = 0; i < fields.size(); i++) {
+ RowType.RowField rowField = fields.get(i);
+ if (META_INCREMENTAL.equals(rowField.getName())) {
+ incremental = rowData.getBoolean(i);
+ fieldIndex = i;
+ break;
+ }
+ }
+
+ RowData newRowData = removeField(rowData, fieldIndex, rowType);
+
+ if (incremental) {
+ switchToUpsert();
Review Comment:
will close the writer and recreate a writer:
<img width="1193" alt="image"
src="https://github.com/apache/inlong/assets/19296967/a5620f5f-b45e-4548-a689-7b70d5343376">
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]