def eval_onde(line, tables): ''' Evaluate a ONDE query :param line: ONDE query without the 'ONDE ' keyword :param tables: a dict {tname: tb} :return: a dict {tname: filtered_tb} ''' # Get atomic conditional statement and connectives from line atomics, conn = man.split_exprn(line) # all the filtered indexes from each condition statement f_cols_lst = [eval_cond(cond, tables) for cond in atomics] # Reduce the list of dicts to one single dict by joining them together # by the connectives join = lambda ind1, ind2: man.join_filt_indexes(tables.keys(), ind1, ind2, conn.pop(0)) f_cols = fct.reduce(join, f_cols_lst) if not isinstance(f_cols, bool): # If ONDE consists of only an EXISTE(...) clause then there is no need # to filter tables return man.filter_tables(tables, f_cols) elif f_cols: # f_cols is a boolean value, i.e. a single EXISTE(...) clause, return # tables if it is True, else raise TerminateQueryError return tables elif not f_cols: raise hpr.TerminateQueryError('Existe condition is False') else: raise hpr.InvalidQueryError('Something is wrong with the query')
def test_join_filt_indexes_bool_return_all(self): expected_tb1 = {self.tbA_name: self.overlap2} expected_tb2 = {self.tbB_name: self.noverlap2} test = man.join_filt_indexes([self.tbA_name, self.tbB_name], True, self.ind2, ' Y ') test_tb1 = test[self.tbA_name] test_tb2 = test[self.tbB_name] self.assertEqual(test_tb1, expected_tb1[self.tbA_name]) self.assertEqual(test_tb2, expected_tb2[self.tbB_name])
def test_join_filt_indexes_OR(self): expected_tb1 = {self.tbA_name: [i for i in range(0, 75)]} expected_tb2 = {self.tbB_name: self.noverlap1 + self.noverlap2} test = man.join_filt_indexes([self.tbA_name, self.tbB_name], self.ind1, self.ind2, ' O ') test_tb1 = test[self.tbA_name] test_tb2 = test[self.tbB_name] self.assertEqual(test_tb1, expected_tb1[self.tbA_name]) self.assertEqual(test_tb2, expected_tb2[self.tbB_name])
def test_join_filt_indexes_AND(self): expected_tb1 = {self.tbA_name: [i for i in range(25, 50)]} expected_tb2 = {self.tbB_name: []} test = man.join_filt_indexes([self.tbA_name, self.tbB_name], self.ind1, self.ind2, ' Y ') test_tb1 = test[self.tbA_name] test_tb2 = test[self.tbB_name] self.assertEqual(test_tb1, expected_tb1[self.tbA_name]) self.assertEqual(test_tb2, expected_tb2[self.tbB_name])
def test_join_filt_indexes_bool_return_all(self): expected_tb1 = {self.tbA_name: self.overlap2} expected_tb2 = {self.tbB_name: self.noverlap2} test = man.join_filt_indexes([self.tbA_name, self.tbB_name], True, self.ind2, ' Y ') test_tb1 = test[self.tbA_name] test_tb2 = test[self.tbB_name] self.assertEqual(test_tb1, expected_tb1[self.tbA_name]) self.assertEqual(test_tb2, expected_tb2[self.tbB_name])
def test_join_filt_indexes_OR(self): expected_tb1 = {self.tbA_name: [i for i in range(0, 75)]} expected_tb2 = {self.tbB_name: self.noverlap1 + self.noverlap2} test = man.join_filt_indexes([self.tbA_name, self.tbB_name], self.ind1, self.ind2, ' O ') test_tb1 = test[self.tbA_name] test_tb2 = test[self.tbB_name] self.assertEqual(test_tb1, expected_tb1[self.tbA_name]) self.assertEqual(test_tb2, expected_tb2[self.tbB_name])
def test_join_filt_indexes_AND(self): expected_tb1 = {self.tbA_name: [i for i in range(25, 50)]} expected_tb2 = {self.tbB_name: []} test = man.join_filt_indexes([self.tbA_name, self.tbB_name], self.ind1, self.ind2, ' Y ') test_tb1 = test[self.tbA_name] test_tb2 = test[self.tbB_name] self.assertEqual(test_tb1, expected_tb1[self.tbA_name]) self.assertEqual(test_tb2, expected_tb2[self.tbB_name])