Skip to content

Commit 17385dd

Browse files
committed
Merge branch 'master' of https://github.com/ImagingDataCommons/IDC-Common into idc-test
2 parents 2d52cbc + 1c27b0f commit 17385dd

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

google_helpers/bigquery/bq_support.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ def insert_job_batch_and_get_results(cls, query_set):
587587
# Support for specifying a set of continuous numeric attributes to be presumed for BETWEEN clauses
588588
#
589589
# TODO: add support for DATETIME eg 6/10/2010
590+
@staticmethod
590591
def build_bq_filter_and_params(filters, comb_with='AND', param_suffix=None, with_count_toggle=False,
591592
field_prefix=None, type_schema=None, case_insens=True, continuous_numerics=None):
592593
if field_prefix and field_prefix[-1] != ".":
@@ -675,8 +676,13 @@ def build_bq_filter_and_params(filters, comb_with='AND', param_suffix=None, with
675676
is_btw = re.search('_e?btwe?', attr.lower()) is not None
676677
attr_name = attr[:attr.rfind('_')] if re.search('_[gl]te?|_e?btwe?|_eq', attr) else attr
677678
if attr_name not in attr_filters:
679+
operator = 'OR'
680+
if 'values' in values:
681+
# This is a fully qualified attribute which needs to have its definition broken out
682+
operator = values['op']
683+
values = values['values']
678684
attr_filters[attr_name] = {
679-
'OP': 'OR',
685+
'OP': operator,
680686
'filters': []
681687
}
682688
attr_filter_set = attr_filters[attr_name]['filters']
@@ -820,17 +826,23 @@ def build_bq_filter_and_params(filters, comb_with='AND', param_suffix=None, with
820826
filter_string += " OR ".join(btw_filter_strings)
821827
query_param = query_params
822828
else:
823-
# Simple array param
824-
query_param['parameterType']['type'] = "ARRAY"
825-
query_param['parameterType']['arrayType'] = {
826-
'type': parameter_type
827-
}
828-
query_param['parameterValue'] = {
829-
'arrayValues': [{'value': x.lower() if parameter_type == 'STRING' else x} for x in values]}
830-
831-
clause_base = "%s IN UNNEST(@{})" % ("LOWER({}{})" if parameter_type == "STRING" else "{}{}")
832-
filter_string += clause_base.format('' if not field_prefix else field_prefix, attr,
833-
param_name)
829+
if operator == 'AND' and len(values) > 1:
830+
# If an operator is to be AND'd with more than one value we must make an intersection statement
831+
# on the higher-level entity (i.e. select for studies which have series containing both values)
832+
# That cannot be performed here, as this is only a clause builder
833+
logger.warning("[WARNING] Multiple-value AND clauses require an intersection statement!")
834+
else:
835+
# Simple array param
836+
query_param['parameterType']['type'] = "ARRAY"
837+
query_param['parameterType']['arrayType'] = {
838+
'type': parameter_type
839+
}
840+
query_param['parameterValue'] = {
841+
'arrayValues': [{'value': x.lower() if parameter_type == 'STRING' else x} for x in values]}
842+
843+
clause_base = "%s IN UNNEST(@{})" % ("LOWER({}{})" if parameter_type == "STRING" else "{}{}")
844+
filter_string += clause_base.format('' if not field_prefix else field_prefix, attr,
845+
param_name)
834846

835847
if with_count_toggle:
836848
filter_string = "({}) OR @{}_filtering = 'not_filtering'".format(filter_string, param_name)

idc_collections/collex_metadata_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ def get_table_data_with_cart_data(tabletype, sortarg, sortdir, current_filters,f
18311831
return [num_found, table_arr]
18321832

18331833

1834-
def get_cart_data_studylvl(filtergrp_list, partitions, limit, offset, length, mxseries,results_lvl='StudyInstanceUID', with_records=True, debug=False):
1834+
def get_cart_data_studylvl(filtergrp_list, partitions, limit, offset, length, mxseries, results_lvl='StudyInstanceUID', with_records=True, debug=False):
18351835
aggregate_level = "StudyInstanceUID"
18361836
versions=ImagingDataCommonsVersion.objects.filter(
18371837
active=True
@@ -1992,6 +1992,7 @@ def get_cart_data_studylvl(filtergrp_list, partitions, limit, offset, length, mx
19921992
if debug:
19931993
solr_result['response']['query_string'] = query_str
19941994
solr_result['response']['query_string_series_lvl'] = query_str_series_lvl
1995+
print(solr_result['response'])
19951996
return solr_result['response']
19961997

19971998

@@ -2206,7 +2207,6 @@ def get_cart_manifest(filtergrp_list, partitions, mxstudies, mxseries, field_lis
22062207
if 'total_SeriesInstanceUID' in solr_result:
22072208
manifest['total'] = solr_result['total_SeriesInstanceUID']
22082209
elif 'total' in solr_result:
2209-
22102210
manifest['total'] = solr_result['total']
22112211

22122212
if ('total_instance_size' in solr_result):
@@ -2818,13 +2818,11 @@ def get_bq_metadata(filters, fields, data_version, sources_and_attrs=None, group
28182818
tables_in_query = []
28192819
joins = []
28202820
query_filters = []
2821-
non_related_filters = {}
28222821
fields = [field_clauses[image_table]] if image_table in field_clauses else []
28232822
if search_child_records_by:
28242823
child_record_search_field = search_child_records_by
28252824
if image_table in filter_attr_by_bq['sources']:
28262825
filter_set = {x: filters[x] for x in filters if x in filter_attr_by_bq['sources'][image_table]['list']}
2827-
non_related_filters = filter_set
28282826
if len(filter_set):
28292827
if may_need_intersect and len(filter_set.keys()) > 1:
28302828
for filter in filter_set:

0 commit comments

Comments
 (0)