@@ -63,12 +63,15 @@ def __init__(
6363 self .start = standardise_date (start )
6464 self .stop = standardise_date (stop )
6565 self .columns = columns
66- self .tables = self . _parse_tables (tables )
66+ self .tables = _parse_tables (tables )
6767 if "*" in columns and len (self .tables ) != 1 :
6868 raise ValueError (
6969 "Must give named columns when combining multiple event type tables."
7070 )
71- self .date_subsets = self ._make_table_list (
71+ self .date_subsets = _make_table_list (
72+ tables = self .tables ,
73+ start = self .start ,
74+ stop = self .stop ,
7275 hours = hours ,
7376 subscriber_subset = subscriber_subset ,
7477 subscriber_identifier = subscriber_identifier ,
@@ -82,43 +85,6 @@ def column_names(self) -> List[str]:
8285 0
8386 ].column_names # Use in preference to self.columns which might be ["*"]
8487
85- def _parse_tables (self , tables ):
86- if tables is None :
87- return (
88- "calls" ,
89- "sms" ,
90- ) # This should default to all the tables really, but that would break all the tests
91- elif isinstance (tables , str ):
92- return [tables ]
93- else :
94- return sorted (tables )
95-
96- def _make_table_list (self , * , hours , subscriber_subset , subscriber_identifier ):
97- """
98- Makes a list of EventTableSubset queries.
99- """
100-
101- date_subsets = []
102- for table in self .tables :
103- try :
104- sql = EventTableSubset (
105- start = self .start ,
106- stop = self .stop ,
107- table = table ,
108- columns = self .columns ,
109- hours = hours ,
110- subscriber_subset = subscriber_subset ,
111- subscriber_identifier = subscriber_identifier ,
112- )
113- date_subsets .append (sql )
114- except MissingDateError :
115- warnings .warn (
116- f"No data in { table } for { self .start } –{ self .stop } " , stacklevel = 2
117- )
118- if not date_subsets :
119- raise MissingDateError (self .start , self .stop )
120- return date_subsets
121-
12288 def _make_query (self ):
12389
12490 # Get the list of tables, select the relevant columns and union
@@ -131,3 +97,44 @@ def _make_query(self):
13197 def fully_qualified_table_name (self ):
13298 # EventTableSubset are a simple select from events, and should not be cached
13399 raise NotImplementedError
100+
101+
102+ def _parse_tables (tables ):
103+ if tables is None :
104+ return (
105+ "calls" ,
106+ "sms" ,
107+ ) # This should default to all the tables really, but that would break all the tests
108+ elif isinstance (tables , str ):
109+ return [tables ]
110+ elif len (tables ) == 0 :
111+ raise ValueError ("Tables must be a list of tables, or None." )
112+ else :
113+ return sorted (tables )
114+
115+
116+ def _make_table_list (
117+ * , tables , start , stop , columns , hours , subscriber_subset , subscriber_identifier
118+ ):
119+ """
120+ Makes a list of EventTableSubset queries.
121+ """
122+
123+ date_subsets = []
124+ for table in tables :
125+ try :
126+ sql = EventTableSubset (
127+ start = start ,
128+ stop = stop ,
129+ table = table ,
130+ columns = columns ,
131+ hours = hours ,
132+ subscriber_subset = subscriber_subset ,
133+ subscriber_identifier = subscriber_identifier ,
134+ )
135+ date_subsets .append (sql )
136+ except MissingDateError :
137+ warnings .warn (f"No data in { table } for { start } –{ stop } " , stacklevel = 2 )
138+ if not date_subsets :
139+ raise MissingDateError (start , stop )
140+ return date_subsets
0 commit comments