Skip to content

Commit

Permalink
Improve support for WHERE-clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers committed Oct 22, 2023
1 parent 68ec0b3 commit 5fdc68d
Show file tree
Hide file tree
Showing 9 changed files with 608 additions and 115 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

0.4.1
-----
- Increased support for WHERE-clauses:
1. Nested clauses
2. OR-clauses
3. Functions: attribute_type, IF (NOT) MISSING, comparison operators (<, >)

0.4.0
-----
- The DynamoDBStatementParser now expects a document in the DynamoDB format:
Expand Down
2 changes: 1 addition & 1 deletion py_partiql_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.4.0"
__version__ = "0.4.1"


from ._internal.parser import DynamoDBStatementParser, S3SelectParser # noqa
Expand Down
2 changes: 1 addition & 1 deletion py_partiql_parser/_internal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ def get_query_metadata(cls, query: str):
else:
where = None

return QueryMetadata(tables=from_clauses, where_clauses=where)
return QueryMetadata(tables=from_clauses, where_clause=where)
15 changes: 11 additions & 4 deletions py_partiql_parser/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from .case_insensitive_dict import CaseInsensitiveDict
from .json_parser import MissingVariable, Variable
from typing import Any, Dict, List, Tuple, Union
from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING

if TYPE_CHECKING:
from .where_parser import AbstractWhereClause


def is_dict(dct):
Expand Down Expand Up @@ -134,13 +137,17 @@ def find_value_in_dynamodb_document(keys: List[str], json_doc):

class QueryMetadata:
def __init__(
self, tables: Dict[str, str], where_clauses: List[Tuple[List[str], str]] = None
self,
tables: Dict[str, str],
where_clause: Optional["AbstractWhereClause"] = None,
):
self._tables = tables
self._where_clauses = where_clauses or []
self._where_clause = where_clause

def get_table_names(self) -> List[str]:
return list(self._tables.values())

def get_filter_names(self) -> List[str]:
return [".".join(keys) for keys, _ in self._where_clauses]
if self._where_clause:
return self._where_clause.get_filter_names()
return []
Loading

0 comments on commit 5fdc68d

Please sign in to comment.