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

Function prepare_database

tests/stress/concurrent_select.py:1079–1099  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1077
1078
1079def 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
1102def reset_databases(cursor):

Callers 1

mainFunction · 0.85

Calls 5

list_table_namesMethod · 0.80
describe_tableMethod · 0.45
debugMethod · 0.45
formatMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected