MCPcopy Create free account
hub / github.com/apache/impala / _create_select_clause

Method _create_select_clause

tests/comparison/query_generator.py:268–373  ·  view source on GitHub ↗
(self,
      table_exprs,
      select_item_data_types,
      required_select_item_type,
      require_aggregate)

Source from the content-addressed store, hash-verified

266 return WithClause(with_clause_inline_views)
267
268 def _create_select_clause(self,
269 table_exprs,
270 select_item_data_types,
271 required_select_item_type,
272 require_aggregate):
273 if select_item_data_types:
274 select_item_data_types = tuple(select_item_data_types)
275 if select_item_data_types \
276 and required_select_item_type \
277 and not issubclass(required_select_item_type, select_item_data_types):
278 raise Exception('Required select item type is not in allowed types')
279
280 # Generate column types for the select clause if not specified.
281 if not select_item_data_types:
282 select_item_data_types = []
283 desired_item_count = self.profile.get_select_item_count()
284 if required_select_item_type:
285 select_item_data_types.append(required_select_item_type)
286 while len(select_item_data_types) < desired_item_count:
287 select_item_data_types.append(self.profile.choose_type(table_exprs.col_types))
288 shuffle(select_item_data_types)
289 select_item_data_types = tuple(select_item_data_types)
290
291 # We want to assign BASIC, AGG or ANALYTIC to each column. We want to prevent GROUP BY
292 # float_col, because the groupings will differ across databases because floats are
293 # approximate values.
294 column_categories = ['-' for _ in select_item_data_types]
295 if require_aggregate:
296 column_categories[randint(0, len(column_categories) - 1)] = 'AGG'
297 # Assign AGG and ANALYTIC some columns
298 for i in range(len(column_categories)):
299 item_category = self.profile._choose_from_weights(
300 self.profile.weights('SELECT_ITEM_CATEGORY'))
301 if item_category in ('AGG', 'ANALYTIC'):
302 column_categories[i] = item_category
303 agg_present = 'AGG' in column_categories
304 # Assign BASIC to the remaining columns
305 for i in range(len(column_categories)):
306 if column_categories[i] == '-':
307 if select_item_data_types[i].is_approximate() and agg_present:
308 column_categories[i] = 'AGG'
309 else:
310 # If AGG column is present, BASIC can only be assigned to a column if it's not a
311 # Float.
312 column_categories[i] = 'BASIC'
313
314 select_items = []
315
316 for i, column_category in enumerate(column_categories):
317 if column_category == 'BASIC':
318 select_items.append(self._create_basic_select_item(
319 table_exprs, select_item_data_types[i]))
320 else:
321 select_items.append((column_category, select_item_data_types[i]))
322
323 analytic_count = sum(1 for c in column_category if c == 'ANALYTIC')
324
325 select_item_exprs = \

Callers 1

generate_statementMethod · 0.95

Calls 15

ValExprListClass · 0.90
SelectClauseClass · 0.90
shuffleFunction · 0.85
rangeFunction · 0.85
get_select_item_countMethod · 0.80
choose_typeMethod · 0.80
_choose_from_weightsMethod · 0.80
weightsMethod · 0.80
typeEnum · 0.50

Tested by

no test coverage detected