Skip to content

Backport #31863 to 1.13: preserve table constraints and column custom properties on recursive CSV import - #32096

Closed
sonika-shah wants to merge 4 commits into
1.13from
backport/csv-recursive-31857-31858-1.13
Closed

sonika-shah wants to merge 4 commits into
1.13from
backport/csv-recursive-31857-31858-1.13

Conversation

@sonika-shah

@sonika-shah sonika-shah commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

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:

Fix

  • EntityCsv.createTableEntity now fetches the existing table with tableConstraints,tablePartition so a createOrUpdate on import carries them through instead of nulling them.
  • EntityRepository.removeExtensions (bulk-import path) now deletes only the entity's own customFieldSchema rows via a new batched, jsonSchema-scoped DAO delete (CollectionDAO.deleteByJsonSchemaBatch) instead of deleteAllBatch, which also removed columnExtension rows. One statement per chunk — no N+1.

Backport notes

Source files (EntityCsv, EntityRepository, CollectionDAO) cherry-picked cleanly. The only conflict was the DatabaseServiceResourceIT import block: main carries 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'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), and the test never stubbed that path — so under the mocked static Entity it returned an empty list, the rule saw no data products, and the import wrongly passed. 1.13's production logic is correct (Entity.getEntities returns the real data products); the fix only stubs the path the operator actually uses on 1.13. No production code changes.

Validation

  • openmetadata-service and openmetadata-integration-tests compile clean.
  • EntityCsvTest: 63/0 (was 63/1 before the test-only fix above).
  • Recursive round-trip ITs in 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.

  • Hydrates existing table constraints and partition data before create-or-update.
  • Restricts bulk extension cleanup to entity-level custom-property rows.
  • Adds recursive round-trip integration coverage and updates the 1.13-specific unit-test stub.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java Expands existing-table hydration so recursive imports carry constraints and partition metadata through updates.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java Adds a chunked, jsonSchema-scoped deletion operation for extension rows.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java Narrows bulk custom-property cleanup so column extension rows are retained.
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DatabaseServiceResourceIT.java Adds recursive CSV round-trip coverage for constraints and combined table and column custom properties.
openmetadata-service/src/test/java/org/openmetadata/csv/EntityCsvTest.java Updates recursive-import expectations and stubs the 1.13 data-product domain lookup path.

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]
Loading

Reviews (3): Last reviewed commit: "Merge branch '1.13' into backport/csv-re..." | Re-trigger Greptile

Context used:

…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.
@sonika-shah
sonika-shah requested a review from a team as a code owner August 26, 2026 10:51
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Aug 26, 2026
…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).
@gitar-bot

gitar-bot Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 closed / 1 findings

Backports 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 removeExtensions, storeCustomProperty, insertMany, and referenced in the DAO Javadoc, and "columnExtension" is likewise a raw literal. Per the project convention (a string used in more than one place must be a named constant), extract a shared constant (e.g. CUSTOM_FIELD_SCHEMA) and pass it to deleteByJsonSchemaBatch so the delete filter can never silently drift from the value used at insert time.

🤖 Prompt for agents
Code Review: Backports 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'.

1. 💡 Quality: Magic string "customFieldSchema" repeated instead of a constant
   Files: 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 `removeExtensions`, `storeCustomProperty`, `insertMany`, and referenced in the DAO Javadoc, and "columnExtension" is likewise a raw literal. Per the project convention (a string used in more than one place must be a named constant), extract a shared constant (e.g. `CUSTOM_FIELD_SCHEMA`) and pass it to `deleteByJsonSchemaBatch` so the delete filter can never silently drift from the value used at insert time.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch was previously deployed

1 inactive deployment
test — 6ab37925 Deployed Sep 1, 2026 by sonika-shah via playwright-ci-postgresql (5, 6) #76592
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant