Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre authored Aug 26, 2024
2 parents d30ae5b + 3713f14 commit f41daa9
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.1.0
uses: dependabot/fetch-metadata@v2.2.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

# https://github.com/marketplace/actions/install-poetry-action
- name: Install Poetry
uses: snok/install-poetry@v1.3.4
uses: snok/install-poetry@v1.4.1
with:
version: latest
virtualenvs-create: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
python-version: '3.x'

- name: Install Poetry
uses: snok/install-poetry@v1.3.4
uses: snok/install-poetry@v1.4.1
with:
virtualenvs-create: true
virtualenvs-in-project: true
Expand Down
84 changes: 42 additions & 42 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ python = "^3.8"
sqlparse = ">=0.4.1,<0.6.0"

[tool.poetry.dev-dependencies]
black = "^24.4"
black = "^24.8"
coverage = {extras = ["toml"], version = "^6.5"}
pylint = "^3.2.3"
pytest = "^8.2.2"
pylint = "^3.2.6"
pytest = "^8.3.2"
pytest-cov = "^5.0.0"
coveralls = "^3.3.1"
flake8 = "^5.0.4"
Expand Down
2 changes: 2 additions & 0 deletions sql_metadata/keywords_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class QueryType(str, Enum):
CREATE = "CREATE TABLE"
ALTER = "ALTER TABLE"
DROP = "DROP TABLE"
TRUNCATE = "TRUNCATE TABLE"


class TokenType(str, Enum):
Expand Down Expand Up @@ -109,6 +110,7 @@ class TokenType(str, Enum):
"ALTERTABLE": QueryType.ALTER,
"DROPTABLE": QueryType.DROP,
"CREATEFUNCTION": QueryType.CREATE,
"TRUNCATETABLE": QueryType.TRUNCATE,
}

# all the keywords we care for - rest is ignored in assigning
Expand Down
2 changes: 1 addition & 1 deletion sql_metadata/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def query_type(self) -> str:
)
if tokens[index].normalized == "CREATE":
switch = self._get_switch_by_create_query(tokens, index)
elif tokens[index].normalized in ("ALTER", "DROP"):
elif tokens[index].normalized in ("ALTER", "DROP", "TRUNCATE"):
switch = tokens[index].normalized + tokens[index + 1].normalized
else:
switch = tokens[index].normalized
Expand Down
2 changes: 1 addition & 1 deletion sql_metadata/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def is_alias_without_as(self) -> bool:
"""
return (
self.next_token.normalized in [",", "FROM"]
and self.previous_token.normalized not in [",", ".", "(", "SELECT"]
and self.previous_token.normalized not in ["*", ",", ".", "(", "SELECT"]
and not self.previous_token.is_keyword
and (
self.last_keyword_normalized == "SELECT"
Expand Down
12 changes: 12 additions & 0 deletions test/test_column_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,15 @@ def test_cast_in_select_with_function():
"datekey": "testdb.test_table.date",
"starttimekey": "testdb.test_table.starttime",
}


def test_nested_function():
query = """
SELECT a * b
FROM c
WHERE b = (SELECT MAX(b) FROM c);
"""
parser = Parser(query)

assert parser.columns == ["a", "b"]
assert parser.tables == ["c"]
9 changes: 9 additions & 0 deletions test/test_truncate_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from sql_metadata import Parser
from sql_metadata.keywords_lists import QueryType


def test_truncate_table():
parser = Parser("TRUNCATE TABLE foo")
assert parser.query_type == QueryType.TRUNCATE
assert parser.tables == ["foo"]
assert parser.columns == []

0 comments on commit f41daa9

Please sign in to comment.