def testReadMapArraySQLInstance(self): test_table = tn('pyodps_t_tmp_read_map_array_sql_instance') self.odps.delete_table(test_table, if_exists=True) table = self.odps.create_table( test_table, schema=Schema.from_lists( ['idx', 'map_col', 'array_col'], [ 'bigint', odps_types.Map(odps_types.string, odps_types.string), odps_types.Array(odps_types.string) ], )) data = [ [ 0, { 'key1': 'value1', 'key2': 'value2' }, ['item1', 'item2', 'item3'] ], [1, { 'key3': 'value3', 'key4': 'value4' }, ['item4', 'item5']], ] self.odps.write_table(test_table, data) inst = self.odps.execute_sql('select * from %s' % test_table) with inst.open_reader(table.schema, use_tunnel=False) as reader: read_data = [list(r.values) for r in reader] read_data = sorted(read_data, key=lambda r: r[0]) expected_data = sorted(data, key=lambda r: r[0]) self.assertSequenceEqual(read_data, expected_data) with inst.open_reader(table.schema, use_tunnel=True) as reader: read_data = [list(r.values) for r in reader] read_data = sorted(read_data, key=lambda r: r[0]) expected_data = sorted(data, key=lambda r: r[0]) self.assertSequenceEqual(read_data, expected_data) table.drop()
def _gen_random_array_type(self): t = random.choice(['string', 'bigint', 'double', 'boolean']) return types.Array(t)