Esempio n. 1
0
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')
Esempio n. 2
0
 def test_filter_tables_by_empty_indexes_return_all(self):
     filt_indexes = {self.tbA_name: [],
                     self.tbB_name: [i for i in range(20, 70, 10)]}
     expected_tba = {'colA1': self.tbA['colA1'],
                     'colA2': self.tbA['colA2'],
                     'colA3': self.tbA['colA3']}
     expected_tbb = {'colB1': [str(i) for i in range(20, 70, 10)]}
     test_tables = man.filter_tables(self.tables, filt_indexes)
     test_tba = test_tables[self.tbA_name]
     test_tbb = test_tables[self.tbB_name]
     # Check each columns that they match
     self.assertEqual(test_tba['colA1'], expected_tba['colA1'])
     self.assertEqual(test_tba['colA2'], expected_tba['colA2'])
     self.assertEqual(test_tba['colA3'], expected_tba['colA3'])
     self.assertEqual(test_tbb['colB1'], expected_tbb['colB1'])
Esempio n. 3
0
 def test_filter_tables_by_empty_indexes_return_all(self):
     filt_indexes = {
         self.tbA_name: [],
         self.tbB_name: [i for i in range(20, 70, 10)]
     }
     expected_tba = {
         'colA1': self.tbA['colA1'],
         'colA2': self.tbA['colA2'],
         'colA3': self.tbA['colA3']
     }
     expected_tbb = {'colB1': [str(i) for i in range(20, 70, 10)]}
     test_tables = man.filter_tables(self.tables, filt_indexes)
     test_tba = test_tables[self.tbA_name]
     test_tbb = test_tables[self.tbB_name]
     # Check each columns that they match
     self.assertEqual(test_tba['colA1'], expected_tba['colA1'])
     self.assertEqual(test_tba['colA2'], expected_tba['colA2'])
     self.assertEqual(test_tba['colA3'], expected_tba['colA3'])
     self.assertEqual(test_tbb['colB1'], expected_tbb['colB1'])