Repository navigation
Backport #31863 to 1.13: preserve table constraints and column custom properties on recursive CSV import - #32096
sonika-shah wants to merge 4 commits into
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.
❌ 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 |
…ProductFailsRule on 1.13 The test was backported to 1.13 (via #30013, backport of #28655) written against main's validateDataProductDomainMatch operator, which resolves a data product's domains through EntityRelationshipRepository. 1.13's operator still resolves them via Entity.getEntities(dataProducts, "domains", NON_DELETED). The test never stubbed that path, so under the mocked static Entity it returned an empty list and the rule saw no data products and wrongly passed -- the test has been red on 1.13 since #30013. 1.13's production logic is correct (Entity.getEntities returns the real data products); this only stubs the path the operator actually uses on 1.13 so the test exercises it. No production code changes. Full EntityCsvTest now 63/0 (was 63/1).
Code Review 👍 Approved with suggestions 0 closed / 1 findingsBackports recursive CSV import fixes to preserve table constraints and column custom properties along with a test fix. Consider defining a constant for the repeated magic string 'customFieldSchema'. 💡 Quality: Magic string "customFieldSchema" repeated instead of a constant📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java:5249 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java:1723-1734 The jsonSchema discriminator "customFieldSchema" is now hardcoded in 🤖 Prompt for agentsOptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Backport of #31863 to the 1.13 release branch.
Fixes #31857 and #31858 for 1.13.
What
Recursive CSV import (
?recursive=true, the path the UI Manage → Import uses at schema/database/service level) silently dropped two things on tables:FOREIGN_KEY(ER) relationships, were wiped.column.extension) were wiped whenever the table also carried table-level custom properties.Fix
EntityCsv.createTableEntitynow fetches the existing table withtableConstraints,tablePartitionso acreateOrUpdateon import carries them through instead of nulling them.EntityRepository.removeExtensions(bulk-import path) now deletes only the entity's owncustomFieldSchemarows via a new batched, jsonSchema-scoped DAO delete (CollectionDAO.deleteByJsonSchemaBatch) instead ofdeleteAllBatch, which also removedcolumnExtensionrows. One statement per chunk — no N+1.Backport notes
Source files (
EntityCsv,EntityRepository,CollectionDAO) cherry-picked cleanly. The only conflict was theDatabaseServiceResourceITimport block:maincarries unrelated ingestion-pipeline imports that 1.13 does not have. Resolved by keeping only the imports the new tests actually use (Type,CustomProperty) and dropping the unrelated ingestion imports.Extra commit: green a pre-existing red test on 1.13
This branch also includes a small test-only fix for
EntityCsvTest#test_bulkEditInheritedDomainWithMismatchedDataProductFailsRule, which has been failing on 1.13 since #30013 (the backport of #28655) — unrelated to CSV, surfaced while validating this PR.Root cause: that test was written against
main'svalidateDataProductDomainMatchoperator, which resolves a data product's domains throughEntityRelationshipRepository. 1.13's operator still resolves them viaEntity.getEntities(dataProducts, "domains", NON_DELETED), and the test never stubbed that path — so under the mocked staticEntityit returned an empty list, the rule saw no data products, and the import wrongly passed. 1.13's production logic is correct (Entity.getEntitiesreturns the real data products); the fix only stubs the path the operator actually uses on 1.13. No production code changes.Validation
openmetadata-serviceandopenmetadata-integration-testscompile clean.EntityCsvTest: 63/0 (was 63/1 before the test-only fix above).DatabaseServiceResourceIT(PK+UNIQUE+FK constraints; table+column custom properties together) included.Greptile Summary
This backport preserves table constraints, table partition metadata, and column custom properties during recursive CSV imports.
Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Recursive CSV import] --> B[Load existing table] B --> C[Hydrate constraints and partition] C --> D[Create or update table] D --> E[Delete entity customFieldSchema rows] E --> F[Preserve columnExtension rows] F --> G[Store imported entity extensions]Reviews (3): Last reviewed commit: "Merge branch '1.13' into backport/csv-re..." | Re-trigger Greptile
Context used: