6
6
7
7
from .drivers .escaper import Escaper
8
8
9
+ escaper = Escaper ()
9
10
10
11
class Engine (SchemaEventTarget , Visitable ):
11
12
__visit_name__ = 'engine'
@@ -54,7 +55,7 @@ def get_expressions_or_columns(self):
54
55
55
56
class MergeTree (Engine ):
56
57
def __init__ (self , date_col , key_expressions , sampling = None ,
57
- index_granularity = None ):
58
+ index_granularity = None , replica_name = None , replica_table_path = None ):
58
59
self .date_col = TableCol (date_col )
59
60
self .key_cols = KeysExpressionOrColumn (* key_expressions )
60
61
@@ -66,6 +67,11 @@ def __init__(self, date_col, key_expressions, sampling=None,
66
67
if index_granularity is not None :
67
68
self .index_granularity = index_granularity
68
69
70
+ self .replica_name = replica_name
71
+ self .replica_table_path = replica_table_path
72
+ if replica_table_path and not replica_name or (not replica_table_path and replica_name ):
73
+ raise Exception ("Need both or no one [replica_path, replica_name]" )
74
+
69
75
super (MergeTree , self ).__init__ ()
70
76
71
77
def _set_parent (self , table ):
@@ -78,9 +84,11 @@ def _set_parent(self, table):
78
84
self .sampling ._set_parent (table )
79
85
80
86
def get_params (self ):
81
- params = [
82
- self .date_col .get_column ()
83
- ]
87
+ params = []
88
+ if self .replica_name :
89
+ params .extend (map (escaper .escape_string , [self .replica_table_path , self .replica_name ]))
90
+
91
+ params .append (self .date_col .get_column ())
84
92
85
93
if self .sampling :
86
94
params .append (self .sampling .get_expressions_or_columns ()[0 ])
@@ -89,6 +97,9 @@ def get_params(self):
89
97
params .append (self .index_granularity )
90
98
return params
91
99
100
+ def name (self ):
101
+ return ("Replicated" if self .replica_name else "" ) + self .__class__ .__name__
102
+
92
103
93
104
class CollapsingMergeTree (MergeTree ):
94
105
def __init__ (self , date_col , key_expressions , sign_col , sampling = None ,
@@ -178,4 +189,4 @@ def __init__(self, db, regexp):
178
189
self .regexp = regexp
179
190
180
191
def get_params (self ):
181
- return [self .db , Escaper () .escape_string (self .regexp )]
192
+ return [self .db , escaper .escape_string (self .regexp )]
0 commit comments