Skip to content

fix: mark Lance HMS tables as EXTERNAL to prevent data purge on DROP#142

Open
xingsuo-zbz wants to merge 1 commit into
lance-format:mainfrom
xingsuo-zbz:fix/hive2-hive3-external-true
Open

fix: mark Lance HMS tables as EXTERNAL to prevent data purge on DROP#142
xingsuo-zbz wants to merge 1 commit into
lance-format:mainfrom
xingsuo-zbz:fix/hive2-hive3-external-true

Conversation

@xingsuo-zbz

Copy link
Copy Markdown

Summary

  • Add parameters.EXTERNAL=TRUE in Hive2Util/Hive3Util createLanceTableParams
  • HMS's MetaStoreUtils.isExternalTable() reads parameters.EXTERNAL, not Table.tableType. Without this parameter, DROP TABLE (Hive CLI, Spark session catalog, HMS's own drop_table_core) treats the table as MANAGED and purges the Lance dataset at the storage location — even though tableType was already set to EXTERNAL_TABLE.
  • The docs already require Lance HMS tables to be EXTERNAL: https://lance.org/format/namespace/supported-catalogs/hive2/

Test plan

  • New testDeclareTableMarksTableAsExternal (hive2 + hive3) — asserts tableType=EXTERNAL_TABLE AND parameters.EXTERNAL=TRUE are both persisted in HMS after declareTable.
  • New testDropTablePreservesDataForDeclaredTable (hive2 + hive3) — declares a table with a data file at its location, drops it via raw HMS dropTable(deleteData=true) (the same call path used by Hive CLI / Spark DROP TABLE), asserts the data file survives.
  • Reverting the fix in either Hive2Util/Hive3Util causes the drop-preserves-data test to fail — the marker file gets purged.
  • mvn test -pl lance-namespace-hive2,lance-namespace-hive3 -am: 31 tests pass, 0 failures.

## Summary
- Add `parameters.EXTERNAL=TRUE` in `Hive2Util`/`Hive3Util`
  `createLanceTableParams`
- HMS's `MetaStoreUtils.isExternalTable()` reads `parameters.EXTERNAL`,
  not `Table.tableType`. Without this parameter, `DROP TABLE` (Hive
  CLI, Spark session catalog, HMS's own `drop_table_core`) treats
  the table as MANAGED and purges the Lance dataset at the storage
  location — even though `tableType` was already set to
  `EXTERNAL_TABLE`.
- The docs already require Lance HMS tables to be EXTERNAL:
  https://lance.org/format/namespace/supported-catalogs/hive2/

## Test plan
- New `testDeclareTableMarksTableAsExternal` (hive2 + hive3) —
  asserts `tableType=EXTERNAL_TABLE` AND `parameters.EXTERNAL=TRUE`
  are both persisted in HMS after `declareTable`.
- New `testDropTablePreservesDataForDeclaredTable` (hive2 + hive3) —
  declares a table with a data file at its location, drops it via
  raw HMS `dropTable(deleteData=true)` (the same call path used by
  Hive CLI / Spark `DROP TABLE`), asserts the data file survives.
- Reverting the fix in either `Hive2Util`/`Hive3Util` causes the
  drop-preserves-data test to fail — the marker file gets purged.
- `mvn test -pl lance-namespace-hive2,lance-namespace-hive3 -am`:
  31 tests pass, 0 failures.
@github-actions github-actions Bot added bug Something isn't working java labels Jul 1, 2026
@xingsuo-zbz

xingsuo-zbz commented Jul 1, 2026

Copy link
Copy Markdown
Author

Hi, @jackye1995 please take a look at this PR.
The table definition is described as external_table, but based on the actual table creation results and the definition that drop table can delete underlying data, it is more in line with managed_table. I am a bit confused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant