fix decoding keys in query condition
This commit is contained in:
parent
5a7c711a74
commit
2c50561563
@ -119,9 +119,9 @@ class Item(object):
|
|||||||
value = value.lstrip(":").rstrip(",")
|
value = value.lstrip(":").rstrip(",")
|
||||||
for k, v in expression_attribute_names.items():
|
for k, v in expression_attribute_names.items():
|
||||||
value = value.replace(k, v)
|
value = value.replace(k, v)
|
||||||
if action == "REMOVE" or action == 'remove':
|
if action == "REMOVE":
|
||||||
self.attrs.pop(value, None)
|
self.attrs.pop(value, None)
|
||||||
elif action == 'SET' or action == 'set':
|
elif action == 'SET':
|
||||||
key, value = value.split("=")
|
key, value = value.split("=")
|
||||||
key = key.strip()
|
key = key.strip()
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
@ -129,6 +129,8 @@ class Item(object):
|
|||||||
self.attrs[key] = DynamoType(expression_attribute_values[value])
|
self.attrs[key] = DynamoType(expression_attribute_values[value])
|
||||||
else:
|
else:
|
||||||
self.attrs[key] = DynamoType({"S": value})
|
self.attrs[key] = DynamoType({"S": value})
|
||||||
|
else:
|
||||||
|
raise NotImplementedError('{} update action not yet supported'.format(action))
|
||||||
|
|
||||||
def update_with_attribute_updates(self, attribute_updates):
|
def update_with_attribute_updates(self, attribute_updates):
|
||||||
for attribute_name, update_action in attribute_updates.items():
|
for attribute_name, update_action in attribute_updates.items():
|
||||||
@ -323,7 +325,6 @@ class Table(object):
|
|||||||
def query(self, hash_key, range_comparison, range_objs, limit,
|
def query(self, hash_key, range_comparison, range_objs, limit,
|
||||||
exclusive_start_key, scan_index_forward, index_name=None, **filter_kwargs):
|
exclusive_start_key, scan_index_forward, index_name=None, **filter_kwargs):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
if index_name:
|
if index_name:
|
||||||
all_indexes = (self.global_indexes or []) + (self.indexes or [])
|
all_indexes = (self.global_indexes or []) + (self.indexes or [])
|
||||||
indexes_by_name = dict((i['IndexName'], i) for i in all_indexes)
|
indexes_by_name = dict((i['IndexName'], i) for i in all_indexes)
|
||||||
|
@ -279,19 +279,22 @@ class DynamoHandler(BaseResponse):
|
|||||||
else:
|
else:
|
||||||
index = table.schema
|
index = table.schema
|
||||||
|
|
||||||
key_map = [column for _, column in sorted((k, v) for k, v in self.body['ExpressionAttributeNames'].items())]
|
reverse_attribute_lookup = {v: k for k, v in self.body['ExpressionAttributeNames'].iteritems()}
|
||||||
|
|
||||||
if " AND " in key_condition_expression:
|
if " AND " in key_condition_expression:
|
||||||
expressions = key_condition_expression.split(" AND ", 1)
|
expressions = key_condition_expression.split(" AND ", 1)
|
||||||
|
|
||||||
index_hash_key = [key for key in index if key['KeyType'] == 'HASH'][0]
|
index_hash_key = [key for key in index if key['KeyType'] == 'HASH'][0]
|
||||||
hash_key_index_in_key_map = key_map.index(index_hash_key['AttributeName'])
|
hash_key_var = reverse_attribute_lookup.get(index_hash_key['AttributeName'], index_hash_key['AttributeName'])
|
||||||
|
i, hash_key_expression = ((i, e) for i, e in enumerate(expressions) if re.search(r'[\s(]#n1\b'.format(hash_key_var), e)).next()
|
||||||
|
hash_key_expression = hash_key_expression.strip('()')
|
||||||
|
expressions.pop(i)
|
||||||
|
|
||||||
hash_key_expression = expressions.pop(hash_key_index_in_key_map).strip('()')
|
|
||||||
# TODO implement more than one range expression and OR operators
|
# TODO implement more than one range expression and OR operators
|
||||||
range_key_expression = expressions[0].strip('()')
|
range_key_expression = expressions[0].strip('()')
|
||||||
range_key_expression_components = range_key_expression.split()
|
range_key_expression_components = range_key_expression.split()
|
||||||
range_comparison = range_key_expression_components[1]
|
range_comparison = range_key_expression_components[1]
|
||||||
|
|
||||||
if 'AND' in range_key_expression:
|
if 'AND' in range_key_expression:
|
||||||
range_comparison = 'BETWEEN'
|
range_comparison = 'BETWEEN'
|
||||||
range_values = [
|
range_values = [
|
||||||
|
Loading…
Reference in New Issue
Block a user