zhiminy commited on
Commit
fa492c4
·
1 Parent(s): cabb3ce

reduce expansion

Browse files
Files changed (2) hide show
  1. app.py +14 -6
  2. msr.py +14 -6
app.py CHANGED
@@ -206,22 +206,30 @@ def get_bigquery_client():
206
 
207
  def generate_table_union_statements(start_date, end_date):
208
  """
209
- Generate UNION ALL statements for githubarchive.day tables in date range.
210
 
211
  Args:
212
  start_date: Start datetime
213
  end_date: End datetime
214
 
215
  Returns:
216
- String with UNION ALL SELECT statements for all tables in range
217
  """
218
  table_names = []
219
- current_date = start_date
220
 
221
- while current_date < end_date:
222
- table_name = f"`githubarchive.day.{current_date.strftime('%Y%m%d')}`"
 
 
 
 
223
  table_names.append(table_name)
224
- current_date += timedelta(days=1)
 
 
 
 
 
225
 
226
  # Create UNION ALL chain
227
  union_parts = [f"SELECT * FROM {table}" for table in table_names]
 
206
 
207
  def generate_table_union_statements(start_date, end_date):
208
  """
209
+ Generate UNION ALL statements for githubarchive.month tables in date range.
210
 
211
  Args:
212
  start_date: Start datetime
213
  end_date: End datetime
214
 
215
  Returns:
216
+ String with UNION ALL SELECT statements for all monthly tables in range
217
  """
218
  table_names = []
 
219
 
220
+ # Start from the beginning of start_date's month
221
+ current_date = start_date.replace(day=1)
222
+ end_month = end_date.replace(day=1)
223
+
224
+ while current_date <= end_month:
225
+ table_name = f"`githubarchive.month.{current_date.strftime('%Y%m')}`"
226
  table_names.append(table_name)
227
+
228
+ # Move to next month
229
+ if current_date.month == 12:
230
+ current_date = current_date.replace(year=current_date.year + 1, month=1)
231
+ else:
232
+ current_date = current_date.replace(month=current_date.month + 1)
233
 
234
  # Create UNION ALL chain
235
  union_parts = [f"SELECT * FROM {table}" for table in table_names]
msr.py CHANGED
@@ -158,22 +158,30 @@ def get_bigquery_client():
158
 
159
  def generate_table_union_statements(start_date, end_date):
160
  """
161
- Generate UNION ALL statements for githubarchive.day tables in date range.
162
 
163
  Args:
164
  start_date: Start datetime
165
  end_date: End datetime
166
 
167
  Returns:
168
- String with UNION ALL SELECT statements for all tables in range
169
  """
170
  table_names = []
171
- current_date = start_date
172
 
173
- while current_date < end_date:
174
- table_name = f"`githubarchive.day.{current_date.strftime('%Y%m%d')}`"
 
 
 
 
175
  table_names.append(table_name)
176
- current_date += timedelta(days=1)
 
 
 
 
 
177
 
178
  # Create UNION ALL chain
179
  union_parts = [f"SELECT * FROM {table}" for table in table_names]
 
158
 
159
  def generate_table_union_statements(start_date, end_date):
160
  """
161
+ Generate UNION ALL statements for githubarchive.month tables in date range.
162
 
163
  Args:
164
  start_date: Start datetime
165
  end_date: End datetime
166
 
167
  Returns:
168
+ String with UNION ALL SELECT statements for all monthly tables in range
169
  """
170
  table_names = []
 
171
 
172
+ # Start from the beginning of start_date's month
173
+ current_date = start_date.replace(day=1)
174
+ end_month = end_date.replace(day=1)
175
+
176
+ while current_date <= end_month:
177
+ table_name = f"`githubarchive.month.{current_date.strftime('%Y%m')}`"
178
  table_names.append(table_name)
179
+
180
+ # Move to next month
181
+ if current_date.month == 12:
182
+ current_date = current_date.replace(year=current_date.year + 1, month=1)
183
+ else:
184
+ current_date = current_date.replace(month=current_date.month + 1)
185
 
186
  # Create UNION ALL chain
187
  union_parts = [f"SELECT * FROM {table}" for table in table_names]