@@ -1111,55 +1111,34 @@ def column_for_split(self, split_cell, label=None):
11111111
11121112 return split_column .label (label )
11131113
1114- # namnd added
1115- def clause_for_having (self , cell ):
1116- """Returns a clause for having clause and attr for group . If cell is empty, not contain having or cell is
1114+ # madman: get having clause and attributes
1115+ def colums_and_having_cut_for_cell (self , cell ):
1116+ """Returns attributes and having clause. If cell is empty, not contain having or cell is
11171117 `None` then returns `None`."""
11181118
11191119 if not cell :
11201120 return None
11211121
1122- clauses = self .clauses_for_having (cell .having_clauses )
1123- condition = and_ (* clauses ["condition" ])
1124- clauses ["condition" ] = condition
1125- return clauses
1122+ having_cuts = cell .having_cuts
1123+ hav_condition = and_ (* self .conditions_for_cuts (having_cuts ))
11261124
1127- # namnd added
1128- def clauses_for_having (self , having_clauses ):
1129- clauses = []
1130- groups = []
1131- for cut in having_clauses :
1132- hierarchy = str (cut .hierarchy ) if cut .hierarchy else None
1133- if isinstance (cut , PointCut ):
1134- path = cut .path
1135- hav_conds = self .having_condition (str (cut .dimension ),
1136- path ,
1137- hierarchy , cut .invert )
1138- clauses .append (hav_conds ["condition" ])
1139- groups += hav_conds ["group" ]
1140- # return one dict
1141- dict_clause = {"groups" : groups , "condition" : clauses }
1142- return dict_clause
1143-
1144- # namnd added
1145- def having_condition (self , dim , path , hierarchy = None , invert = False ):
1146- """Returns a dict of `Condition` tuple (`attributes`, `conditions`,
1147- `group_by`) dimension `dim` point at `path` and list group attrs use having. It is a compound
1148- condition - one equality condition for each path element in form:
1149- ``level[i].key = path[i]``"""
1150- conditions = []
1151- groups = []
1152- levels = self .level_keys (dim , hierarchy , path )
1153- for level_key , value in zip (levels , path ):
1154- # Prepare condition: dimension.level_key = path_value
1155- column = self .column (level_key )
1156- conditions .append (column == value )
1157- groups .append (column )
1125+ if hav_condition is None :
1126+ return None
11581127
1159- condition = sql . expression . and_ ( * conditions )
1128+ colums = self . colums_in_having_cuts ( having_cuts )
11601129
1161- if invert :
1162- condition = sql .expression .not_ (condition )
1130+ return (colums , hav_condition )
1131+
1132+ # madman: get attributes in having cuts
1133+ def colums_in_having_cuts (self , having_cus ):
1134+
1135+ columns = []
1136+
1137+ for cut in having_cus :
1138+ hierarchy = str (cut .hierarchy ) if cut .hierarchy else None
1139+ levels = self .hierarchies [(str (cut .dimension ), hierarchy )]
1140+ for level_key in levels :
1141+ column = self .column (level_key )
1142+ columns .append (column )
11631143
1164- dict_condition = {"group" : groups , "condition" : condition }
1165- return dict_condition
1144+ return columns
0 commit comments