Skip to content

Fixes #37540: Doris materialized views, views and table DDL as Doris reports them - #37705

Merged
pmbrull merged 2 commits into
open-metadata:mainfrom
morningman:doris-table-types
Nov 16, 2026
Merged

pmbrull merged 2 commits into
open-metadata:mainfrom
morningman:doris-table-types

Conversation

@morningman

@morningman morningman commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #37540

The Doris connector listed a schema's tables from information_schema.tables and typed them with RELKIND_MAP, keyed on ENGINE:

  • Doris reports an async materialized view as a BASE TABLE whose ENGINE is NULL, so it was ingested as a regular table. SHOW CREATE TABLE refuses a materialized view, so it got no definition and no view lineage.
  • That listing includes the views, and the generic source lists them again from SHOW FULL TABLES, so every view was ingested twice, and includeViews: false did not exclude them.
  • With includeDDL, a table got the DDL SQLAlchemy rebuilds from reflection, without the key model, partitioning, distribution or properties: the PostgreSQL connector module installs that Inspector.get_table_ddl on SQLAlchemy's Inspector when imported, and the Doris module imports it indirectly. A materialized view got a CREATE TABLE of its columns.
  • The other RELKIND_MAP keys never match: Doris 4.1+ reports no OLAP or MEMORY engine, and external catalogs, which this connector does not read yet (Doris: ingest external catalogs (Hive, Iceberg, JDBC, …) as databases #37549), report iceberg in lower case.

This change:

  • Lists the base tables of a schema as the generic source does (SHOW FULL TABLES through pydoris), and the views only through the views listing. Both come from the same statement, split by Table_type, so each object is listed once and includeViews applies.
  • Reads the schema's materialized views once with SELECT Name FROM mv_infos('database' = :schema) and types them MaterializedView. mv_infos() exists on every supported Doris version and filters by the same table-level SHOW privilege as SHOW FULL TABLES, so an account sees the same objects in both. A failing mv_infos() read raises, like a failing table listing, rather than typing the materialized views as tables.
  • Reads a materialized view's definition with SHOW CREATE MATERIALIZED VIEW, and with includeDDL a table's DDL with SHOW CREATE TABLE. Both need only the SHOW privilege, which SELECT_PRIV grants. Views keep the generic path (SHOW CREATE TABLE, which needs SHOW_VIEW_PRIV). As in the generic source, a failed read leaves the definition unset.
  • Removes RELKIND_MAP with its test, and the Doris utils.py. Its get_table_names_and_type and get_view_definition had no caller. The get_table_comment it installed on the dialect returned a row where SQLAlchemy expects a string, so DorisSource.get_table_description unwrapped it with description[0], which raised a TypeError and dropped the table whenever the comment query failed. pydoris 1.2.0, the pinned version, implements get_table_comment with the same query, so the generic get_table_description applies.

The definition of a materialized view now reaches view lineage. Its BUILD ... REFRESH ..., key, distribution and PROPERTIES clauses 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 to CREATE VIEW name (columns) AS <query>, the same DDL parses with its column lineage. That, and the internal catalog prefix that keeps Doris view lineage from connecting today (#37544), are left to the view lineage work.

Part of #37537.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • A schema with tables, an async materialized view and a view: each is listed once, and the materialized view is typed MaterializedView.
  • includeViews: false lists no view.
  • A failing mv_infos() read raises instead of typing the materialized views as tables.
  • A materialized view gets the output of SHOW CREATE MATERIALIZED VIEW; with includeDDL, a table gets SHOW CREATE TABLE; without includeDDL, no statement runs; a view keeps its definition; a failed read leaves the definition unset.
  • A table comment is read through the pydoris dialect; a failed comment read keeps the table, without a description.

Unit tests

  • I added unit tests for the new/changed logic.
  • File added: 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 the SHOW FULL TABLES listings of the inspector); only the database connection and the inspector are replaced.
  • test_iceberg_relkind_mapping is removed from tests/unit/topology/database/test_doris.py with RELKIND_MAP.
  • On main, 6 of the 10 tests fail: views listed twice, views listed with includeViews: false, the materialized view typed Regular and without a definition, no mv_infos() read, the reflected DDL, and the TypeError on 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.
  • Coverage %: 55% on doris/metadata.py; every line and branch of the new code is covered, the uncovered lines predate this change.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. 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).

  2. Ran the Doris source's get_tables_name_and_type and yield_table against it with a mocked OpenMetadata client, before and after this change:

    Before After
    mv_region_amount (async MV) Regular, no definition MaterializedView, 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 definition MaterializedView with the same partition details, and their definitions
    mv_auto_empty (MV without partitions) Regular, no definition MaterializedView, with its definition
    v_user_summary, v_char ingested twice ingested once
    views with includeViews: false ingested not listed
    t_uniq with includeDDL: true CREATE 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_amount with includeDDL: true CREATE TABLE om_verify.mv_region_amount (region VARCHAR(10) NOT NULL, amount DECIMAL(38, 2)) its CREATE MATERIALIZED VIEW

    Nothing else in the output changed: the columns, constraints, partitions and descriptions of every table and view are the same.

  3. 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, one mv_infos() and one SHOW CREATE MATERIALIZED VIEW added, the 2 views no longer read twice; with includeDDL: true, 115 before (the reflection of the whole schema) and 74 after.

  4. An account with only SELECT_PRIV gets the same table types and the materialized view's definition; view definitions still need SHOW_VIEW_PRIV, as before.

  5. make py_format_check and make static-checks pass (0 errors, no new warnings). make py_format pruned the G004 baseline entry of the removed f-string log call, and the basedpyright baseline entry of the deleted utils.py is removed.

  6. 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.md and 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.

RetriggerView in GreptileConfidence 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.

  • Doris lists views once and recognizes materialized views.
  • Doris materialized views and tables now return their full definitions.

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

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.
@morningman
morningman requested a review from a team as a code owner November 12, 2026 23:36
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

Comment on lines +175 to +178
materialized_views = {
name
for (name,) in self.connection.execute(sql.text(DORIS_GET_MATERIALIZED_VIEW_NAMES), {"schema": schema_name})
}

@gitar-bot gitar-bot Bot Nov 12, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ 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 👍 / 👎

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@gitar-bot

gitar-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 🟡 Medium risk 0 closed / 1 findings

Changes Doris object discovery and DDL capture, so misclassification or query failures could omit or misrepresent ingested table metadata.

Types Doris async materialized views as MaterializedView, lists each object once through SHOW FULL TABLES and the views listing, and reads definitions with SHOW CREATE MATERIALIZED VIEW. Changes are requested because the unguarded mv_infos() read fails on Doris 1.2 and 2.0, which makes the connector drop every base table in the schema and soft-delete previously ingested tables when markDeletedTables is enabled. The fix is to treat a missing mv_infos function as an empty set while still raising on transient read errors.

⚠️ Bug: mv_infos() failure on Doris <2.1 drops every table in the schema

📄 ingestion/src/metadata/ingestion/source/database/doris/metadata.py:175-178 📄 ingestion/src/metadata/ingestion/source/database/doris/queries.py:24-28

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}
🤖 Prompt for agents
Code Review: Types Doris async materialized views as `MaterializedView`, lists each object once through `SHOW FULL TABLES` and the views listing, and reads definitions with `SHOW CREATE MATERIALIZED VIEW`. Changes are requested because the unguarded `mv_infos()` read fails on Doris 1.2 and 2.0, which makes the connector drop every base table in the schema and soft-delete previously ingested tables when `markDeletedTables` is enabled. The fix is to treat a missing `mv_infos` function as an empty set while still raising on transient read errors.

1. ⚠️ Bug: mv_infos() failure on Doris <2.1 drops every table in the schema
   Files: ingestion/src/metadata/ingestion/source/database/doris/metadata.py:175-178, ingestion/src/metadata/ingestion/source/database/doris/queries.py:24-28

   `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](https://doris.apache.org/docs/2.1/sql-manual/sql-functions/table-valued-functions/mv_infos/), and the [2.0 docs page](https://doris.apache.org/docs/2.0/sql-manual/sql-functions/table-valued-functions/mv_infos/) 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.

   Fix (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}

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@pmbrull

pmbrull commented Nov 16, 2026

Copy link
Copy Markdown
Member

decision about doris versions that are EOL makes sense to me, thanks for the contribution!

@pmbrull
pmbrull merged commit 7dd12d1 into open-metadata:main Nov 16, 2026
49 of 51 checks passed
Khairajani added a commit to morningman/OpenMetadata that referenced this pull request Nov 18, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doris: async materialized views are ingested as regular tables and views are listed twice

2 participants