def _cross_join(a_table: Table, b_table: Table, r_table: Table): a_table_rows, b_table_rows = a_table.get_rows(), b_table.get_rows() for a_table_row in a_table_rows: for b_table_row in b_table_rows: r_row = a_table_row.copy() r_row.extend(b_table_row) r_table.add_row_list(r_row) return r_table
def _cross_join_on_condition(a_table: Table, b_table: Table, r_table: Table, names, condition: Expr): a_table_rows, b_table_rows = a_table.get_rows(), b_table.get_rows() a_table_rows_map_list, b_table_rows_map_list = a_table.get_rows_map_list(names), b_table.get_rows_map_list(names) for a_table_row, a_table_row_map in zip(a_table_rows, a_table_rows_map_list): for b_table_row, b_table_row_map in zip(b_table_rows, b_table_rows_map_list): values = a_table_row_map.copy() values.update(b_table_row_map) if not condition.execute(values): continue new_row = a_table_row.copy() new_row.extend(b_table_row) r_table.add_row_list(new_row) return r_table
def condition_filter(a_table: Table, r_table: Table, condition: Expr): names = [] var_count, new_condition = condition.compile(names) if var_count == 0: value = new_condition.execute() if value: return r_table.set_rows_list(a_table.get_rows(copy=False)) return r_table a_table_rows, a_table_rows_map_list = a_table.get_rows(copy=False), a_table.get_rows_map_list(names) for a_table_row, a_table_row_map in zip(a_table_rows, a_table_rows_map_list): if new_condition.execute(a_table_row_map): r_table.add_row_list(a_table_row, copy=False) return r_table
def _a_right_join_b_on_condition(a_table: Table, b_table: Table, r_table: Table, names, condition: Expr): a_table_rows, b_table_rows = a_table.get_rows(), b_table.get_rows() a_table_rows_map_list, b_table_rows_map_list = a_table.get_rows_map_list(names), b_table.get_rows_map_list(names) for b_table_row, b_table_row_map in zip(b_table_rows, b_table_rows_map_list): find = False for a_table_row, a_table_row_map in zip(a_table_rows, a_table_rows_map_list): values = a_table_row_map.copy() values.update(b_table_row_map) if not condition.execute(values): continue new_row = a_table_row.copy() new_row.extend(b_table_row) r_table.add_row_list(new_row) if not find: new_row = b_table_row.copy() r_table.add_row_list(new_row, header=True) return r_table
def execute(self, a_table: Table): if a_table.empty(): return a_table all_rows = a_table.get_rows(copy=False) rows_expr_res, asc_infos = self._get_rows_expr_res_and_asc_info(a_table) rows_expr_res = self._sort(rows_expr_res, asc_infos) new_rows = self._get_rows_by_order(rows_expr_res, all_rows) a_table.clear() a_table.set_rows_list(new_rows) return a_table
def execute(self, a_table: Table): rows = a_table.get_rows(copy=False) columns_len = len(a_table.columns) grouped_rows = _group_rows(rows, 0, columns_len - 1) # 选择每个组的第一条 new_rows = [] for rows in grouped_rows: new_rows.append(rows[0]) a_table.clear() a_table.set_rows_list(new_rows) return a_table
def execute(self, a_table: Table): if a_table.empty(): return a_table all_rows = a_table.get_rows(copy=False) rows_expr_res, asc_infos = self._get_rows_expr_res_and_asc_info(a_table) rows_expr_res = self._sort(rows_expr_res, asc_infos) grouped_orders = _group_rows(rows_expr_res, 0, len(self._order_items) - 1) grouped_rows = self._get_grouped_rows_by_order(grouped_orders, all_rows) a_table.clear() a_table.set_rows_list(grouped_rows) return a_table
def execute(self, r_table: Table): new_table = Table(table_name=r_table.table_name, columns=r_table.columns) table_rows = r_table.get_rows(self._limit, self._offset) for table_row in table_rows: new_table.add_row_list(table_row, copy=False) return new_table
def _a_right_join_b_false(b_table: Table, r_table: Table): b_table_rows = b_table.get_rows() for b_table_row in b_table_rows: r_table.add_row_list(b_table_row, header=True) return r_table
def _a_left_join_b_false(a_table: Table, r_table: Table): a_table_rows = a_table.get_rows() for a_table_row in a_table_rows: r_table.add_row_list(a_table_row) return r_table