Repository navigation
Fixes #37540: Doris materialized views, views and table DDL as Doris reports them - #37705
Conversation
The Doris connector typed tables by their ENGINE in information_schema.tables, where an async materialized view is a BASE TABLE with a NULL engine, so materialized views were ingested as regular tables without a definition. That listing also includes the views, which the generic source lists again, so every view was ingested twice and includeViews: false did not exclude them. With includeDDL, tables got the DDL that SQLAlchemy rebuilds from reflection. List the base tables as the generic source does and the views only through the views listing, both from SHOW FULL TABLES. Read the schema's materialized views with mv_infos() and their definitions with SHOW CREATE MATERIALIZED VIEW; with includeDDL, read a table's DDL with SHOW CREATE TABLE. Remove RELKIND_MAP, whose keys never match on Doris 4.1+, and the Doris utils module: two functions without callers, and a get_table_comment that pydoris already implements, whose row result made get_table_description drop the table when the comment query failed.
❌ 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 |
| materialized_views = { | ||
| name | ||
| for (name,) in self.connection.execute(sql.text(DORIS_GET_MATERIALIZED_VIEW_NAMES), {"schema": schema_name}) | ||
| } |
There was a problem hiding this comment.
⚠️ Bug: mv_infos() failure on Doris <2.1 drops every table in the schema
query_table_names_and_types now runs SELECT Name FROM mv_infos(...) before it lists tables, with no guard. The mv_infos TVF is first documented in Doris 2.1, and the 2.0 docs page returns 404. On Doris 1.2 or 2.0 the query therefore fails every time. In CommonDbSourceService.get_tables_name_and_type that exception is caught and table_iter = [], so no base table gets ingested in any schema. With markDeletedTables on, every table that was ingested before is soft-deleted. Before this PR these versions worked through the information_schema.tables listing. Raising instead of falling back is a deliberate choice for real read failures. A server that simply lacks the function, though, has no async materialized views, so it is safe to treat that case as an empty set. The fix is to catch the unknown-function error (or check the Doris version) and use an empty set, while still raising for transient errors.
Treat a missing mv_infos function (pre-2.1 Doris, which has no async MVs) as no materialized views, but still raise on other failures:
try:
rows = self.connection.execute(sql.text(DORIS_GET_MATERIALIZED_VIEW_NAMES), {"schema": schema_name})
except ProgrammingError as exc:
if "mv_infos" not in str(exc).lower():
raise
# Doris before 2.1 has no async materialized views nor mv_infos()
rows = []
materialized_views = {name for (name,) in rows}
Was this helpful? React with 👍 / 👎
There was a problem hiding this comment.
Leaving this as is on purpose. The Doris work under #37537 supports Doris 4.1 and later (#37538 puts that on the docs page), and mv_infos() has been there since 2.1, the release that added async materialized views. 1.2 and 2.0 are outside that range, so I'd rather not add a branch keyed on their error text that no test or supported server exercises.
On a supported version the read doesn't fail for an account with partial grants. mv_infos() skips the materialized views the account can't SHOW, the same table-level check SHOW FULL TABLES applies (MetadataGenerator.mtmvMetadataResult in Doris). Apart from transient errors, it only fails when the database is gone.
The soft-delete path isn't specific to this query either. CommonDbSourceService.get_tables_name_and_type turns any exception from query_table_names_and_types into an empty list, so a failed SHOW FULL TABLES has the same effect today. If a failed listing should keep markDeletedTables from deleting, that check belongs in the generic source.
There was a problem hiding this comment.
Gitar can change code and merge on your behalf, so it only acts on requests from people who can push. This needs Write access to this repository.
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
|
decision about doris versions that are EOL makes sense to me, thanks for the contribution! |
Resolve the Doris connector conflicts with open-metadata#37705 and open-metadata#37706: read the DDL through _get_create_statement, and keep a failing per-table partition lookup from dropping the table (it returns no partition details instead).
Describe your changes:
Fixes #37540
The Doris connector listed a schema's tables from
information_schema.tablesand typed them withRELKIND_MAP, keyed onENGINE:BASE TABLEwhoseENGINEis NULL, so it was ingested as a regular table.SHOW CREATE TABLErefuses a materialized view, so it got no definition and no view lineage.SHOW FULL TABLES, so every view was ingested twice, andincludeViews: falsedid not exclude them.includeDDL, a table got the DDL SQLAlchemy rebuilds from reflection, without the key model, partitioning, distribution or properties: the PostgreSQL connector module installs thatInspector.get_table_ddlon SQLAlchemy'sInspectorwhen imported, and the Doris module imports it indirectly. A materialized view got aCREATE TABLEof its columns.RELKIND_MAPkeys never match: Doris 4.1+ reports noOLAPorMEMORYengine, and external catalogs, which this connector does not read yet (Doris: ingest external catalogs (Hive, Iceberg, JDBC, …) as databases #37549), reporticebergin lower case.This change:
SHOW FULL TABLESthrough pydoris), and the views only through the views listing. Both come from the same statement, split byTable_type, so each object is listed once andincludeViewsapplies.SELECT Name FROM mv_infos('database' = :schema)and types themMaterializedView.mv_infos()exists on every supported Doris version and filters by the same table-level SHOW privilege asSHOW FULL TABLES, so an account sees the same objects in both. A failingmv_infos()read raises, like a failing table listing, rather than typing the materialized views as tables.SHOW CREATE MATERIALIZED VIEW, and withincludeDDLa table's DDL withSHOW CREATE TABLE. Both need only the SHOW privilege, whichSELECT_PRIVgrants. Views keep the generic path (SHOW CREATE TABLE, which needsSHOW_VIEW_PRIV). As in the generic source, a failed read leaves the definition unset.RELKIND_MAPwith its test, and the Dorisutils.py. Itsget_table_names_and_typeandget_view_definitionhad no caller. Theget_table_commentit installed on the dialect returned a row where SQLAlchemy expects a string, soDorisSource.get_table_descriptionunwrapped it withdescription[0], which raised aTypeErrorand dropped the table whenever the comment query failed. pydoris 1.2.0, the pinned version, implementsget_table_commentwith the same query, so the genericget_table_descriptionapplies.The definition of a materialized view now reaches view lineage. Its
BUILD ... REFRESH ..., key, distribution andPROPERTIESclauses parse with neither sqlglot nor sqlfluff, so the parser falls back to sqlparse, which finds the source and target tables but not the column-level lineage; reduced toCREATE VIEW name (columns) AS <query>, the same DDL parses with its column lineage. That, and theinternalcatalog prefix that keeps Doris view lineage from connecting today (#37544), are left to the view lineage work.Part of #37537.
Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
MaterializedView.includeViews: falselists no view.mv_infos()read raises instead of typing the materialized views as tables.SHOW CREATE MATERIALIZED VIEW; withincludeDDL, a table getsSHOW CREATE TABLE; withoutincludeDDL, no statement runs; a view keeps its definition; a failed read leaves the definition unset.Unit tests
ingestion/tests/unit/source/database/doris/test_doris_table_types.py. The connector's statements are answered with the rows Doris master returns (mv_infos(),SHOW CREATE TABLE,SHOW CREATE MATERIALIZED VIEW, and theSHOW FULL TABLESlistings of the inspector); only the database connection and the inspector are replaced.test_iceberg_relkind_mappingis removed fromtests/unit/topology/database/test_doris.pywithRELKIND_MAP.main, 6 of the 10 tests fail: views listed twice, views listed withincludeViews: false, the materialized view typedRegularand without a definition, nomv_infos()read, the reflected DDL, and theTypeErroron a failed comment read. The other 4 pin behavior this change keeps.make unit_ingestion ARGS="-n 0 tests/unit/source/database/doris tests/unit/topology/database/test_doris.py": 33 passed.doris/metadata.py; every line and branch of the new code is covered, the uncovered lines predate this change.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
Started a local Apache Doris master build with test databases: DUPLICATE, UNIQUE and AGGREGATE tables, a table named
order, two views and an async materialized view (om_verify), and four async materialized views, partitioned or not (om_probe).Ran the Doris source's
get_tables_name_and_typeandyield_tableagainst it with a mocked OpenMetadata client, before and after this change:mv_region_amount(async MV)Regular, no definitionMaterializedView,CREATE MATERIALIZED VIEW mv_region_amount (region,amount) BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL DUPLICATE KEY(region) ...mv_dyn,mv_month,mv_range_int(RANGE-partitioned MVs)Partitioned, no definitionMaterializedViewwith the same partition details, and their definitionsmv_auto_empty(MV without partitions)Regular, no definitionMaterializedView, with its definitionv_user_summary,v_charincludeViews: falset_uniqwithincludeDDL: trueCREATE TABLE om_verify.t_uniq (region VARCHAR(10) NOT NULL, user_id INTEGER NOT NULL, ...)CREATE TABLE `t_uniq` (...) ENGINE=OLAP UNIQUE KEY(`region`, `user_id`) COMMENT 'unique key table' PARTITION BY LIST (`region`) (...) DISTRIBUTED BY HASH(`user_id`) BUCKETS 1 PROPERTIES (...);mv_region_amountwithincludeDDL: trueCREATE TABLE om_verify.mv_region_amount (region VARCHAR(10) NOT NULL, amount DECIMAL(38, 2))CREATE MATERIALIZED VIEWNothing else in the output changed: the columns, constraints, partitions and descriptions of every table and view are the same.
Doris's audit log for the same runs, schema
om_verify(8 tables, 2 views, 1 materialized view): with the default config, 70 statements before and 66 after, onemv_infos()and oneSHOW CREATE MATERIALIZED VIEWadded, the 2 views no longer read twice; withincludeDDL: true, 115 before (the reflection of the whole schema) and 74 after.An account with only
SELECT_PRIVgets the same table types and the materialized view's definition; view definitions still needSHOW_VIEW_PRIV, as before.make py_format_checkandmake static-checkspass (0 errors, no new warnings).make py_formatpruned the G004 baseline entry of the removed f-string log call, and the basedpyright baseline entry of the deletedutils.pyis removed.Repeated steps 2 to 4 on Doris 4.1.3 (
apache/doris:all-in-one-4.1.3): every table and view gets the same type, definition and DDL as on master, before and after this change, and each kind of statement is sent the same number of times. The only difference in the output is that 4.1.3 prints the column lists of views and materialized views without backquotes.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)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 based on code inspection.Summary
The Doris connector now identifies async materialized views and reads their definitions directly from Doris, while listing ordinary views only once.
No actionable issues found. Tests were not run during this review.
Reviews (3) · Last reviewed commit: "Merge branch 'main' into doris-table-typ..." · Reviewed by Greptile