示例#1
0
 def map_table(self, merged_table, mapper):
     copied_column = [i.clone() for i in merged_table.columns]
     input_type = namedtuple("input", [c.program_name for c in merged_table.columns])
     kidx, mapped_column = mapper[0](copied_column)
     names = set()
     for mc in mapped_column:
         dup = mc.program_name in names
         if dup:
             logger.fatal("duplicated column names")
             assert mc.program_name not in names
         names.add(mc.program_name)
     output_type = build_record([c.program_name for c in mapped_column])
     mapping = self.get_index_mapping(mapped_column, merged_table.columns)
     mapped_table = Table()
     mapped_table.key_column = kidx
     mapped_table.columns = mapped_column
     tmp_matrix = []
     for row in merged_table.matrix:
         input_row = input_type(*row)
         output_list = [None if i is None else row[i] for i in mapping]
         output_row = output_type(output_list)
         preserve = mapper[1](output_row, input_row)
         if preserve:
             # mapped_table.matrix.append(output_row.to_tuple())
             tmp_matrix.append(output_row)
     mapper[2](tmp_matrix)
     for row in tmp_matrix:
         mapped_table.matrix.append(row.to_tuple())
     return mapped_table
示例#2
0
 def map_table(self, merged_table, mapper):
     copied_column = [i.clone() for i in merged_table.columns]
     input_type = namedtuple("input",
                             [c.program_name for c in merged_table.columns])
     kidx, mapped_column = mapper[0](copied_column)
     names = set()
     for mc in mapped_column:
         dup = mc.program_name in names
         if dup:
             logger.fatal("duplicated column names")
             assert (mc.program_name not in names)
         names.add(mc.program_name)
     output_type = build_record([c.program_name for c in mapped_column])
     mapping = self.get_index_mapping(mapped_column, merged_table.columns)
     mapped_table = Table()
     mapped_table.key_column = kidx
     mapped_table.columns = mapped_column
     tmp_matrix = []
     for row in merged_table.matrix:
         input_row = input_type(*row)
         output_list = [None if i is None else row[i] for i in mapping]
         output_row = output_type(output_list)
         preserve = mapper[1](output_row, input_row)
         if preserve:
             #mapped_table.matrix.append(output_row.to_tuple())
             tmp_matrix.append(output_row)
     mapper[2](tmp_matrix)
     for row in tmp_matrix:
         mapped_table.matrix.append(row.to_tuple())
     return mapped_table