the-other-tim-brown commented on code in PR #14374:
URL: https://github.com/apache/hudi/pull/14374#discussion_r2590765724
##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaUtils.java:
##########
@@ -140,6 +141,57 @@ public static HoodieSchema
createNullableSchema(HoodieSchema schema) {
return HoodieSchema.fromAvroSchema(nullableAvro);
}
+ /**
+ * Removes specified fields from a RECORD schema.
+ * This is equivalent to HoodieAvroUtils.removeFields() but operates on
HoodieSchema.
+ *
+ * @param schema original schema (must be RECORD type)
+ * @param fieldNamesToRemove set of field names to remove
+ * @return new HoodieSchema without the specified fields
+ * @throws IllegalArgumentException if schema is null or not a RECORD type
+ */
+ public static HoodieSchema removeFields(HoodieSchema schema, Set<String>
fieldNamesToRemove) {
+ ValidationUtils.checkArgument(schema != null, "Schema cannot be null");
+ ValidationUtils.checkArgument(schema.getType() == HoodieSchemaType.RECORD,
+ () -> "Only RECORD schemas can have fields removed, got: " +
schema.getType());
+
+ if (fieldNamesToRemove == null || fieldNamesToRemove.isEmpty()) {
+ return schema;
+ }
+
+ // Filter and copy fields (must create new instances, can't reuse Avro
fields)
+ List<HoodieSchemaField> filteredFields = schema.getFields().stream()
+ .filter(field -> !fieldNamesToRemove.contains(field.name()))
+ .map(field -> HoodieSchemaUtils.createNewSchemaField(
+ field.name(),
+ field.schema(),
+ field.doc().orElse(null),
+ field.defaultVal().orElse(null)
Review Comment:
You can simplify this by just passing in `field`
--
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]