提交 3040c387 编写于 作者: L Larry Hamel 提交者: Nadeem Ghani

Whitespace reformat and handle lint warnings

Signed-off-by: NNadeem Ghani <nghani@pivotal.io>
Signed-off-by: NLarry Hamel <lhamel@pivotal.io>
上级 a14fa2f5
此差异已折叠。
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -4,6 +4,7 @@ import shutil
from gppylib.db import dbconn
from test.behave_utils.utils import check_schema_exists, check_table_exists, drop_table_if_exists
from gppylib.operations.backup_utils import get_lines_from_file
from behave import given, when, then
CREATE_MULTI_PARTITION_TABLE_SQL = """
CREATE TABLE %s.%s (trans_id int, date date, amount decimal(9,2), region text)
......@@ -32,6 +33,7 @@ EVERY (INTERVAL '1 day'),
DEFAULT PARTITION default_dates);
"""
@given('there is a regular "{storage_type}" table "{tablename}" with column name list "{col_name_list}" and column type list "{col_type_list}" in schema "{schemaname}"')
def impl(context, storage_type, tablename, col_name_list, col_type_list, schemaname):
schemaname_no_quote = schemaname
......@@ -41,7 +43,8 @@ def impl(context, storage_type, tablename, col_name_list, col_type_list, scheman
raise Exception("Schema %s does not exist in database %s" % (schemaname_no_quote, context.dbname))
drop_table_if_exists(context, '.'.join([schemaname, tablename]), context.dbname)
create_table_with_column_list(context.conn, storage_type, schemaname, tablename, col_name_list, col_type_list)
check_table_exists(context, context.dbname, '.'.join([schemaname, tablename]), table_type = storage_type)
check_table_exists(context, context.dbname, '.'.join([schemaname, tablename]), table_type=storage_type)
@given('there is a hard coded ao partition table "{tablename}" with 4 child partitions in schema "{schemaname}"')
def impl(context, tablename, schemaname):
......@@ -50,16 +53,19 @@ def impl(context, tablename, schemaname):
drop_table_if_exists(context, '.'.join([schemaname, tablename]), context.dbname)
dbconn.execSQL(context.conn, CREATE_PARTITION_TABLE_SQL % (schemaname, tablename))
context.conn.commit()
check_table_exists(context, context.dbname, '.'.join([schemaname, tablename]), table_type = 'ao')
check_table_exists(context, context.dbname, '.'.join([schemaname, tablename]), table_type='ao')
@given('there is a hard coded multi-level ao partition table "{tablename}" with 4 mid-level and 16 leaf-level partitions in schema "{schemaname}"')
@given(
'there is a hard coded multi-level ao partition table "{tablename}" with 4 mid-level and 16 leaf-level partitions in schema "{schemaname}"')
def impl(context, tablename, schemaname):
if not check_schema_exists(context, schemaname, context.dbname):
raise Exception("Schema %s does not exist in database %s" % (schemaname, context.dbname))
drop_table_if_exists(context, '.'.join([schemaname, tablename]), context.dbname)
dbconn.execSQL(context.conn, CREATE_MULTI_PARTITION_TABLE_SQL % (schemaname, tablename))
context.conn.commit()
check_table_exists(context, context.dbname, '.'.join([schemaname, tablename]), table_type = 'ao')
check_table_exists(context, context.dbname, '.'.join([schemaname, tablename]), table_type='ao')
@given('no state files exist for database "{dbname}"')
def impl(context, dbname):
......@@ -68,47 +74,55 @@ def impl(context, dbname):
if os.path.exists(analyze_dir):
shutil.rmtree(analyze_dir)
@given('a view "{view_name}" exists on table "{table_name}" in schema "{schema_name}"')
def impl(context, view_name, table_name, schema_name):
create_view_on_table(context.conn, schema_name, table_name, view_name)
@given('"{qualified_table}" appears in the latest state files')
@then('"{qualified_table}" should appear in the latest state files')
def impl(context, qualified_table):
found,filename = table_found_in_state_file(context.dbname, qualified_table)
found, filename = table_found_in_state_file(context.dbname, qualified_table)
if not found:
if filename == '':
assert False, "no state files found for database %s" % context.dbname
else:
assert False, "table %s not found in state file %s" % (qualified_table, os.path.basename(filename))
@given('columns "{col_name_list}" of table "{qualified_table}" appear in the latest column state file')
@then('columns "{col_name_list}" of table "{qualified_table}" should appear in the latest column state file')
def impl(context, col_name_list, qualified_table):
found,column,filename = column_found_in_state_file(context.dbname, qualified_table, col_name_list)
found, column, filename = column_found_in_state_file(context.dbname, qualified_table, col_name_list)
if not found:
if filename == '':
assert False, "no column state file found for database %s" % context.dbname
else:
assert False, "column(s) %s of table %s not found in state file %s" % (column, qualified_table, os.path.basename(filename))
assert False, "column(s) %s of table %s not found in state file %s" % (
column, qualified_table, os.path.basename(filename))
@given('column "{col_name}" of table "{qualified_table}" does not appear in the latest column state file')
@then('column "{col_name}" of table "{qualified_table}" should not appear in the latest column state file')
def impl(context, col_name, qualified_table):
found,column,filename = column_found_in_state_file(context.dbname, qualified_table, col_name)
found, column, filename = column_found_in_state_file(context.dbname, qualified_table, col_name)
if found:
if filename == '':
assert False, "no column state file found for database %s" % context.dbname
else:
assert False, "unexpected column %s of table %s found in state file %s" % (column, qualified_table, os.path.basename(filename))
assert False, "unexpected column %s of table %s found in state file %s" % (
column, qualified_table, os.path.basename(filename))
@given('"{qualified_table}" appears in the latest report file')
@then('"{qualified_table}" should appear in the latest report file')
def impl(context, qualified_table):
found,filename = table_found_in_report_file(context.dbname, qualified_table)
found, filename = table_found_in_report_file(context.dbname, qualified_table)
if not found:
assert False, "table %s not found in report file %s" % (qualified_table, os.path.basename(filename))
@then('output should contain either "{output1}" or "{output2}"')
def impl(context, output1, output2):
pat1 = re.compile(output1)
......@@ -117,6 +131,7 @@ def impl(context, output1, output2):
err_str = "Expected stdout string '%s' or '%s', but found:\n'%s'" % (output1, output2, context.stdout_message)
raise Exception(err_str)
@then('output should not contain "{output1}"')
def impl(context, output1):
pat1 = re.compile(output1)
......@@ -124,6 +139,7 @@ def impl(context, output1):
err_str = "Unexpected stdout string '%s', found:\n'%s'" % (output1, context.stdout_message)
raise Exception(err_str)
@then('output should contain both "{output1}" and "{output2}"')
def impl(context, output1, output2):
pat1 = re.compile(output1)
......@@ -132,26 +148,30 @@ def impl(context, output1, output2):
err_str = "Expected stdout string '%s' and '%s', but found:\n'%s'" % (output1, output2, context.stdout_message)
raise Exception(err_str)
@given('table "{qualified_table}" does not appear in the latest state files')
def impl(context, qualified_table):
found,filename = table_found_in_state_file(context.dbname, qualified_table)
found, filename = table_found_in_state_file(context.dbname, qualified_table)
if found:
delete_table_from_state_files(context.dbname, qualified_table)
@given('some data is inserted into table "{tablename}" in schema "{schemaname}" with column type list "{column_type_list}"')
@when('some data is inserted into table "{tablename}" in schema "{schemaname}" with column type list "{column_type_list}"')
def impl(context, tablename, schemaname, column_type_list):
insert_data_into_table(context.conn, schemaname, tablename, column_type_list)
@given('some ddl is performed on table "{tablename}" in schema "{schemaname}"')
def impl(context, tablename, schemaname):
perform_ddl_on_table(context.conn, schemaname, tablename)
def table_found_in_state_file(dbname, qualified_table):
comma_name = ','.join(qualified_table.split('.'))
files = get_latest_analyze_state_files(dbname)
if len(files) == 0:
return False,""
return False, ""
state_file = ""
for state_file in files:
found = False
......@@ -160,46 +180,49 @@ def table_found_in_state_file(dbname, qualified_table):
found = True
continue
if not found:
return False,state_file
return True,state_file
return False, state_file
return True, state_file
def table_found_in_report_file(dbname, qualified_table):
report_file = get_latest_analyze_report_file(dbname)
found = False
for line in get_lines_from_file(report_file):
if qualified_table == line:
return True,report_file
return True, report_file
return False, report_file
return False,report_file
def column_found_in_state_file(dbname, qualified_table, col_name_list):
comma_name = ','.join(qualified_table.split('.'))
files = get_latest_analyze_state_files(dbname)
if len(files) == 0:
return False,"",""
return False, "", ""
for state_file in files:
if not "col_state_file" in state_file:
if "col_state_file" not in state_file:
continue
for line in get_lines_from_file(state_file):
if comma_name in line:
for column in col_name_list.split(','):
if not column in line.split(',')[2:]:
return False,column,state_file
return True,"",state_file
return False,col_name_list,state_file
if column not in line.split(',')[2:]:
return False, column, state_file
return True, "", state_file
return False, col_name_list, state_file
def delete_table_from_state_files(dbname, qualified_table):
comma_name = ','.join(qualified_table.split('.'))
files = get_latest_analyze_state_files(dbname)
for filename in files:
lines = get_lines_from_file(filename)
f = open(filename,"w")
f = open(filename, "w")
for line in lines:
if not comma_name in line:
if comma_name not in line:
f.write(line)
f.close()
def get_latest_analyze_state_files(dbname):
"""
return the latest state files (absolute paths)
......@@ -224,6 +247,7 @@ def get_latest_analyze_state_files(dbname):
ret.append(os.path.join(state_files_dir, f))
return ret
def get_latest_analyze_report_file(dbname):
"""
return the latest report file (absolute path)
......@@ -246,10 +270,11 @@ def get_latest_analyze_report_file(dbname):
raise Exception("Missing report file in folder %s" % report_file_dir)
def create_table_with_column_list(conn, storage_type, schemaname, tablename, col_name_list, col_type_list):
col_name_list = col_name_list.strip().split(',')
col_type_list = col_type_list.strip().split(',')
col_list = ' (' + ','.join(['%s %s' % (x,y) for x,y in zip(col_name_list,col_type_list)]) + ') '
col_list = ' (' + ','.join(['%s %s' % (x, y) for x, y in zip(col_name_list, col_type_list)]) + ') '
if storage_type.lower() == 'heap':
storage_str = ''
......@@ -264,6 +289,7 @@ def create_table_with_column_list(conn, storage_type, schemaname, tablename, col
dbconn.execSQL(conn, query)
conn.commit()
def insert_data_into_table(conn, schemaname, tablename, col_type_list):
col_type_list = col_type_list.strip().split(',')
col_str = ','.join(["(random()*i)::%s" % x for x in col_type_list])
......@@ -272,7 +298,6 @@ def insert_data_into_table(conn, schemaname, tablename, col_type_list):
conn.commit()
def perform_ddl_on_table(conn, schemaname, tablename):
query = "ALTER TABLE " + schemaname + '.' + tablename + " ADD COLUMN tempcol int default 0"
dbconn.execSQL(conn, query)
......@@ -280,7 +305,9 @@ def perform_ddl_on_table(conn, schemaname, tablename):
dbconn.execSQL(conn, query)
conn.commit()
def create_view_on_table(conn, schemaname, tablename, viewname):
query = "CREATE OR REPLACE VIEW " + schemaname + "." + viewname + " AS SELECT * FROM " + schemaname + "." + tablename
query = "CREATE OR REPLACE VIEW " + schemaname + "." + viewname + \
" AS SELECT * FROM " + schemaname + "." + tablename
dbconn.execSQL(conn, query)
conn.commit()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册