Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. # создаем таблицу заранее
  2.  
  3. CREATE TABLE kostya_test.view_result_table
  4. date Date,
  5. customer_id UInt32,
  6. val AggregateFunction (sum, UInt32))
  7. ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/kostya_test.view_table',
  8. '{replica}', date, (date, prom_customer_id, val), 8192);
  9.  
  10.  
  11. CREATE MATERIALIZED VIEW kostya_test.view_table
  12. TO kostya_test.view_result_table
  13. AS SELECT date, customer_id, sumState(val) AS val
  14. FROM test_db.log_41949_pageviews_product GROUP BY date, customer_id;
  15.  
  16.  
  17. # создаем таблицу неявно
  18.  
  19. CREATE MATERIALIZED VIEW kostya_test.view_table
  20. ( date Date,
  21. customer_id UInt32,
  22. val AggregateFunction (sum, UInt32))
  23. ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/kostya_test.view_table',
  24. '{replica}', date, (date, prom_customer_id, val), 8192)
  25. AS SELECT date, customer_id, sumState(val) AS val
  26. FROM test_db.log_41949_pageviews_product GROUP BY date, customer_id;
  27.  
  28.  
  29. ## добавляем поле NEWCOL
  30.  
  31. detach table kostya_test.view_table;
  32.  
  33. alter table kostya_test.`.inner.view_table` add column NEWCOL String;
  34.  
  35. ATTACH MATERIALIZED VIEW kostya_test.view_table
  36. ( date Date,
  37. customer_id UInt32,
  38. val AggregateFunction (sum, UInt32),
  39. NEWCOL String)
  40. ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/kostya_test.view_table',
  41. '{replica}', date, (date, prom_customer_id, val), 8192)
  42. AS SELECT date, customer_id, sumState(val) AS val,NEWCOL
  43. FROM test_db.log_41949_pageviews_product GROUP BY date, customer_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement