Guest User

Untitled

a guest
Oct 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. create table z(a date, b Int64) Engine=MergeTree Partition by toYYYYMM(a) order by a;
  2. insert into z select today(), number from numbers(1000000000);
  3. insert into z select yesterday(), number from numbers(1000);
  4.  
  5. create table mv_z_store(a date, max_b AggregateFunction(MAX,Int64)) ENGINE = AggregatingMergeTree Partition by toYYYYMM(a) order by a;
  6. create table temp(a date, b Int64) Engine=Null;
  7. create MATERIALIZED VIEW mv_z to mv_z_store AS SELECT a, maxState(b) AS max_b FROM temp GROUP BY a;
  8. insert into temp select * from z;
  9. drop table mv_z;
  10. drop table temp;
  11. create MATERIALIZED VIEW mv_z to mv_z_store AS SELECT a, maxState(b) AS max_b FROM z GROUP BY a;
  12.  
  13. insert into z select yesterday()-1, number from numbers(100);
  14. select a, maxMerge(max_b) from mv_z group by a
  15. a maxMerge(max_b)
  16. 2018-08-07 99
  17. 2018-08-08 999
  18. 2018-08-09 999999999
Add Comment
Please, Sign In to add comment