hudi-agent commented on code in PR #18595:
URL: https://github.com/apache/hudi/pull/18595#discussion_r3143142452
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java:
##########
@@ -1337,10 +1337,22 @@ protected void
setWriteSchemaForDeletes(HoodieTableMetaClient metaClient) {
if (!StringUtils.isNullOrEmpty(extraSchema)) {
config.setSchema(commitMetadata.getExtraMetadata().get(SCHEMA_KEY));
} else {
- throw new HoodieIOException("Latest commit does not have any schema
in commit metadata");
+ Option<Schema> tableCreateSchema =
metaClient.getTableConfig().getTableCreateSchema();
Review Comment:
🤖 Heads up — master already replaced this method via PR #18030 (commit
21eb05e) to call `TableSchemaResolver.getTableSchemaIfPresent(false)`, which
walks back through commits to find one with a valid schema and then falls back
to `tableCreateSchema` (and even to a data-file schema). That should already
cover the second-delete-on-empty-table scenario from #18330. Could you rebase
on master and verify whether this fix is still needed? If not, the PR can
probably be closed; if it is, it might be worth driving it through
`TableSchemaResolver` so all schema-resolution paths benefit. @yihua could you
weigh in on whether the existing `TableSchemaResolver` flow already resolves
#18330?
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/TestDeleteFromTable.scala:
##########
@@ -82,4 +82,30 @@ class TestDeleteFromTable extends HoodieSparkSqlTestBase {
}
})
}
+ test("Test deleting from twice on empty table") {
Review Comment:
🤖 nit: "Test deleting from twice on empty table" reads a bit awkwardly —
something like `"Test delete from empty table twice"` or `"Test repeated delete
from empty table"` would be clearer about what the test is verifying.
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java:
##########
@@ -1337,10 +1337,22 @@ protected void
setWriteSchemaForDeletes(HoodieTableMetaClient metaClient) {
if (!StringUtils.isNullOrEmpty(extraSchema)) {
config.setSchema(commitMetadata.getExtraMetadata().get(SCHEMA_KEY));
} else {
- throw new HoodieIOException("Latest commit does not have any schema
in commit metadata");
+ 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());
+ } else {
+ throw new HoodieIOException("Latest commit does not have any
schema in commit metadata and table create schema is not available");
+ }
}
} else {
Review Comment:
🤖 nit: the `tableCreateSchema` lookup + `config.setSchema(...)` pattern is
nearly identical to lines 1340–1346 above — could you extract a small helper
like `applyTableCreateSchemaIfAvailable(metaClient, config)` and call it in
both branches? That way a future change to this fallback logic only needs to
happen in one place.
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/BaseHoodieWriteClient.java:
##########
@@ -1337,10 +1337,22 @@ protected void
setWriteSchemaForDeletes(HoodieTableMetaClient metaClient) {
if (!StringUtils.isNullOrEmpty(extraSchema)) {
config.setSchema(commitMetadata.getExtraMetadata().get(SCHEMA_KEY));
} else {
- throw new HoodieIOException("Latest commit does not have any schema
in commit metadata");
+ Option<Schema> tableCreateSchema =
metaClient.getTableConfig().getTableCreateSchema();
+ if (tableCreateSchema.isPresent()) {
+ LOG.warn("Schema not found in commit metadata, using table create
schema");
Review Comment:
🤖 Could `tableCreateSchema` be stale here? If the table has gone through
schema evolution but the most recent instant happens to be one without
`SCHEMA_KEY` in extraMetadata (e.g. a clustering/replace commit, or an empty
commit from a prior delete), we'd silently fall back to the original
create-time schema and use it for the delete write. Walking earlier commits to
find the most recent schema-bearing commit (as
`TableSchemaResolver.getLatestCommitMetadataWithValidSchema` does) seems safer
than always jumping straight to create schema.
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
--
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]