def test_601_with_trucate_true(): "601 gpload with truncate is true" file = mkpath('setup.sql') runfile(file) f = open(mkpath('query601.sql'), 'a') f.write("\\! psql -d reuse_gptest -c 'select count(*) from testtruncate;'") f.close() copy_data('external_file_04.txt', 'data_file.txt') write_config_file(mode='insert', reuse_tables=False, fast_match=False, file='data_file.txt', table='testtruncate', error_limit=1002, truncate=True)
def test_602_with_reuse_tables_true(): "602 gpload with reuse_tables is true" drop_tables() file = mkpath('setup.sql') runfile(file) f = open(mkpath('query602.sql'), 'a') f.write( "\\! psql -d reuse_gptest -c \"SELECT count(*) from pg_class WHERE relname like 'ext_gpload_reusable%' OR relname like 'staging_gpload_reusable%';\"" ) f.close() copy_data('external_file_04.txt', 'data_file.txt') write_config_file(mode='insert', reuse_tables=True, fast_match=False, file='data_file.txt', table='texttable', error_limit=1002, truncate=False)
def test_662_gpload_sql_after_fail(): "662 gpload fails to execute `after sql`" file = mkpath('setup.sql') runfile(file) f = open(mkpath('query661.sql'), 'a') f.write("\\! psql -d reuse_gptest -c 'SELECT * FROM test_662'") f.write("\\! psql -d reuse_gptest -c 'SELECT COUNT(*) texttable_662'\n") f.close() sql = '''CREATE TABLE texttable_662 ( s1 text, s2 text, s3 text, dt timestamp, n1 smallint, n2 integer, n3 bigint, n4 decimal, n5 numeric, n6 real, n7 double precision) DISTRIBUTED BY (n1);''' (ok, out) = psql_run(cmd=sql, dbname='reuse_gptest') if not ok: raise Exception("Unable to execute sql %s" % out) write_config_file(format='text', table='texttable_662', sql=True, after="INSERT INTO test_662 VALUES(1)")
def test_651_gpload_sql_before_success(): "651 gpload executes `before sql` successfully" file = mkpath('setup.sql') runfile(file) f = open(mkpath('query651.sql'), 'a') f.write("\\! psql -d reuse_gptest -c 'SELECT COUNT(*) FROM test_651'") f.close() sql = '''CREATE TABLE texttable_651 ( s1 text, s2 text, s3 text, dt timestamp, n1 smallint, n2 integer, n3 bigint, n4 decimal, n5 numeric, n6 real, n7 double precision) DISTRIBUTED BY (n1); CREATE TABLE test_651 (c1 int);''' (ok, out) = psql_run(cmd=sql, dbname='reuse_gptest') if not ok: raise Exception("Unable to execute sql %s" % out) write_config_file(format='text', table='texttable_651', sql=True, before="INSERT INTO test_651 VALUES(1)")
def test_652_gpload_sql_before_fail(): "652 gpload fails to execute `before sql`" file = mkpath('setup.sql') runfile(file) sql = '''CREATE TABLE texttable_652 (c1 int);''' (ok, out) = psql_run(cmd=sql, dbname='reuse_gptest') if not ok: raise Exception("Unable to execute sql %s" % out) write_config_file(format='text', table='texttable_652', sql=True, before="INSERT INTO test_652 VALUES(1)")
def test_608_gpload_ext_staging_table(): "608 gpload ignore staging_table if the reuse is false" file = mkpath('setup.sql') runfile(file) copy_data('external_file_13.csv', 'data_file.csv') write_config_file(reuse_tables=False, format='csv', file='data_file.csv', table='csvtable', delimiter="','", log_errors=True, error_limit=10, staging_table='staging_table')
def test_653_gpload_sql_before_creating_table(): "653 gpload creates target table in `before sql`" # Actually, gpload doesn't support doing this # as it firstly checks if the target table exists, # then executes the 'before sql' file = mkpath('setup.sql') runfile(file) sql = '''CREATE TABLE texttable_653 (c1 int);''' write_config_file(format='text', table='texttable_653', sql=True, before=sql)
def test_665_gpload_sql_before_after(): "665 gpload's before and after not in a transaction, after sql fails" file = mkpath('setup.sql') runfile(file) f = open(mkpath('query665.sql'), 'a') f.write("\\! psql -d reuse_gptest -c 'SELECT * FROM test_665_before'\n") f.write("\\! psql -d reuse_gptest -c 'SELECT * FROM test_665_after'\n") f.write( "\\! psql -d reuse_gptest -c 'SELECT COUNT(*) FROM texttable_665'\n") f.close() sql = '''CREATE TABLE texttable_665 ( s1 text, s2 text, s3 text, dt timestamp, n1 smallint, n2 integer, n3 bigint, n4 decimal, n5 numeric, n6 real, n7 double precision) DISTRIBUTED BY (n1); CREATE TABLE test_665_before (c1 int); CREATE TABLE test_665_after (c1 int);''' (ok, out) = psql_run(cmd=sql, dbname='reuse_gptest') if not ok: raise Exception("Unable to execute sql %s" % out) write_config_file(format='text', table='texttable_665', sql=True, before="INSERT INTO test_665_before VALUES(1)", after="INSERT INTO test_665_after VALUES('a')")
def test_607_clear_database(): "drop tables in database and recreate them to clear the environment" file = mkpath('setup.sql') runfile(file)