-
Notifications
You must be signed in to change notification settings - Fork 3
/
7ea9419bdb87_add_mat_view.py
39 lines (31 loc) · 1.09 KB
/
7ea9419bdb87_add_mat_view.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Add mat view
Revision ID: 7ea9419bdb87
Revises: c0f4b9bc4e01
Create Date: 2022-05-11 23:52:07.919836
"""
from alembic import op
import clickhouse_sqlalchemy
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7ea9419bdb87'
down_revision = 'c0f4b9bc4e01'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_mat_view(
'grouped_statistics',
'SELECT statistics.date, sum(statistics.metric1 * statistics.sign) AS metric1 '
'FROM statistics '
'WHERE statistics.grouping > 42 GROUP BY statistics.date',
'SummingMergeTree()'
' PARTITION BY toYYYYMM(date)'
' ORDER BY date',
sa.Column('date', clickhouse_sqlalchemy.types.common.Date(), nullable=False),
sa.Column('metric1', clickhouse_sqlalchemy.types.common.Int32(), nullable=False)
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_mat_view('grouped_statistics')
# ### end Alembic commands ###