Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/run-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
pip install pyparsing
pip install sqlean.py
- name: black
if: matrix.python-version != '3.9'
run: |
pip install black
black --check pydynamodb
Expand Down
1 change: 0 additions & 1 deletion pydynamodb/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .error import NotSupportedError
from .util import RetryConfig, retry_api_call


if TYPE_CHECKING:
from botocore.client import BaseClient

Expand Down
1 change: 1 addition & 0 deletions pydynamodb/sql/ddl_alter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
SSESpecification.KMSMasterKeyId $$$$$$$$
TableClass STANDARD_INFREQUENT_ACCESS
"""

import logging
from .ddl_sql import DdlBase
from .common import KeyWords, Tokens
Expand Down
1 change: 1 addition & 0 deletions pydynamodb/sql/ddl_drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
DROP GLOBAL TABLE Issues
ReplicationGroup (us-east-1, us-west-2)
"""

import logging
from .ddl_sql import DdlBase
from .common import KeyWords, Tokens
Expand Down
1 change: 1 addition & 0 deletions pydynamodb/sql/dml_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

DELETE FROM "Music" WHERE "Artist" = 'Acme Band' AND "SongTitle" = 'PartiQL Rocks' RETURNING ALL OLD *
"""

import logging
from .dml_sql import DmlBase
from .common import KeyWords, Tokens
Expand Down
1 change: 1 addition & 0 deletions pydynamodb/sql/dml_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
------------------------
INSERT INTO "Music" value {'Artist' : 'Acme Band','SongTitle' : 'PartiQL Rocks'}
"""

import logging
from .dml_sql import DmlBase
from .common import KeyWords, Tokens
Expand Down
1 change: 1 addition & 0 deletions pydynamodb/sql/dml_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
ConsistentRead False
ReturnConsumedCapacity NONE
"""

import logging
import re
from abc import ABCMeta
Expand Down
12 changes: 6 additions & 6 deletions pydynamodb/sql/dml_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ def __escape_column(self, token: Any) -> str:

def __init__(self, statement: str) -> None:
super().__init__(statement)
self._where_conditions = []
self._parsed_where_conditions = []
self._limit = None
self._consistent_read = False
self._return_consumed_capacity = "NONE"

@property
def where_conditions(self) -> List[Optional[str]]:
return self._where_conditions
return self._parsed_where_conditions

@property
def limit(self) -> int:
Expand All @@ -166,18 +166,18 @@ def transform(self) -> Dict[str, Any]:
def _construct_where_conditions(self, where_conditions: List[Any]) -> str:
for condition in where_conditions:
if not isinstance(condition, ParseResults):
self._where_conditions.append(str(condition))
self._parsed_where_conditions.append(str(condition))
else:
function_ = condition.get("function", None)
function_with_op_ = condition.get("function_with_op", None)
if function_:
flatted_func_params = ",".join(condition["function_params"])
self._where_conditions.append(
self._parsed_where_conditions.append(
"%s(%s)" % (function_, flatted_func_params)
)
elif function_with_op_:
flatted_func_params = ",".join(condition["function_params"])
self._where_conditions.append(
self._parsed_where_conditions.append(
"%s(%s) %s %s"
% (
function_with_op_,
Expand All @@ -191,7 +191,7 @@ def _construct_where_conditions(self, where_conditions: List[Any]) -> str:
flatted_where = " ".join(
str(c) for c in flatten_list(where_conditions_)
)
self._where_conditions.append(flatted_where)
self._parsed_where_conditions.append(flatted_where)

return "WHERE %s" % " ".join(self.where_conditions)

Expand Down
1 change: 1 addition & 0 deletions pydynamodb/sql/dml_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
REMOVE AwardDetail.Grammys[2]
WHERE Artist='Acme Band' AND SongTitle='PartiQL Rocks'
"""

import logging
from .dml_sql import DmlBase
from .json_parser import jsonArray, jsonObject
Expand Down
30 changes: 0 additions & 30 deletions pydynamodb/sql/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,6 @@
# members optional in array and object collections
#
# Updated 9 Aug 2016 - use more current pyparsing constructs/idioms
#
'''
json_bnf = """
object
{ members }
{}
members
string : value
members , string : value
array
[ elements ]
[]
elements
value
elements , value
value
string
number
object
array
true
false
null
"""
'''

import pyparsing as pp
from pyparsing import pyparsing_common as ppc
Expand Down Expand Up @@ -61,11 +36,6 @@ def make_keyword(kwd_str, kwd_value):
jsonValue = pp.Forward().set_name("jsonValue")

jsonElements = pp.DelimitedList(jsonValue).set_name(None)
# jsonArray = pp.Group(LBRACK + pp.Optional(jsonElements, []) + RBRACK)
# jsonValue << (
# jsonString | jsonNumber | pp.Group(jsonObject) | jsonArray | TRUE | FALSE | NULL
# )
# memberDef = pp.Group(jsonString + COLON + jsonValue).set_name("jsonMember")

jsonArray = pp.Group(
LBRACK + pp.Optional(jsonElements) + RBRACK, aslist=RETURN_PYTHON_COLLECTIONS
Expand Down
6 changes: 3 additions & 3 deletions pydynamodb/sql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .dml_update import DmlUpdate
from .dml_delete import DmlDelete
from .util_sql import UtilListTables, UtilDescTable
from typing import Any, Dict, Tuple
from typing import Any, Dict, Tuple, Type, Optional

_logger = logging.getLogger(__name__) # type: ignore

Expand Down Expand Up @@ -71,8 +71,8 @@ def parser(self) -> Base:

return self._parser

def _get_parse_class(self) -> Base:
_parse_class = None
def _get_parse_class(self) -> Optional[Type[Base]]:
_parse_class: Optional[Type[Base]] = None
if (
self.query_type == QueryType.CREATE
or self.query_type == QueryType.CREATE_GLOBAL
Expand Down
2 changes: 1 addition & 1 deletion pydynamodb/superset_dynamodb/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_config_value(config_name: str, **kwargs) -> Optional[Union[str, int]]:
return kwargs[config_name]
else:
if config_name in SUPPORTED_QUERYDB_CONFIG:
(env_name, default_val) = SUPPORTED_QUERYDB_CONFIG[config_name]
env_name, default_val = SUPPORTED_QUERYDB_CONFIG[config_name]
env_val = os.getenv(env_name, None)
if env_val is None:
return default_val
Expand Down
2 changes: 1 addition & 1 deletion pydynamodb/superset_dynamodb/pydynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def execute(self, **kwargs) -> None:
cursor.execute_statement(self._statement)
self._load_into_query_db(cursor.result_set)

(desc_, results_) = self._query_db.query()
desc_, results_ = self._query_db.query()
self._rows.extend(results_)
for d in desc_:
self._metadata.update(
Expand Down
3 changes: 1 addition & 2 deletions pydynamodb/superset_dynamodb/querydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ def add_cache(self) -> None:
"""INSERT INTO %s (query_id, statement,
created, last_updated, queried_times
) VALUES (?, ?, ?, ?, ?)
"""
% QueryDB.CACHE_TABLE,
""" % QueryDB.CACHE_TABLE,
(
self.query_id,
str(self.statement.api_request),
Expand Down
41 changes: 12 additions & 29 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
class TestConnection:
def test_transaction_both_read_write(self, conn):
try:
sql_trans_1_ = (
"""
sql_trans_1_ = """
INSERT INTO %s VALUE {
'key_partition': ?, 'key_sort': ?, 'col_str': ?, 'col_num': ?
}
"""
% TESTCASE01_TABLE
)
""" % TESTCASE01_TABLE

conn.begin()
with conn.cursor() as cursor:
Expand All @@ -33,8 +30,7 @@ def test_transaction_both_read_write(self, conn):
cursor.execute(
"""
SELECT * FROM %s WHERE key_partition = ?
"""
% TESTCASE01_TABLE,
""" % TESTCASE01_TABLE,
["test_trans_1"],
)

Expand All @@ -46,14 +42,11 @@ def test_transaction_both_read_write(self, conn):
assert len(self._query_data(cursor, "test_trans_1")) == 0

def test_transaction_one_row(self, conn):
sql_trans_2_ = (
"""
sql_trans_2_ = """
INSERT INTO %s VALUE {
'key_partition': ?, 'key_sort': ?, 'col_str': ?, 'col_num': ?
}
"""
% TESTCASE01_TABLE
)
""" % TESTCASE01_TABLE

conn.begin()
cursor = conn.cursor()
Expand All @@ -63,14 +56,11 @@ def test_transaction_one_row(self, conn):
assert len(self._query_data(cursor, "test_trans_2")) == 1

def test_transaction_many_row(self, conn):
sql_trans_3_ = (
"""
sql_trans_3_ = """
INSERT INTO %s VALUE {
'key_partition': ?, 'key_sort': ?, 'col_str': ?, 'col_num': ?
}
"""
% TESTCASE01_TABLE
)
""" % TESTCASE01_TABLE

conn.begin()
cursor = conn.cursor()
Expand All @@ -89,14 +79,11 @@ def test_transaction_many_row(self, conn):
assert len(self._query_data(cursor, "test_trans_3")) == 5

def test_transaction_mixed_no_trans(self, conn):
sql_trans_4_ = (
"""
sql_trans_4_ = """
INSERT INTO "%s" VALUE {
'key_partition': ?, 'key_sort': ?, 'col_str': ?, 'col_num': ?
}
"""
% TESTCASE01_TABLE
)
""" % TESTCASE01_TABLE

cursor = conn.cursor()
cursor.execute(sql_trans_4_, ["test_trans_4", 0, "test case 4-0", 0])
Expand Down Expand Up @@ -138,14 +125,11 @@ def test_transaction_mixed_no_trans(self, conn):

def test_batch_write_1(self, conn):
cursor = conn.cursor()
sql_batch_1_ = (
"""
sql_batch_1_ = """
INSERT INTO "%s" VALUE {
'key_partition': ?, 'key_sort': ?, 'col_str': ?, 'col_num': ?
}
"""
% TESTCASE01_TABLE
)
""" % TESTCASE01_TABLE
conn.autocommit = False
cursor.execute(sql_batch_1_, ["test_batch_1", 0, "test case 5-0", 0])
cursor.execute(sql_batch_1_, ["test_batch_1", 1, "test case 5-1", 1])
Expand Down Expand Up @@ -174,8 +158,7 @@ def _query_data(self, cursor, test_case):
cursor.execute(
"""
SELECT * FROM %s WHERE key_partition = ?
"""
% TESTCASE01_TABLE,
""" % TESTCASE01_TABLE,
[test_case],
)
return cursor.fetchall()
Expand Down
Loading