Repository navigation
Fixes #37541: Doris primary keys follow the table model - #37618
Conversation
❌ 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 |
The Doris connector took the Key flag of SHOW FULL COLUMNS as the primary key. Doris sets that flag on the key columns of every table model, including the sort key of a DUPLICATE KEY table, and on every column of an external table. Read TABLE_MODEL and TABLE_MODEL_KEY from information_schema.table_options once per schema instead. UNIQUE KEY and AGGREGATE KEY tables get a primary key on their key columns, DUPLICATE KEY tables get none, and the columns of a composite key keep NULL / NOT NULL.
The table models were cached for 32 schemas, a size with no decision record behind it. Each of the `threads` workers ingests one schema at a time, so keep one entry per thread. Log the warning for an unreadable table_options with lazy %-style arguments: the suppression check of make py_format_check rejects a new logging f-string (G004).
e3286be to
1b4a1cb
Compare
A lost connection leaves the thread's connection refusing every statement until it is rolled back. When the table_options query lost it, the table's description and definition could not be read, and the schema's partition lookup failed and cached no partitions, so every table of the schema was ingested without partition details. Roll back the connection in that handler, as the partition lookups do.
|
hi @ayush-shah PTAL |
Match the table model key against complete leading column names in schema order. Cover single and composite keys with commas in their names.
Code Review ✅ Approved 🟡 Medium risk 3 closed / 3 findingsChanging Doris constraint ingestion to use table models could misstate catalog primary keys if model metadata is missing or parsed incorrectly. Doris primary keys now come from the table model in ✅ 3 closed✅ Edge Case: table_options query failure now drops every table in the schema
✅ Quality: Unrecorded cap: Doris primary-key cache holds 32 schemas
✅ Bug: table_options failure doesn't roll back; next tables fail
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 |
Describe your changes:
Fixes #37541
The Doris connector marked a column PRIMARY KEY when
SHOW FULL COLUMNSreportedKey=YES. Doris sets that flag on the key columns of every table model, including the sort key of a DUPLICATE KEY table, which can repeat, and on every column of an external table. So the first sort column of a DUPLICATE KEY table became a primary key, and a composite key lost both the table-level constraint and the NOT NULL of its columns.This change reads
TABLE_MODELandTABLE_MODEL_KEYfrominformation_schema.table_options, once per schema:SqlColumnHandlerMixinmakes for other connectors. An AGGREGATE KEY table merges the rows that share a key, so its key is unique as well.PRI) is treated the same way.table_optionscannot be read (for example a Doris version without it), a warning is logged and the schema's tables are ingested without primary keys instead of failing. The thread's connection is rolled back, as the partition lookups do, so a lost connection does not fail the statements that follow.threadsworkers ingests its own schema.TABLE_MODEL_KEYagainst the complete leading column names fromSHOW FULL COLUMNSin schema order. This preserves commas inside key column names.The query uses
DISTINCTbecause Doris master returns one row per partition intable_options(apache/doris#56122); released versions return one row per table.Part of #37537.
Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
(region, user_id)gets a table-level PRIMARY KEY, and its key columns stay NOT NULL.x,y, including when the table also has separatexandycolumns.PRI) model table gets a table-level PRIMARY KEY.table_optionsquery keeps the tables, without primary keys, and is not retried per table.table_optionsquery is rolled back, so the next table's statements still run.Unit tests
ingestion/tests/unit/source/database/doris/test_doris_constraints.pyDorisSource.get_columns_and_constraintswithSHOW FULL COLUMNSandinformation_schema.table_optionsresponse rows (only the database connection is replaced), for UNIQUE, AGGREGATE and DUPLICATE KEY tables;information_schema.table_optionsis queried once per schema, also with two threads;table_optionsquery falls back to no primary keys;test_doris_partitions.py:_get_columnsreturns the columns only (the partition code that calls it is updated the same way);test_doris_column_types.py: the IPV4/IPV6 test answered every statement withSHOW FULL COLUMNSrows, the newtable_optionsquery included; it now gets no row for that query.main, 8 of the original 10 tests fail. The lost-connection test passes onmain, which does not querytable_options. Without the rollback, it fails withPendingRollbackError.f05c77ba6a4and pass with the fix.pytest tests/unit/source/database/doris tests/unit/topology/database/test_doris.py: 129 passed.doris/metadata.py: 92%.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
TABLE_MODEL/TABLE_MODEL_KEYvalues, one row per table.yield_tableagainst it with a mocked OpenMetadata client, before and after this change:t_uniq (region, user_id),t_agg (dt, site)andt_types (k_date, k_id)had no constraint at all;t_uniqhas PRIMARY KEY(region, user_id)andt_aggPRIMARY KEY(dt, site); no DUPLICATE KEY table has a primary key; every key column is NOT NULL; nothing else in the output changed.SELECT_PRIVsees the sametable_optionsrows.make py_format_checkandmake static-checkspass (0 type errors).Known limitation: on Doris master, a table that has no partition yet (for example an empty AUTO PARTITION table) has no row in
table_options, so it gets no primary key until that is fixed on the Doris side. Released versions are not affected.UI screen recording:
Not applicable — ingestion-only bug fix with no UI change.
Checklist:
I have read the CONTRIBUTING document.
My PR title is
Fixes <issue-number>: <short explanation>My PR is linked to a GitHub issue via
Fixes #<issue-number>above.I have commented on my code, particularly in hard-to-understand areas.
For JSON Schema changes: I updated the migration scripts or explained why it is not needed. (N/A: no schema change)
For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable). (N/A: not a UI change)
I have added tests (unit / integration / Playwright as applicable) and listed them above.
Self-review: I reviewed the final diff against
REVIEW.mdand fixed every 🔴 finding, or answered it on the line below.Decision check: if this PR decides something the next contributor could undo, it adds a record under
docs/decisions/. (N/A: bug fix, no durable decision)I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.


Confidence Score: 5/5
The PR appears safe to merge; the previous disconnect issue is fixed.Summary
Doris primary keys now follow the table model instead of the
SHOW FULL COLUMNSkey flag.No new actionable issues found.
Reviews (2) · Last reviewed commit: "Roll back the Doris connection after a f..." · Reviewed by Greptile