@@ -292,88 +292,6 @@ def get_snuba_column_name(name, dataset=Dataset.Events):
292
292
return DATASETS [dataset ].get (name , u"tags[{}]" .format (name ))
293
293
294
294
295
- def detect_dataset (query_args , aliased_conditions = False ):
296
- """
297
- Determine the dataset to use based on the conditions, selected_columns,
298
- groupby clauses.
299
-
300
- This function operates on the end user field aliases and not the internal column
301
- names that have been converted using the field mappings.
302
-
303
- The aliased_conditions parameter switches column detection between
304
- the public aliases and the internal names. When query conditions
305
- have been pre-parsed by api.event_search set aliased_conditions=True
306
- as we need to look for internal names.
307
-
308
- :deprecated: This method and the automatic dataset resolution is deprecated.
309
- You should use sentry.snuba.discover instead.
310
- """
311
- if query_args .get ("dataset" , None ):
312
- return query_args ["dataset" ]
313
-
314
- dataset = Dataset .Events
315
- transaction_fields = set (DATASETS [Dataset .Transactions ].keys ()) - set (
316
- DATASETS [Dataset .Events ].keys ()
317
- )
318
- condition_fieldset = transaction_fields
319
-
320
- if aliased_conditions :
321
- # Release and user are also excluded as they are present on both
322
- # datasets and don't trigger usage of transactions.
323
- condition_fieldset = (
324
- set (DATASET_FIELDS [Dataset .Transactions ])
325
- - set (DATASET_FIELDS [Dataset .Events ])
326
- - set (["release" , "user" ])
327
- )
328
-
329
- for condition in query_args .get ("conditions" ) or []:
330
- if isinstance (condition [0 ], six .string_types ) and condition [0 ] in condition_fieldset :
331
- return Dataset .Transactions
332
- if condition == ["event.type" , "=" , "transaction" ] or condition == [
333
- "type" ,
334
- "=" ,
335
- "transaction" ,
336
- ]:
337
- return Dataset .Transactions
338
-
339
- if condition == ["event.type" , "!=" , "transaction" ] or condition == [
340
- "type" ,
341
- "!=" ,
342
- "transaction" ,
343
- ]:
344
- return Dataset .Events
345
-
346
- for field in query_args .get ("selected_columns" ) or []:
347
- if isinstance (field , six .string_types ) and field in transaction_fields :
348
- return Dataset .Transactions
349
-
350
- for field in query_args .get ("aggregations" ) or []:
351
- if len (field ) != 3 :
352
- continue
353
- # Check field or fields
354
- if isinstance (field [1 ], six .string_types ) and field [1 ] in transaction_fields :
355
- return Dataset .Transactions
356
- if isinstance (field [1 ], (list , tuple )):
357
- is_transaction = [column for column in field [1 ] if column in transaction_fields ]
358
- if is_transaction :
359
- return Dataset .Transactions
360
- # Check for transaction only field aliases
361
- if isinstance (field [2 ], six .string_types ) and field [2 ] in (
362
- "apdex" ,
363
- "impact" ,
364
- "p75" ,
365
- "p95" ,
366
- "p99" ,
367
- ):
368
- return Dataset .Transactions
369
-
370
- for field in query_args .get ("groupby" ) or []:
371
- if field in transaction_fields :
372
- return Dataset .Transactions
373
-
374
- return dataset
375
-
376
-
377
295
def get_function_index (column_expr , depth = 0 ):
378
296
"""
379
297
If column_expr list contains a function, returns the index of its function name
@@ -411,7 +329,7 @@ def get_function_index(column_expr, depth=0):
411
329
return None
412
330
413
331
414
- def parse_columns_in_functions (col , context = None , index = None , dataset = Dataset . Events ):
332
+ def parse_columns_in_functions (col , context = None , index = None ):
415
333
"""
416
334
Checks expressions for arguments that should be considered a column while
417
335
ignoring strings that represent clickhouse function names
@@ -434,23 +352,23 @@ def parse_columns_in_functions(col, context=None, index=None, dataset=Dataset.Ev
434
352
if function_name_index > 0 :
435
353
for i in six .moves .xrange (0 , function_name_index ):
436
354
if context is not None :
437
- context [i ] = get_snuba_column_name (col [i ], dataset )
355
+ context [i ] = get_snuba_column_name (col [i ])
438
356
439
357
args = col [function_name_index + 1 ]
440
358
441
359
# check for nested functions in args
442
360
if get_function_index (args ):
443
361
# look for columns
444
- return parse_columns_in_functions (args , args , dataset = dataset )
362
+ return parse_columns_in_functions (args , args )
445
363
446
364
# check each argument for column names
447
365
else :
448
366
for (i , arg ) in enumerate (args ):
449
- parse_columns_in_functions (arg , args , i , dataset = dataset )
367
+ parse_columns_in_functions (arg , args , i )
450
368
else :
451
369
# probably a column name
452
370
if context is not None and index is not None :
453
- context [index ] = get_snuba_column_name (col , dataset )
371
+ context [index ] = get_snuba_column_name (col )
454
372
455
373
456
374
def get_arrayjoin (column ):
@@ -459,23 +377,6 @@ def get_arrayjoin(column):
459
377
return match .groups ()[0 ]
460
378
461
379
462
- def valid_orderby (orderby , custom_fields = None , dataset = Dataset .Events ):
463
- """
464
- Check if a field can be used in sorting. We don't allow
465
- sorting on fields that would be aliased as tag[foo] because those
466
- fields are unlikely to be selected.
467
- """
468
- if custom_fields is None :
469
- custom_fields = []
470
- fields = orderby if isinstance (orderby , (list , tuple )) else [orderby ]
471
- mapping = DATASETS [dataset ]
472
- for field in fields :
473
- field = field .lstrip ("-" )
474
- if field not in mapping and field not in custom_fields :
475
- return False
476
- return True
477
-
478
-
479
380
def transform_aliases_and_query (** kwargs ):
480
381
"""
481
382
Convert aliases in selected_columns, groupby, aggregation, conditions,
@@ -499,7 +400,7 @@ def transform_aliases_and_query(**kwargs):
499
400
arrayjoin = kwargs .get ("arrayjoin" )
500
401
orderby = kwargs .get ("orderby" )
501
402
having = kwargs .get ("having" , [])
502
- dataset = detect_dataset ( kwargs )
403
+ dataset = Dataset . Events
503
404
504
405
if selected_columns :
505
406
for (idx , col ) in enumerate (selected_columns ):
@@ -511,14 +412,14 @@ def transform_aliases_and_query(**kwargs):
511
412
translated_columns [col [2 ]] = col [2 ]
512
413
derived_columns .add (col [2 ])
513
414
else :
514
- name = get_snuba_column_name (col , dataset )
415
+ name = get_snuba_column_name (col )
515
416
selected_columns [idx ] = name
516
417
translated_columns [name ] = col
517
418
518
419
if groupby :
519
420
for (idx , col ) in enumerate (groupby ):
520
421
if col not in derived_columns :
521
- name = get_snuba_column_name (col , dataset )
422
+ name = get_snuba_column_name (col )
522
423
else :
523
424
name = col
524
425
@@ -528,12 +429,12 @@ def transform_aliases_and_query(**kwargs):
528
429
for aggregation in aggregations or []:
529
430
derived_columns .add (aggregation [2 ])
530
431
if isinstance (aggregation [1 ], six .string_types ):
531
- aggregation [1 ] = get_snuba_column_name (aggregation [1 ], dataset )
432
+ aggregation [1 ] = get_snuba_column_name (aggregation [1 ])
532
433
elif isinstance (aggregation [1 ], (set , tuple , list )):
533
- aggregation [1 ] = [get_snuba_column_name (col , dataset ) for col in aggregation [1 ]]
434
+ aggregation [1 ] = [get_snuba_column_name (col ) for col in aggregation [1 ]]
534
435
535
436
for col in filter_keys .keys ():
536
- name = get_snuba_column_name (col , dataset )
437
+ name = get_snuba_column_name (col )
537
438
filter_keys [name ] = filter_keys .pop (col )
538
439
539
440
if conditions :
@@ -558,7 +459,7 @@ def transform_aliases_and_query(**kwargs):
558
459
translated_orderby .append (
559
460
u"{}{}" .format (
560
461
"-" if field_with_order .startswith ("-" ) else "" ,
561
- field if field in derived_columns else get_snuba_column_name (field , dataset ),
462
+ field if field in derived_columns else get_snuba_column_name (field ),
562
463
)
563
464
)
564
465
@@ -1052,15 +953,7 @@ def dataset_query(
1052
953
You should use sentry.snuba.discover instead.
1053
954
"""
1054
955
if dataset is None :
1055
- dataset = detect_dataset (
1056
- dict (
1057
- dataset = dataset ,
1058
- aggregations = aggregations ,
1059
- conditions = conditions ,
1060
- selected_columns = selected_columns ,
1061
- groupby = groupby ,
1062
- )
1063
- )
956
+ raise ValueError ("A dataset is required, and is no longer automatically detected." )
1064
957
1065
958
derived_columns = []
1066
959
if selected_columns :
0 commit comments