def _parse_order(self, sql): """ parsing the sql by the grammar Order ::= asc A | desc A A ::= agg column table :return: [Order(), states] """ result = [] if 'order' not in sql['query_toks_no_value'] or 'by' not in sql['query_toks_no_value']: return result, None elif 'limit' in sql['query_toks_no_value']: return result, None else: if sql['sql']['orderBy'] == []: return result, None else: select = sql['sql']['select'][1] if sql['sql']['orderBy'][0] == 'desc': result.append(Order(0)) else: result.append(Order(1)) result.append(A(sql['sql']['orderBy'][1][0][1][0])) self.colSet.add(sql['col_set'].index(sql['names'][sql['sql']['orderBy'][1][0][1][1]])) result.append(C(sql['col_set'].index(sql['names'][sql['sql']['orderBy'][1][0][1][1]]))) if sql['sql']['orderBy'][1][0][1][1] == 0: result.append(self._parser_column0(sql, select)) else: result.append(T(sql['col_table'][sql['sql']['orderBy'][1][0][1][1]])) return result, None
def _parse_sup(self, sql): """ parsing the sql by the grammar Sup ::= Most A | Least A A ::= agg column table :return: [Sup(), states] """ result = [] select = sql['sql']['select'][1] if sql['sql']['limit'] == None: return result, None if sql['sql']['orderBy'][0] == 'desc': result.append(Sup(0)) else: result.append(Sup(1)) result.append(A(sql['sql']['orderBy'][1][0][1][0])) self.colSet.add(sql['col_set'].index( sql['names'][sql['sql']['orderBy'][1][0][1][1]])) result.append( C(sql['col_set'].index( sql['names'][sql['sql']['orderBy'][1][0][1][1]]))) if sql['sql']['orderBy'][1][0][1][1] == 0: result.append(self._parser_column0(sql, select)) else: result.append( T(sql['col_table'][sql['sql']['orderBy'][1][0][1][1]])) return result, None
def _parse_select(self, sql): """ parsing the sql by the grammar Select ::= A | AA | AAA | ... | A ::= agg column table :return: [Sel(), states] """ result = [] select = sql['sql']['select'][1] result.append(Sel(0)) result.append(N(len(select) - 1)) for sel in select: result.append(A(sel[0])) self.colSet.add(sql['col_set'].index(sql['names'][sel[1][1][1]])) result.append(C(sql['col_set'].index(sql['names'][sel[1][1][1]]))) # now check for the situation with * if sel[1][1][1] == 0: result.append(self._parser_column0(sql, select)) else: result.append(T(sql['col_table'][sel[1][1][1]])) if not self.copy_selec: self.copy_selec = [copy.deepcopy(result[-2]), copy.deepcopy(result[-1])] return result, None
def parse_one_condition(self, sql_condit, names, sql): result = [] # check if V(root) nest_query = True if type(sql_condit[3]) != dict: nest_query = False if sql_condit[0] == True: if sql_condit[1] == 9: # not like only with values fil = Filter(10) elif sql_condit[1] == 8: # not in with Root fil = Filter(19) else: print(sql_condit[1]) raise NotImplementedError("not implement for the others FIL") else: # check for Filter (<,=,>,!=,between, >=, <=, ...) single_map = {1:8,2:2,3:5,4:4,5:7,6:6,7:3} nested_map = {1:15,2:11,3:13,4:12,5:16,6:17,7:14} if sql_condit[1] in [1, 2, 3, 4, 5, 6, 7]: if nest_query == False: fil = Filter(single_map[sql_condit[1]]) else: fil = Filter(nested_map[sql_condit[1]]) elif sql_condit[1] == 9: fil = Filter(9) elif sql_condit[1] == 8: fil = Filter(18) else: print(sql_condit[1]) raise NotImplementedError("not implement for the others FIL") result.append(fil) result.append(A(sql_condit[2][1][0])) self.colSet.add(sql['col_set'].index(sql['names'][sql_condit[2][1][1]])) result.append(C(sql['col_set'].index(sql['names'][sql_condit[2][1][1]]))) if sql_condit[2][1][1] == 0: select = sql['sql']['select'][1] result.append(self._parser_column0(sql, select)) else: result.append(T(sql['col_table'][sql_condit[2][1][1]])) # check for the nested value if type(sql_condit[3]) == dict: nest_query = {} nest_query['names'] = names nest_query['query_toks_no_value'] = "" nest_query['sql'] = sql_condit[3] nest_query['col_table'] = sql['col_table'] nest_query['col_set'] = sql['col_set'] nest_query['table_names'] = sql['table_names'] nest_query['question'] = sql['question'] nest_query['query'] = sql['query'] nest_query['keys'] = sql['keys'] result.extend(self.parser(nest_query)) return result
def convert_TC_to_C_and_T(lf_action, embedder_input, embedder_input_idxes): convert_action_list = [] for action in lf_action: if type(action) != define_rule.TC: convert_action_list.append(action) else: t_id, c_id = embedder_input_idxes[action.id_c] convert_action_list.append(C(c_id)) convert_action_list.append(T(t_id)) return convert_action_list