For each table in the database that cursor is connected to, create an identical copy with '_original' suffix. This function is idempotent. Note: At this time we only support Kudu tables with a simple hash partitioning based on the primary key. (SHOW CREATE TABLE would not work otherwise.)
(cursor)
| 1077 | |
| 1078 | |
| 1079 | def prepare_database(cursor): |
| 1080 | """For each table in the database that cursor is connected to, create an identical copy |
| 1081 | with '_original' suffix. This function is idempotent. |
| 1082 | |
| 1083 | Note: At this time we only support Kudu tables with a simple hash partitioning based on |
| 1084 | the primary key. (SHOW CREATE TABLE would not work otherwise.) |
| 1085 | """ |
| 1086 | tables = dict((t, cursor.describe_table(t)) for t in cursor.list_table_names()) |
| 1087 | for table_name in tables: |
| 1088 | if not table_name.endswith("_original") and table_name + "_original" not in tables: |
| 1089 | LOG.debug("Creating original table: {0}".format(table_name)) |
| 1090 | cursor.execute("SHOW CREATE TABLE " + table_name) |
| 1091 | create_sql = cursor.fetchone()[0] |
| 1092 | search_pattern = r"CREATE TABLE (\w*)\.(.*) \(" |
| 1093 | replacement = "CREATE TABLE {tbl} (".format(tbl=table_name + "_original") |
| 1094 | create_original_sql = re.sub( |
| 1095 | search_pattern, replacement, create_sql, count=1) |
| 1096 | LOG.debug("Create original SQL:\n{0}".format(create_original_sql)) |
| 1097 | cursor.execute(create_original_sql) |
| 1098 | cursor.execute("INSERT INTO {0}_original SELECT * FROM {0}".format(table_name)) |
| 1099 | cursor.execute("COMPUTE STATS {0}".format(table_name + "_original")) |
| 1100 | |
| 1101 | |
| 1102 | def reset_databases(cursor): |
no test coverage detected