Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre committed Sep 19, 2023
2 parents 4db191e + 0e37db9 commit 69547f3
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 97 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.x

- name: Install black
run: |
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ jobs:
# https://github.com/actions/python-versions/blob/main/versions-manifest.json
# https://devguide.python.org/versions/#supported-versions
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -47,7 +46,7 @@ jobs:

# https://github.com/marketplace/actions/install-poetry-action
- name: Install Poetry
uses: snok/install-poetry@v1.3.3
uses: snok/install-poetry@v1.3.4
with:
version: 1.3.2
virtualenvs-create: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Poetry
uses: snok/install-poetry@v1.3.3
uses: snok/install-poetry@v1.3.4
with:
virtualenvs-create: true
virtualenvs-in-project: true
Expand Down
94 changes: 8 additions & 86 deletions poetry.lock

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

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ packages = [
]

[tool.poetry.dependencies]
python = "^3.7.2"
python = "^3.8"
sqlparse = "^0.4.1"

[tool.poetry.dev-dependencies]
black = "^23.3"
coverage = {extras = ["toml"], version = "^6.5"}
pylint = "^2.17.5"
pytest = "^7.4.0"
pytest = "^7.4.2"
pytest-cov = "^4.1.0"
coveralls = "^3.3.1"
flake8 = "^5.0.4"
Expand Down
8 changes: 7 additions & 1 deletion sql_metadata/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, sql: str = "", disable_logging: bool = False) -> None:
self._nested_level = 0
self._parenthesis_level = 0
self._open_parentheses: List[SQLToken] = []
self._preceded_keywords: List[SQLToken] = []
self._aliases_to_check = None
self._is_in_nested_function = False
self._is_in_with_block = False
Expand Down Expand Up @@ -124,7 +125,7 @@ def query_type(self) -> str:
return self._query_type

@property
def tokens(self) -> List[SQLToken]:
def tokens(self) -> List[SQLToken]: # noqa: C901
"""
Tokenizes the query
"""
Expand Down Expand Up @@ -164,6 +165,8 @@ def tokens(self) -> List[SQLToken]:
elif token.is_right_parenthesis:
token.token_type = TokenType.PARENTHESIS
self._determine_closing_parenthesis_type(token=token)
if token.is_subquery_end:
last_keyword = self._preceded_keywords.pop()

last_keyword = self._determine_last_relevant_keyword(
token=token, last_keyword=last_keyword
Expand Down Expand Up @@ -856,6 +859,7 @@ def _determine_opening_parenthesis_type(self, token: SQLToken):
# inside subquery / derived table
token.is_subquery_start = True
self._subquery_level += 1
self._preceded_keywords.append(token.last_keyword_normalized)
token.subquery_level = self._subquery_level
elif token.previous_token.normalized in KEYWORDS_BEFORE_COLUMNS.union({","}):
# we are in columns and in a column subquery definition
Expand Down Expand Up @@ -970,6 +974,8 @@ def replace_back_quotes_in_string(match):
return query

def _determine_last_relevant_keyword(self, token: SQLToken, last_keyword: str):
if token.value == "," and token.last_keyword_normalized == "ON":
return "FROM"
if token.is_keyword and "".join(token.normalized.split()) in RELEVANT_KEYWORDS:
if (
not (
Expand Down

0 comments on commit 69547f3

Please sign in to comment.