未验证 提交 b2e38f17 编写于 作者: H Huiliang.liu 提交者: GitHub

Fix external schema bug in fast_match (#5324)

- The results of fast_match SQL don't include shema name, so we need
add shema name to extSchemaTable for fast_match
- Remove locationStr which is unused.
上级 2dca8766
......@@ -2081,9 +2081,9 @@ class gpload:
# names and types
#
# This function will return the SQL to run in order to find out whether
# such a table exists.
# such a table exists. The results of this SQl are table names without schema
#
def get_fast_match_exttable_query(self, locationStr, formatType, formatOpts, limitStr, schemaName, log_errors):
def get_fast_match_exttable_query(self, formatType, formatOpts, limitStr, schemaName, log_errors):
sqlFormat = """select relname from pg_class
join
......@@ -2341,7 +2341,7 @@ class gpload:
# process the single quotes in order to successfully find an existing external table to reuse.
self.formatOpts = self.formatOpts.replace("E'\\''","'\''")
if self.fast_match:
sql = self.get_fast_match_exttable_query(locationStr, formatType, self.formatOpts,
sql = self.get_fast_match_exttable_query(formatType, self.formatOpts,
limitStr, self.extSchemaName, self.log_errors)
else:
sql = self.get_reuse_exttable_query(formatType, self.formatOpts,
......@@ -2351,7 +2351,11 @@ class gpload:
if len(resultList) > 0:
# found an external table to reuse. no need to create one. we're done here.
self.extTableName = (resultList[0])[0]
self.extSchemaTable = self.extTableName
# fast match result is only table name, so we need add schema info
if self.fast_match:
self.extSchemaTable = self.get_ext_schematable(quote_unident(self.extSchemaName), self.extTableName)
else:
self.extSchemaTable = self.extTableName
self.log(self.INFO, "reusing external table %s" % self.extSchemaTable)
return
......
......@@ -437,7 +437,7 @@ class GPLoad_FormatOpts_TestCase(unittest.TestCase):
def test_00_gpload_formatOpts_setup(self):
"0 gpload setup"
for num in range(1,33):
for num in range(1,34):
f = open(mkpath('query%d.sql' % num),'w')
f.write("\! gpload -f "+mkpath('config/config_file')+ " -d reuse_gptest\n"+"\! gpload -f "+mkpath('config/config_file')+ " -d reuse_gptest\n")
f.close()
......@@ -683,7 +683,7 @@ class GPLoad_FormatOpts_TestCase(unittest.TestCase):
def test_30_gpload_reuse_table_update_mode_with_fast_match(self):
"30 gpload update mode with fast match"
#drop_tables()
drop_tables()
copy_data('external_file_04.txt','data_file.txt')
write_config_file(mode='update',reuse_flag='true',fast_match='true',file='data_file.txt')
self.doTest(30)
......@@ -701,6 +701,13 @@ class GPLoad_FormatOpts_TestCase(unittest.TestCase):
copy_data('external_file_08.txt','data_file.txt')
write_config_file(mode='update',reuse_flag='false',fast_match='true',file='data_file.txt')
self.doTest(32)
def test_33_gpload_reuse_table_merge_mode_with_fast_match_and_external_schema(self):
"33 gpload update mode with fast match and external schema"
file = mkpath('setup.sql')
runfile(file)
copy_data('external_file_04.txt','data_file.txt')
write_config_file(mode='merge',reuse_flag='true',fast_match='true',file='data_file.txt',externalSchema='test')
self.doTest(33)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(GPLoad_FormatOpts_TestCase)
......
2018-07-24 06:14:29|INFO|gpload session started 2018-07-24 06:14:29
2018-07-24 06:14:29|INFO|setting schema 'public' for table 'texttable'
2018-07-24 06:14:29|INFO|started gpfdist -p 8081 -P 8082 -f "/home/gpadmin/workspace/gpdb/gpMgmt/bin/gpload_test/gpload2/data_file.txt" -t 30
2018-07-24 06:14:29|INFO|did not find a staging table to reuse. creating staging_gpload_reusable_afbaac0da7ced19791c9ab9c537f41d3
2018-07-24 06:14:29|INFO|did not find an external table to reuse. creating test.ext_gpload_reusable_d2e95f76_8f08_11e8_8c76_0242ac110002
2018-07-24 06:14:29|INFO|running time: 0.40 seconds
2018-07-24 06:14:29|INFO|rows Inserted = 16
2018-07-24 06:14:29|INFO|rows Updated = 0
2018-07-24 06:14:29|INFO|data formatting errors = 0
2018-07-24 06:14:29|INFO|gpload succeeded
2018-07-24 06:14:30|INFO|gpload session started 2018-07-24 06:14:30
2018-07-24 06:14:30|INFO|setting schema 'public' for table 'texttable'
2018-07-24 06:14:30|INFO|started gpfdist -p 8081 -P 8082 -f "/home/gpadmin/workspace/gpdb/gpMgmt/bin/gpload_test/gpload2/data_file.txt" -t 30
2018-07-24 06:14:30|INFO|reusing staging table staging_gpload_reusable_afbaac0da7ced19791c9ab9c537f41d3
2018-07-24 06:14:30|INFO|reusing external table test.ext_gpload_reusable_d2e95f76_8f08_11e8_8c76_0242ac110002
2018-07-24 06:14:30|INFO|running time: 0.31 seconds
2018-07-24 06:14:30|INFO|rows Inserted = 0
2018-07-24 06:14:30|INFO|rows Updated = 16
2018-07-24 06:14:30|INFO|data formatting errors = 0
2018-07-24 06:14:30|INFO|gpload succeeded
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册