-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support kaggle sqlite * update * update * update
- Loading branch information
1 parent
a6211fc
commit bd2c531
Showing
11 changed files
with
189 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import re | ||
from typing import Callable, Optional, Tuple | ||
from triad.utils.assertion import assert_or_throw | ||
|
||
SQLITE_TABLE_REGEX = re.compile(r"([0-9a-zA-Z\-_]+\.sqlite3?)\.([0-9a-zA-Z\-_]+)") | ||
|
||
|
||
def transform_sqlite_sql( | ||
sql: str, validate: Callable[[str], None] | ||
) -> Tuple[str, Optional[str]]: | ||
tables = {m.group(1) for m in SQLITE_TABLE_REGEX.finditer(sql)} | ||
assert_or_throw( | ||
len(tables) <= 1, | ||
NotImplementedError("can't have multiple sources in one statement", tables), | ||
) | ||
if len(tables) > 0: | ||
validate(list(tables)[0]) | ||
return ( | ||
SQLITE_TABLE_REGEX.sub(r"\2", sql), | ||
None if len(tables) == 0 else list(tables)[0], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.0.6" | ||
__version__ = "0.0.7" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ pylint | |
pytest | ||
pytest-cov | ||
pytest-mock | ||
pytest-spark | ||
sphinx | ||
sphinx-rtd-theme | ||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from fuggle._utils import transform_sqlite_sql | ||
from pytest import raises | ||
from triad.utils.assertion import assert_or_throw | ||
|
||
|
||
def test_transform_sqlite_sql(): | ||
def should_not_call(s): | ||
raise ValueError | ||
|
||
assert ("", None) == transform_sqlite_sql("", should_not_call) | ||
assert ("x", "a.sqlite") == transform_sqlite_sql( | ||
"a.sqlite.x", lambda x: assert_or_throw("a.sqlite" == x) | ||
) | ||
assert ("b y ", "a.sqlite3") == transform_sqlite_sql( | ||
"b a.sqlite3.y ", lambda x: assert_or_throw("a.sqlite3" == x) | ||
) | ||
assert ("SELECT * FROM p INNER JOIN z", "a.sqlite3") == transform_sqlite_sql( | ||
"SELECT * FROM a.sqlite3.p INNER JOIN a.sqlite3.z", | ||
lambda x: assert_or_throw("a.sqlite3" == x), | ||
) | ||
# multiple source is not allowed | ||
with raises(NotImplementedError): | ||
transform_sqlite_sql( | ||
"SELECT * FROM a.sqlite.p INNER JOIN a.sqlite3.z", should_not_call | ||
) | ||
# validation failed | ||
with raises(AssertionError): | ||
transform_sqlite_sql( | ||
"b a.sqlite3.y ", lambda x: assert_or_throw("a.sqlite" == x) | ||
) |