Last active
April 11, 2019 12:06
-
-
Save den-crane/bc5256cb3f64ed3789819d40c11bda84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# создаем таблицу заранее | |
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