MCPcopy Create free account
hub / github.com/apache/impala / migrate_db

Function migrate_db

tests/comparison/data_generator.py:64–81  ·  view source on GitHub ↗

Read table metadata and data from the source database and create a replica in the destination database. For example, the Impala functional test database could be copied into Postgresql.

(src_cursor, dst_cursor, include_table_names=None)

Source from the content-addressed store, hash-verified

62
63
64def migrate_db(src_cursor, dst_cursor, include_table_names=None):
65 '''Read table metadata and data from the source database and create a replica in
66 the destination database. For example, the Impala functional test database could
67 be copied into Postgresql.
68 '''
69 for table_name in src_cursor.list_table_names():
70 if include_table_names and table_name not in include_table_names:
71 continue
72 table = src_cursor.describe_table(table_name)
73 dst_cursor.create_table(table)
74 src_cursor.execute('SELECT * FROM ' + table_name)
75 while True:
76 rows = src_cursor.fetchmany(size=100)
77 if not rows:
78 break
79 sql = dst_cursor.make_insert_sql_from_data(table, rows)
80 dst_cursor.execute(sql)
81 index_tables_in_db_if_possible(dst_cursor)
82
83
84class DbPopulator(object):

Callers 1

data_generator.pyFile · 0.85

Calls 6

list_table_namesMethod · 0.80
describe_tableMethod · 0.45
create_tableMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected