Skip to content

Fixes #31857, #31858: preserve table constraints and column custom properties on recursive CSV import - #31863

Merged
sonika-shah merged 8 commits into
mainfrom
fix/csv-recursive-constraints-31857
Aug 26, 2026
Merged

sonika-shah merged 8 commits into
mainfrom
fix/csv-recursive-constraints-31857

Conversation

@sonika-shah

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

Copy link
Copy Markdown
Collaborator

Fixes #31857

Problem

A recursive CSV import of a Database Service / Database / Database Schema silently loses metadata on tables it touches — even though none of it is represented in the CSV:

  1. Table constraints — PRIMARY KEY, UNIQUE, and FOREIGN KEY (incl. the referenced-table linkage). Fixes CSV recursive import wipes table constraints (primary key / unique / foreign key) #31857.
  2. Column-level custom properties (column.extension) — when the table also carries table-level custom properties (the realistic governance scenario). Fixes CSV import at schema/database/service level wipes column-level custom properties (column.extension) #31858.

Both are user-reachable from the UI: Manage (⋮) → Export/Import on a Service / Database / Schema page issues importAsync?...&recursive=true. Reproduced on 1.12.14 and on current main / 2.0, and verified fixed on a locally-built 2.0 stack.

Root causes & fixes

#31857 — constraints. EntityCsv.createTableEntity fetched the existing table without tableConstraints/tablePartition, so the subsequent createOrUpdate persisted them as null and the recursive import dropped them. Fix: include tableConstraints,tablePartition in that fetch so they carry through unchanged. (The recursive table update uses the single-entity constraint diff in TableUpdater, so an unchanged constraint set also leaves the FK RELATED_TO edge intact — see the FK test.)

#31858 — column custom properties. The bulk import update path updateManyEntitiesForImport called removeExtensions(originals), which did a blanket entityExtensionDAO.deleteAllBatch(id) — deleting every entity_extension row for the table, including its columnExtension rows — whenever the entity carried table-level extension, then re-stored only the table-level extension. So a table with both table- and column-level custom properties lost the column ones on recursive import. Fix: make removeExtensions targeted (mirror the single-entity removeExtension, deleting only the entity's own custom-property rows) so columnExtension rows are not collateral-deleted.

Tests (DatabaseServiceResourceIT)

  • test_importExportRecursive_preservesTableConstraints — service → database → schema → a referenced table + a constrained table with PRIMARY_KEY, UNIQUE and a FOREIGN_KEY (with referredColumns); recursive export → re-import; asserts all three survive incl. the FK linkage.
  • test_importExportRecursive_preservesColumnCustomProperties — a table carrying both a table-level custom property and column-level custom properties; asserts both survive the recursive round trip (this combination is the CSV import at schema/database/service level wipes column-level custom properties (column.extension) #31858 trigger; testing them separately false-greens).
  • Regression guard: the pre-existing test_importExportRecursive_withColumnTagsAndGlossaryTerms still passes.

EntityCsvTest 65/0; the three recursive ITs pass; and a live 2.0 stack confirms table + column custom properties and table constraints all survive export→re-import at table/schema/database/service levels.

Out of scope (not a normal scenario): a Tier tag applied directly to a column is dropped on a table-level import — Tier is an asset/table-level concept and is not normally placed on columns.

Greptile Summary

The PR preserves table constraints, table partitions, and column custom-property rows during recursive CSV import.

  • Requests tableConstraints and tablePartition when resolving existing tables.
  • Narrows batch extension deletion to customFieldSchema rows.
  • Adds recursive round-trip coverage for constraints and custom properties.

Confidence Score: 4/5

The PR is not yet safe to merge because recursive batch import still removes the relationship edge backing a preserved FOREIGN_KEY constraint.

The earlier reply from sonika-shah states that the recursive path uses the diff-based single-entity updater, but the current path queues the table for updateManyEntitiesForImport; that batch path deletes table-to-table RELATED_TO edges and restores only containment, so the constraint JSON survives while relationship-based consumers lose the foreign-key linkage.

Files Needing Attention: openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java, openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java, openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java Extends existing-table resolution so recursive imports carry forward constraints and partition metadata.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java Adds a bound, chunked DAO operation for deleting extension rows by JSON schema.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java Uses targeted deletion for entity-level custom properties instead of deleting every extension row.
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DatabaseServiceResourceIT.java Adds recursive import/export tests for constraint payloads and table-plus-column custom properties.
openmetadata-service/src/test/java/org/openmetadata/csv/EntityCsvTest.java Updates the dependency-resolution expectation for the additional preserved table fields.

Reviews (8): Last reviewed commit: "perf(csv-import): batch removeExtensions..." | Re-trigger Greptile

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.
@sonika-shah
sonika-shah requested a review from a team as a code owner August 21, 2026 06:52
Copilot AI lite review requested due to automatic review settings August 21, 2026 06:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Aug 21, 2026
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.
Copilot AI review requested due to automatic review settings August 21, 2026 07:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

The Java checkstyle failed.

Please run mvn spotless:apply in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Java code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

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.
Copilot AI review requested due to automatic review settings August 21, 2026 07:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonika-shah sonika-shah changed the title Fixes #31857: preserve table constraints on recursive CSV import Fixes #31857, #31858: preserve table constraints and column custom properties on recursive CSV import Aug 21, 2026
@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit dc9029b22d05359171f8ea2d2f7b92e214aada53 in Playwright run 32934914705, attempt 1.

✅ 553 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 51m 9s

⏱️ Max setup 4m 14s · max shard execution 17m 6s · max shard-job elapsed before upload 20m 30s · reporting 4s

🌐 213.22 requests/attempt · 2.83 app boots/UI scenario · 4.29% common-shard skew

Optimization targets still in progress:

  • Browser traffic was 213.22 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.83 per UI scenario (1622 boots / 574 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 133 0 0 0 0 0
✅ Shard chromium-02 140 0 0 0 0 0
✅ Shard chromium-03 126 0 0 0 0 0
✅ Shard data-asset-rules-01 61 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard ingestion-01 1 0 0 0 0 0
✅ Shard reindex-01 2 0 0 0 0 0
✅ Shard search-01 11 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

…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.
Copilot AI review requested due to automatic review settings August 26, 2026 05:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonika-shah sonika-shah added the To release Will cherry-pick this PR into the release branch label Aug 26, 2026
yan-3005
yan-3005 previously approved these changes Aug 26, 2026
…d 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.
Copilot AI review requested due to automatic review settings August 26, 2026 05:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Preserves table constraints and column custom properties during recursive CSV imports by including table fields in lookups and targeting entity-level extension cleanup. All new regression tests pass.

✅ 2 resolved
✅ Performance: removeExtensions replaces one batched delete with per-field deletes

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java:5780-5792
The old path issued a single chunked deleteAllBatch(ids); the new loop calls removeExtension(entity) for each original, and removeExtension issues one entityExtensionDAO().delete per custom-property field. For a bulk import chunk where many entities carry table-level extension this becomes N*M individual DELETE round trips inside the transaction, lengthening the InnoDB lock-hold window. The correctness fix is right (deleteAllBatch wiped columnExtension rows too), but consider a targeted batch delete keyed by id + jsonSchema='customFieldSchema' so column extension rows are preserved while table-level rows are removed in one batched statement. Note the impact is bounded because removeExtension early-returns when getExtension()==null.

✅ Quality: FK test asserts JSON only, not the RELATED_TO edge

📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DatabaseServiceResourceIT.java:814 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DatabaseServiceResourceIT.java:888-898 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DatabaseServiceResourceIT.java:871-885
The comment at line 814 states this table exercises "the table-to-table RELATED_TO edge path," but the assertions (lines 894-898) only verify the FOREIGN_KEY constraint's referredColumns JSON survives — they never confirm the actual table-to-table relationship edge is recreated after a recursive import. Per the PR discussion, recursive batch updates can delete the RELATED_TO edge without recreating it, so this test could pass while the relationship remains broken. Consider asserting the relationship edge exists (e.g. fetch the referenced table and check its inbound/related relationships, or query the relationships field) so the test matches its stated intent.

Options

Display: compact → Showing less information.

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

@sonika-shah
sonika-shah added this pull request to the merge queue Aug 26, 2026
Merged via the queue into main with commit 0a603cd Aug 26, 2026
113 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Failed to cherry-pick changes to the 2.0 branch.
Please cherry-pick the changes manually.
You can find more details here.

@github-actions

Copy link
Copy Markdown
Contributor

Failed to cherry-pick changes to the 1.13 branch.
Please cherry-pick the changes manually.
You can find more details here.

This branch was previously deployed

1 inactive deployment
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 To release Will cherry-pick this PR into the release branch

Projects

None yet

4 participants