Repository navigation
Backport #31863 + #32113 to 2.0: keep table constraints and FK edges on recursive CSV import - #37244
Conversation
…operties on recursive CSV import (#31863) * Fixes #31857: preserve table constraints on recursive CSV import createTableEntity fetched the existing table without tableConstraints/ tablePartition, so the subsequent createOrUpdate persisted them as null and the recursive CSV import silently dropped every table's PK/UNIQUE/FK. Load those fields so they carry through unchanged. Adds DatabaseServiceResourceIT.test_importExportRecursive_preservesTableConstraints. * test: cover FOREIGN_KEY (ER) in recursive CSV constraint round trip Adds a referenced table and a FOREIGN_KEY constraint (with referredColumns) so the recursive round trip also asserts the referenced-table linkage survives, not just PRIMARY_KEY/UNIQUE. * Fixes #31858: preserve column custom properties on recursive CSV import createTableEntity fetched the table with "extension" but not "columns"; TableRepository.setFields only hydrates column.extension when both fields are requested, so the recursive table-row createOrUpdate persisted columns with null extension and dropped column custom properties before the column rows patched back. Add "columns" to the fetch so column extension is hydrated and carried through. Adds DatabaseServiceResourceIT.test_importExportRecursive_preservesColumnCustomProperties. Verified: 3 recursive round-trip ITs pass (constraints+FK, column custom properties, and the pre-existing column tags/glossary test) — Tests run: 3, Failures: 0, Errors: 0. * test: update EntityCsvTest mock stub for new createTableEntity fetch fields createTableEntity now fetches tableConstraints,tablePartition,columns; the unit test stubbed getEntityWithDependencyResolution on the exact old field string, so the stub stopped matching and returned null -> NPE. Update the stub to the new field string. EntityCsvTest: Tests run: 65, Failures: 0. * Fixes #31858: preserve column custom properties via targeted removeExtensions The complete fix. The bulk import update path (updateManyEntitiesForImport) called removeExtensions(originals), which did a blanket entityExtensionDAO.deleteAllBatch(id) -- deleting EVERY entity_extension row for a table (including its columnExtension rows) whenever the entity carried table-level extension -- then re-stored only the table-level extension. So a recursive CSV import of a table that had BOTH table-level and column-level custom properties silently dropped the column custom properties. Make removeExtensions targeted, mirroring the single-entity removeExtension() (delete only the entity's own custom-property rows), so columnExtension rows are no longer collateral-deleted. Also revert the earlier createTableEntity 'columns' fetch addition (it only masked the column-only case; the real defect was the blanket delete above) -- the fetch keeps tableConstraints,tablePartition for #31857. Strengthen DatabaseServiceResourceIT.test_importExportRecursive_preservesColumnCustomProperties to define + set a table-level custom property alongside column-level ones, so the regression (which only manifests when both are present) can't false-green. Verified live on a 2.0 stack: recursive export->import at table/schema/database/ service now preserves table + column custom properties AND table constraints; EntityCsvTest 65/0; the 3 recursive ITs pass. * perf(csv-import): batch removeExtensions custom-property delete (avoid N+1) The prior fix looped removeExtension(entity) per entity, which fires one DELETE per custom-property field -- an N+1 for bulk imports of many entities. Restore a single batched delete but scope it to the entity's own custom-property rows via a new jsonSchema-filtered DAO batch: DELETE FROM entity_extension WHERE id IN (<ids>) AND jsonSchema = 'customFieldSchema' run one statement per chunk (updateInChunks). This keeps columnExtension (and version) rows untouched -- so column custom properties still survive a bulk import that updates table-level extension -- without the per-field N+1. Verified: EntityCsvTest 65/0; DatabaseServiceResourceIT recursive tests 0 fail (incl. table+column custom properties); ColumnCustomPropertiesIT 30/0. (cherry picked from commit 0a603cd)
The bulk relationship path was asymmetric for tables: clearEntitySpecificRelationshipsForMany deletes both the schema CONTAINS edge and the foreign-key RELATED_TO (ER) edge, but storeEntitySpecificRelationshipsForMany only re-added CONTAINS. So on a recursive CSV import (and bulk create), a table's FK relationship to its referenced table disappeared even though the tableConstraints JSON was preserved. The single-entity path is unaffected (storeEntity -> addConstraintRelationship), which is why non-recursive imports kept the edge. Fix: after the bulk CONTAINS insert, re-add the constraint RELATED_TO edges via addConstraintRelationship, mirroring the single-entity store path. Test: DatabaseServiceResourceIT#test_importExportRecursive_preservesTableConstraints now also asserts the RELATED_TO edge survives a recursive round trip (read from the DAO, not the eventually-consistent search endpoint). Verified before/after on a live stack: without the fix the edge is dropped, with the fix it survives. (cherry picked from commit 25880b2)
Addresses two review points on the initial fix: - N+1: the per-table addConstraintRelationship() did a getEntityReferenceByName lookup and a single addRelationship insert per foreign key. Replaced with buildConstraintRelationships(), which resolves all referred tables in one findByNames() query and folds the RELATED_TO edges into the caller's existing bulkInsertRelationships() call -- no per-FK query or insert. - Cross-chunk forward reference (greptile P1): addConstraintRelationship() resolved the referred table eagerly and threw EntityNotFoundException when the target was created later in another bulk chunk, failing the source table with BAD_REQUEST. The batched resolver skips a referred table that is not yet persisted instead of throwing, so a forward reference cannot fail the request. The edge is best-effort in the bulk path and is created whenever the target already exists -- always true for a recursive re-import of existing tables, the case that regressed. Duplicate edges are harmless (bulkInsertTo is INSERT IGNORE / ON CONFLICT DO NOTHING). Re-verified: recursive-import edge IT still GREEN, and live before/after confirms the FK edge survives a recursive import. (cherry picked from commit 4482fac)
Referred tables already in the batch (the common recursive-import case) are resolved from memory, so only out-of-batch targets hit findByNames. Also walks constraints once and dedupes composite-FK targets per table. (cherry picked from commit 23bf8e2)
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Code Review ✅ Approved🔴 High risk · Recursive CSV persistence now retains constraints and custom properties and rebuilds FK edges; unresolved targets could leave imported table relationships incomplete. Backports recursive CSV import fixes to 2.0 that keep table constraints and column custom properties and restore the foreign-key RELATED_TO edge between tables, with FK targets resolved from the import batch before querying. No issues found. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Summary
Backport to
2.0of two related recursive CSV import fixes (import at service / database / schema level):tableConstraintsand column custom properties on recursive import. Fixes CSV recursive import wipes table constraints (primary key / unique / foreign key) #31857, CSV import at schema/database/service level wipes column-level custom properties (column.extension) #31858.RELATED_TOrelationship edge on the same path, so the ER/graph link between tables survives the import.They ship together because #32113 rebuilds the FK edge from
tableConstraints; without #31863 the constraints are already dropped on 2.0 and there is nothing to rebuild from. The earlier 2.0 backport of #31863 (#32095) was auto-closed as stale and never merged.What changed
EntityCsv/EntityRepository/CollectionDAO: recursive import keeps existing table constraints and column custom properties (Fixes #31857, #31858: preserve table constraints and column custom properties on recursive CSV import #31863).TableRepository: the bulk relationship store re-adds FKRELATED_TOedges after theCONTAINSinsert; referred tables are resolved from the import batch first, and only the rest are looked up in one batched query (fix(csv): restore FK RELATED_TO edge on recursive/bulk import #32113).DatabaseServiceResourceIT#test_importExportRecursive_preservesTableConstraints: asserts both the constraints JSON and the FK edge survive a recursive round trip.Verification (on this branch)
mvn spotless:checkandmvn clean install -pl openmetadata-service,openmetadata-integration-tests -am -DskipTests: passEntityCsvTest: 68/68 passDatabaseServiceResourceIT#test_importExportRecursive_preservesTableConstraints(MySQL + Elasticsearch): 1/1 pass. Postgres lane left to CI.Backport details
Cherry-picked with
-x, all applied without conflicts:0a603cdd45b(Fixes #31857, #31858: preserve table constraints and column custom properties on recursive CSV import #31863 squash commit): diff stats identical to main (5 files, +277 / -4).25880b2e7c,4482fac6cd,23bf8e238fe(fix(csv): restore FK RELATED_TO edge on recursive/bulk import #32113 commits; the merge-main commits are not included).The resulting
TableRepositoryFK methods and the IT test are line-for-line identical to the #32113 head on main. If #32113 changes further during review, this PR will be updated to match.