cbg-wx opened a new pull request, #18595:
URL: https://github.com/apache/hudi/pull/18595
… have any schema in commit metadata
### Describe the issue this Pull Request addresses
<!-- Either describe the issue inline here with motivation behind the
changes
(or) link to an issue by including `Closes #<issue-number>` for
context.
If this PR includes changes to the storage format, public APIs,
or has breaking changes, use `!` (e.g., feat!: ...) -->
this pull request in order to close #18330
The exception occurs in the `setWriteSchemaForDeletes` method when a
`DELETE` operation is performed:
1. This method attempts to retrieve the schema from the most recent commit's
metadata.
2. If the metadata of the most recent commit does not contain a schema field
(`extraMetadata` is empty or does not contain a schema), an exception is thrown.
3. This can happen if:
- The table has just been created but no data has been written to it(the
config hoodie.allow.empty.commit default value is true ).
- Some older commits did not save schema information.
- The table's `create schema` was deleted or is missing.
**Fix Description**
This fix employs a fallback strategy:
1. Prioritizes the schema in commit metadata: If the most recent commit
metadata contains a schema, it is used (maintaining existing logic).
2. Falls to the table create schema: If the commit metadata does not contain
a schema, the schema saved during table creation is retrieved from
HoodieTableConfig.
3. Throws an exception only as a last resort: An exception is thrown only if
neither is present, with a more explicit error message.
The benefits of this approach are:
- Improved code robustness, preventing failures due to some commits not
saving the schema.
- Utilizes the persistent create schema in the Hoodie table configuration as
a fallback.
- For test scenarios (such as newly created tables), DELETE operations can
still be executed correctly even without writing data.
- Maintains backward compatibility.
### Summary and Changelog
<!-- Short, plain-English summary of what users gain or what changed in
behavior.
Followed by a detailed log of all the changes. Highlight if any code
was copied. -->
BaseHoodieWriteClient.java#setWriteSchemaForDeletes
- **First priority:** Retrieve the schema from the most recent commit
metadata (preserving existing logic)
```java
Option<Schema> tableCreateSchema =
metaClient.getTableConfig().getTableCreateSchema();
if (tableCreateSchema.isPresent()) {
LOG.warn("Schema not found in commit metadata, using table create
schema");
config.setSchema(tableCreateSchema.get().toString());
}
```
- **Second priority:** When the commit metadata does not contain a schema,
retrieve it from the CREATE_SCHEMA property of HoodieTableConfig.
```java
Option<Schema> tableCreateSchema =
metaClient.getTableConfig().getTableCreateSchema();
if (tableCreateSchema.isPresent()) {
LOG.warn("Schema not found in commit metadata, using table create
schema");
config.setSchema(tableCreateSchema.get().toString());
}
```
- **Third priority:** When there are no commit records (empty table), also
try using `table create schema`.
```java
} else {
Option<Schema> tableCreateSchema =
metaClient.getTableConfig().getTableCreateSchema();
if (tableCreateSchema.isPresent()) {
LOG.warn("No commit history found, using table create schema for
delete operation");
config.setSchema(tableCreateSchema.get().toString());
} else {
LOG.warn("None rows are deleted because the table is empty and no
schema available");
}
}
```
- **A more specific exception message:** When all options fail.
```java
throw new HoodieIOException("Latest commit does not have any schema in
commit metadata and table create schema is not available");
```
### Impact
<!-- Describe any public API or user-facing feature change or any
performance impact. -->
delete from table.
### Risk Level
<!-- Accepted values: none, low, medium or high. Other than `none`, explain
the risk.
If medium or high, explain what verification was done to mitigate the
risks. -->
### Documentation Update
<!-- Describe any necessary documentation update if there is any new
feature, config, or user-facing change. If not, put "none".
none
- The config description must be updated if new configs are added or the
default value of the configs are changed.
- Any new feature or user-facing change requires updating the Hudi website.
Please follow the
[instruction](https://hudi.apache.org/contribute/developer-setup#website)
to make changes to the website. -->
### Contributor's checklist
- [ ] Read through [contributor's
guide](https://hudi.apache.org/contribute/how-to-contribute)
- [ ] Enough context is provided in the sections above
- [ ] Adequate tests were added if applicable
--
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]