Skip to content

Commit

Permalink
Added changes to regex pattern to include hyphen
Browse files Browse the repository at this point in the history
  • Loading branch information
souravg-db2 committed Dec 22, 2023
1 parent e8d5d28 commit 7437f7b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion discoverx/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class DataExplorer:
FROM_COMPONENTS_EXPR = r"^(([0-9a-zA-Z_\*]+)\.([0-9a-zA-Z_\*]+)\.([0-9a-zA-Z_\*]+))$"
FROM_COMPONENTS_EXPR = r"^(([0-9a-zA-Z_\*-]+)\.([0-9a-zA-Z_\*-]+)\.([0-9a-zA-Z_\*-]+))$"

def __init__(self, from_tables, spark: SparkSession, info_fetcher: InfoFetcher) -> None:
self._from_tables = from_tables
Expand Down
4 changes: 2 additions & 2 deletions discoverx/msql.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class SQLRow:
class Msql:
"""This class compiles M-SQL expressions into regular SQL"""

from_statement_expr = r"(FROM\s+)(([0-9a-zA-Z_\*]+).([0-9a-zA-Z_\*]+).([0-9a-zA-Z_\*]+))"
from_components_expr = r"^(([0-9a-zA-Z_\*]+).([0-9a-zA-Z_\*]+).([0-9a-zA-Z_\*]+))$"
from_statement_expr = r"(FROM\s+)(([0-9a-zA-Z_\*-]+).([0-9a-zA-Z_\*-]+).([0-9a-zA-Z_\*-]+))"
from_components_expr = r"^(([0-9a-zA-Z_\*-]+).([0-9a-zA-Z_\*-]+).([0-9a-zA-Z_\*-]+))$"
command_expr = r"^\s*(\w+)\s"
class_regex = r"\[([\w_-]+)\]"
valid_commands = ["SELECT", "DELETE"]
Expand Down
1 change: 1 addition & 0 deletions tests/unit/msql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def test_execute_sql_should_fail_for_no_successful_queries(spark):
def test_validate_from_components():
assert Msql.validate_from_components("c.d.t") == ("c", "d", "t")
assert Msql.validate_from_components("*.*.*") == ("*", "*", "*")
assert Msql.validate_from_components("c-1.d.t-1") == ("c-1", "d", "t-1")

with pytest.raises(ValueError):
Msql.validate_from_components("c.d")
Expand Down

0 comments on commit 7437f7b

Please sign in to comment.