Skip to content

Commit 34261f0

Browse files
authored
[HUDI-6909] Add logic to check operation metadata field for Spark Record (apache#11930)
1 parent ec32e03 commit 34261f0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/common/model/HoodieSparkRecord.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,25 @@ public HoodieRecord truncateRecordKey(Schema recordSchema, Properties props, Str
237237
}
238238

239239
@Override
240-
public boolean isDelete(Schema recordSchema, Properties props) throws IOException {
240+
public boolean isDelete(Schema recordSchema, Properties props) {
241241
if (null == data) {
242242
return true;
243243
}
244-
if (recordSchema.getField(HoodieRecord.HOODIE_IS_DELETED_FIELD) == null) {
244+
245+
// Use metadata filed to decide.
246+
Schema.Field operationField = recordSchema.getField(OPERATION_METADATA_FIELD);
247+
if (null != operationField
248+
&& HoodieOperation.isDeleteRecord((String) data.get(operationField.pos(), StringType))) {
249+
return true;
250+
}
251+
252+
// Use data field to decide.
253+
if (recordSchema.getField(HOODIE_IS_DELETED_FIELD) == null) {
245254
return false;
246255
}
247-
Object deleteMarker = data.get(recordSchema.getField(HoodieRecord.HOODIE_IS_DELETED_FIELD).pos(), BooleanType);
256+
257+
Object deleteMarker = data.get(
258+
recordSchema.getField(HOODIE_IS_DELETED_FIELD).pos(), BooleanType);
248259
return deleteMarker instanceof Boolean && (boolean) deleteMarker;
249260
}
250261

hudi-common/src/main/java/org/apache/hudi/common/model/HoodieOperation.java

+4
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,8 @@ public static boolean isUpdateAfter(HoodieOperation operation) {
122122
public static boolean isDelete(HoodieOperation operation) {
123123
return operation == DELETE;
124124
}
125+
126+
public static boolean isDeleteRecord(String name) {
127+
return isDelete(fromName(name));
128+
}
125129
}

0 commit comments

Comments
 (0)