Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to create non-clustered materialized views and clustered tables #336

Open
aaronli94 opened this issue Aug 14, 2024 · 0 comments

Comments

@aaronli94
Copy link

aaronli94 commented Aug 14, 2024

I use the following code to create a materialized view to write to a table with ReplicatedReplacingMergeTree engine:

{{ config(
       materialized="materialized_view",
       engine="ReplicatedReplacingMergeTree('/clickhouse/tables/kafka/mysql_test_users/{uuid}','{replica}',_ts_ms,_deleted)",
       order_by="(id)"
) }}

SELECT
    JSONExtractString(_key, 'id') AS id,
    if(op = 'd',JSONExtractString(before,'name'),JSONExtractString(after,'name')) AS name,
	toInt32(if(op = 'd',JSONExtractString(before,'age'),JSONExtractString(after,'age'))) AS age,
	if(op = 'd',toDateTime64(JSONExtractString(before,'created_at'),3),
	    toDateTime64(JSONExtractString(after,'created_at'),3)) AS created_at,
	if(op = 'd',toDateTime64(JSONExtractString(before,'updated_at'),3),
	    toDateTime64(JSONExtractString(after,'updated_at'),3)) AS updated_at,
	if(op = 'd',1,0) as _deleted,
    ts_ms as _ts_ms
FROM
    {{ source('kafka', 'mysql_test_users_json') }}

This will be compiled into a view creation query with on cluster clause, however, I do not want to create a view in the cluster, but the engine of the target table needs on cluster clause, is there any way to create non-clustered materialized views and clustered tables?

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

No branches or pull requests

1 participant