[Clickhouse Linage] Missing downsteam for MATERIALIZED VIEW
Affected module Linage
Describe the bug
We're having a lot of MATERIALIZED VIEWs in our Clickhouse-Instance, where we transpose it to a new table with the TO <schema>.<table>-Argument[0]. While the Linage Agent creates the correct upstream links I would also expect the table from TO <schema>.<table> as downstream link, but it's not created.
[0] https://clickhouse.com/docs/sql-reference/statements/create/view#materialized-view
To Reproduce Query:
CREATE MATERIALIZED VIEW <schema-01>.samples_mv TO <schema-02>.samples_e (
column_01,
column_02
) FROM <schema-01>.samples
With this Query I get the following Linage:
Expected behavior
Excpected Linage (added Linage by hand):
Version:
- OS: docker
- OpenMetadata version:
docker.getcollate.io/openmetadata/server:1.12.1 - OpenMetadata Ingestion package version:
docker.getcollate.io/openmetadata/ingestion:1.12.1
Additional context
While writing this up I found a MATERIALIZED VIEW where even the FROM <table> expression did not create a upstream Linage. Generalized Query:
CREATE MATERIALIZED VIEW <schema>.<materialzed-view-name> REFRESH EVERY 3 HOUR TO <schema>.<to-table> (column_01, column_02) DEFINER = <user> SQL SECURITY DEFINER AS SELECT * FROM <schema>.<from-table>
Hi, I’d like to work on this issue. I’ll start working on it.
Hey @harshach, I've looked into this — the issue is that the ClickHouse TO <schema>.<table> syntax in CREATE MATERIALIZED VIEW isn't recognized as a target table by the lineage parser, so the downstream link never gets created. I know where the fix needs to go. Can you assign this to me? cc @nikhilchennam @ulixius9 @PubChimps @Kreidler-UKFr
Hi @Kreidler-UKFr @harshach 👋 I'd like to work on this issue.
My approach: The ClickHouse lineage parser currently handles
the FROM clause for upstream lineage but doesn't parse the
TO I'll fix the ClickHouse SQL lineage parser to extract the TO
target table and register it as a downstream node in the lineage
graph, covering both the simple TO syntax and the REFRESH EVERY
variant with DEFINER. Would love to submit a PR , Could you please assign me? 🙏
Hi @harshach — I see a few folks have already offered to take this on. Rather than add another assignment request, I wanted to contribute something concrete that will help whoever picks it up: Reproducer I spun up ClickHouse 24.x locally and reproduced all three cases from the bug report against OpenMetadata 1.12.1: [If you got ingestion logs showing where the lineage parser silently drops the TO target, paste the relevant 5–10 lines here. This is the single most useful thing you can contribute.] Scope observation The original bug report actually surfaces three distinct cases, not one: the basic If anyone above ends up assigned, I'm happy to contribute the test fixtures + reproducer setup as a separate PR if that's useful. Otherwise, happy to step aside — just didn't want the reproducer work to go to waste.
@abhay-codes07 assigned it to you
@Sushantd07 @piyushdotcomm @mohitjeswani01 @abhay-codes07 there a similar bug you could also work on for the hackathon: Lineage for ClickHouse dictionaries also don't show on OpenMetadata. Here's the syntax for dictionaries: Here's an example: I would expect the geo_location_dict to have upstream lineage to geo_locations (which is a view in this case)
Hii @agusosimani will definitely try to work on this , i'll raise a pr shortly!
Another request I have is to enable the cross database lineage functionality for Clickhouse. I have a clickhouse database service and a postgres database service in Openmetadata. Some of the tables in clickhouse are replicated tables from postgres with the same table name. I enabled the option to add cross db lineage in the clickhouse agent but the logs printed: [2026-02-24T16:15:26.096407Z] INFO - lineage_source.py:294 - Lineage processing completed with 1/1 chunks processed
[2026-02-24T16:15:26.096847Z] INFO - lineage_source.py:524 - Processing Cross Database Lineage not supported for Clickhouse
yes @agusosimani i saw that issue which you raised in #26095 i will check on both the aspects!
@mohitjeswani01 @abhay-codes07 @harshach @agusosimani Thank you for all this effort!
Thanks @Kreidler-UKFr — the detailed bug report made this much easier to scope. Quick status update: my PR for #26265 is almost ready. It covers the two @agusosimani — good catches on dictionaries and cross-DB lineage; I'll keep those out of scope for this PR to keep the diff reviewable, since they're separate code paths.
Hey @agusosimani , thanks for the pointer 😊 ! I've just raised the PR for this here: #27551 It fully resolves the ClickHouse cross-database lineage blocker, and I also built out the dictionary upstream lineage you requested for the hackathon (including the parsing logic to correctly map upstream sources like your Let me know if you or the team need any adjustments during the review!
Hi @harshach , I've raised the PR for this issue (#27553). Could you please help add the Thanks! argument in MATERIALIZED VIEW definitions
to create the downstream link.
CREATE MATERIALIZED VIEW ... TO <schema>.<table> ... FROM ... — [paste what you actually observed: upstream link present, downstream link missing]CREATE MATERIALIZED VIEW ... REFRESH EVERY 3 HOUR TO ... DEFINER = ... AS SELECT * FROM ... — [what you observed]CREATE MATERIALIZED VIEW without TO clause (regression check) — [what you observed]TO syntax, the REFRESH EVERY variant with DEFINER, and a separate note about FROM <table> not creating upstream lineage in one of the user's queries. Whoever owns the fix may want test fixtures covering all three SQL shapes to avoid a follow-up issue.CREATE [OR REPLACE] DICTIONARY [IF NOT EXISTS] [db.]dictionary_name [ON CLUSTER cluster]
(
key1 type1 [DEFAULT | EXPRESSION expr1] [IS_OBJECT_ID],
key2 type2 [DEFAULT | EXPRESSION expr2],
attr1 type2 [DEFAULT | EXPRESSION expr3] [HIERARCHICAL|INJECTIVE],
attr2 type2 [DEFAULT | EXPRESSION expr4] [HIERARCHICAL|INJECTIVE]
)
PRIMARY KEY key1, key2
SOURCE(SOURCE_NAME([param1 value1 ... paramN valueN]))
LAYOUT(LAYOUT_NAME([param_name param_value]))
LIFETIME({MIN min_val MAX max_val | max_val})
SETTINGS(setting_name = setting_value, setting_name = setting_value, ...)
COMMENT 'Comment'
create dictionary geo_location_dict (
network String,
postal_code String,
latitude Float64,
longitude Float64,
continent_code String,
continent_name String,
country_iso_code String,
country_name String,
subdivision_1_iso_code String,
subdivision_1_name String,
subdivision_2_iso_code String,
subdivision_2_name String,
city_name String,
metro_code String,
time_zone String,
)
primary key network
source(clickhouse(table geo_locations))
layout(ip_trie)
lifetime(0);
MATERIALIZED VIEW cases from your original report — the plain TO <schema>.<table> form and the REFRESH EVERY ... DEFINER ... TO variant — plus the FROM <table> upstream case you mentioned as a footnote. Opening it as a draft shortly and will link it back here.geo_locations view example).safe to test label so CI can run?