Skip to content

Instantly share code, notes, and snippets.

@den-crane
Last active April 11, 2019 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save den-crane/bc5256cb3f64ed3789819d40c11bda84 to your computer and use it in GitHub Desktop.
Save den-crane/bc5256cb3f64ed3789819d40c11bda84 to your computer and use it in GitHub Desktop.
# создаем таблицу заранее
CREATE TABLE kostya_test.view_result_table
date Date,
customer_id UInt32,
val AggregateFunction (sum, UInt32))
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/kostya_test.view_table',
'{replica}', date, (date, prom_customer_id, val), 8192);
CREATE MATERIALIZED VIEW kostya_test.view_table
TO kostya_test.view_result_table
AS SELECT date, customer_id, sumState(val) AS val
FROM test_db.log_41949_pageviews_product GROUP BY date, customer_id;
# создаем таблицу неявно
CREATE MATERIALIZED VIEW kostya_test.view_table
( date Date,
customer_id UInt32,
val AggregateFunction (sum, UInt32))
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/kostya_test.view_table',
'{replica}', date, (date, prom_customer_id, val), 8192)
AS SELECT date, customer_id, sumState(val) AS val
FROM test_db.log_41949_pageviews_product GROUP BY date, customer_id;
## добавляем поле NEWCOL
detach table kostya_test.view_table;
alter table kostya_test.`.inner.view_table` add column NEWCOL String;
ATTACH MATERIALIZED VIEW kostya_test.view_table
( date Date,
customer_id UInt32,
val AggregateFunction (sum, UInt32),
NEWCOL String)
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/kostya_test.view_table',
'{replica}', date, (date, prom_customer_id, val), 8192)
AS SELECT date, customer_id, sumState(val) AS val,NEWCOL
FROM test_db.log_41949_pageviews_product GROUP BY date, customer_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment