Skip to content

Commit

Permalink
Update keywords_lists.py (#428)
Browse files Browse the repository at this point in the history
* Update keywords_lists.py

Add HAVING keyword for column sections

* testing for HAVING keyword

* Update test/test_getting_columns.py

---------

Co-authored-by: Andy Tang <atang@spotify.com>
Co-authored-by: Maciej Brencz <maciej.brencz@gmail.com>
  • Loading branch information
3 people committed Sep 23, 2023
1 parent 67d8c36 commit c76aacb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sql_metadata/keywords_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
KEYWORDS_BEFORE_COLUMNS = {
"SELECT",
"WHERE",
"HAVING",
"ORDERBY",
"GROUPBY",
"ON",
Expand Down Expand Up @@ -55,6 +56,7 @@
COLUMNS_SECTIONS = {
"SELECT": "select",
"WHERE": "where",
"HAVING": "having",
"ORDERBY": "order_by",
"ON": "join",
"USING": "join",
Expand Down
16 changes: 16 additions & 0 deletions test/test_getting_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,19 @@ def test_aliases_switching_column_names():
parsed = Parser(query)
assert parsed.columns == ["a", "b"]
assert parsed.columns_dict == {"select": ["a", "b"]}


def test_having_columns():
query = """
SELECT Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;
"""
parsed = Parser(query)
assert parsed.columns == ["Country", "CustomerID"]
assert parsed.columns_dict == {
"select": ["Country"],
"group_by": ["Country"],
"having": ["CustomerID"],
}

0 comments on commit c76aacb

Please sign in to comment.