Glue: Fix get_tables()-expression (#5533)
This commit is contained in:
parent
694ae84bc0
commit
951a271b49
@ -140,6 +140,15 @@ class GlueBackend(BaseBackend):
|
|||||||
def get_tables(self, database_name, expression):
|
def get_tables(self, database_name, expression):
|
||||||
database = self.get_database(database_name)
|
database = self.get_database(database_name)
|
||||||
if expression:
|
if expression:
|
||||||
|
# sanitise expression, * is treated as a glob-like wildcard
|
||||||
|
# so we make it a valid regex
|
||||||
|
if "*" in expression:
|
||||||
|
if expression.endswith(".*"):
|
||||||
|
expression = (
|
||||||
|
f"{expression[:-2].replace('*', '.*')}{expression[-2:]}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
expression = expression.replace("*", ".*")
|
||||||
return [
|
return [
|
||||||
table
|
table
|
||||||
for table_name, table in database.tables.items()
|
for table_name, table in database.tables.items()
|
||||||
|
@ -240,6 +240,8 @@ def test_get_tables_expression():
|
|||||||
"test_catchthis123_test",
|
"test_catchthis123_test",
|
||||||
"asduas6781catchthisasdas",
|
"asduas6781catchthisasdas",
|
||||||
"fakecatchthisfake",
|
"fakecatchthisfake",
|
||||||
|
"trailingtest.",
|
||||||
|
"trailingtest...",
|
||||||
]
|
]
|
||||||
table_inputs = {}
|
table_inputs = {}
|
||||||
|
|
||||||
@ -252,17 +254,55 @@ def test_get_tables_expression():
|
|||||||
postfix_expression = "\\w+_mytablepostfix"
|
postfix_expression = "\\w+_mytablepostfix"
|
||||||
string_expression = "\\w+catchthis\\w+"
|
string_expression = "\\w+catchthis\\w+"
|
||||||
|
|
||||||
|
# even though * is an invalid regex, sadly glue api treats it as a glob-like wildcard
|
||||||
|
star_expression1 = "*"
|
||||||
|
star_expression2 = "mytable*"
|
||||||
|
star_expression3 = "*table*"
|
||||||
|
star_expression4 = "*catch*is*"
|
||||||
|
star_expression5 = ".*catch*is*"
|
||||||
|
star_expression6 = "trailing*.*"
|
||||||
|
|
||||||
response_prefix = helpers.get_tables(client, database_name, prefix_expression)
|
response_prefix = helpers.get_tables(client, database_name, prefix_expression)
|
||||||
response_postfix = helpers.get_tables(client, database_name, postfix_expression)
|
response_postfix = helpers.get_tables(client, database_name, postfix_expression)
|
||||||
response_string_match = helpers.get_tables(client, database_name, string_expression)
|
response_string_match = helpers.get_tables(client, database_name, string_expression)
|
||||||
|
response_star_expression1 = helpers.get_tables(
|
||||||
|
client, database_name, star_expression1
|
||||||
|
)
|
||||||
|
response_star_expression2 = helpers.get_tables(
|
||||||
|
client, database_name, star_expression2
|
||||||
|
)
|
||||||
|
response_star_expression3 = helpers.get_tables(
|
||||||
|
client, database_name, star_expression3
|
||||||
|
)
|
||||||
|
response_star_expression4 = helpers.get_tables(
|
||||||
|
client, database_name, star_expression4
|
||||||
|
)
|
||||||
|
response_star_expression5 = helpers.get_tables(
|
||||||
|
client, database_name, star_expression5
|
||||||
|
)
|
||||||
|
response_star_expression6 = helpers.get_tables(
|
||||||
|
client, database_name, star_expression6
|
||||||
|
)
|
||||||
|
|
||||||
tables_prefix = response_prefix["TableList"]
|
tables_prefix = response_prefix["TableList"]
|
||||||
tables_postfix = response_postfix["TableList"]
|
tables_postfix = response_postfix["TableList"]
|
||||||
tables_string_match = response_string_match["TableList"]
|
tables_string_match = response_string_match["TableList"]
|
||||||
|
tables_star_expression1 = response_star_expression1["TableList"]
|
||||||
|
tables_star_expression2 = response_star_expression2["TableList"]
|
||||||
|
tables_star_expression3 = response_star_expression3["TableList"]
|
||||||
|
tables_star_expression4 = response_star_expression4["TableList"]
|
||||||
|
tables_star_expression5 = response_star_expression5["TableList"]
|
||||||
|
tables_star_expression6 = response_star_expression6["TableList"]
|
||||||
|
|
||||||
tables_prefix.should.have.length_of(2)
|
tables_prefix.should.have.length_of(2)
|
||||||
tables_postfix.should.have.length_of(1)
|
tables_postfix.should.have.length_of(1)
|
||||||
tables_string_match.should.have.length_of(3)
|
tables_string_match.should.have.length_of(3)
|
||||||
|
tables_star_expression1.should.have.length_of(8)
|
||||||
|
tables_star_expression2.should.have.length_of(2)
|
||||||
|
tables_star_expression3.should.have.length_of(3)
|
||||||
|
tables_star_expression4.should.have.length_of(3)
|
||||||
|
tables_star_expression5.should.have.length_of(3)
|
||||||
|
tables_star_expression6.should.have.length_of(2)
|
||||||
|
|
||||||
|
|
||||||
@mock_glue
|
@mock_glue
|
||||||
|
Loading…
Reference in New Issue
Block a user