Merge pull request #2583 from trilliput/issue/1996
Improve parsing DynamoDB begins_with expression
This commit is contained in:
commit
9f73a67cef
@ -438,9 +438,12 @@ class DynamoHandler(BaseResponse):
|
|||||||
all_indexes = (table.global_indexes or []) + (table.indexes or [])
|
all_indexes = (table.global_indexes or []) + (table.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)
|
||||||
if index_name not in indexes_by_name:
|
if index_name not in indexes_by_name:
|
||||||
raise ValueError(
|
er = "com.amazonaws.dynamodb.v20120810#ResourceNotFoundException"
|
||||||
"Invalid index: %s for table: %s. Available indexes are: %s"
|
return self.error(
|
||||||
% (index_name, name, ", ".join(indexes_by_name.keys()))
|
er,
|
||||||
|
"Invalid index: {} for table: {}. Available indexes are: {}".format(
|
||||||
|
index_name, name, ", ".join(indexes_by_name.keys())
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
index = indexes_by_name[index_name]["KeySchema"]
|
index = indexes_by_name[index_name]["KeySchema"]
|
||||||
@ -481,7 +484,9 @@ class DynamoHandler(BaseResponse):
|
|||||||
]
|
]
|
||||||
elif "begins_with" in range_key_expression:
|
elif "begins_with" in range_key_expression:
|
||||||
range_comparison = "BEGINS_WITH"
|
range_comparison = "BEGINS_WITH"
|
||||||
range_values = [value_alias_map[range_key_expression_components[1]]]
|
range_values = [
|
||||||
|
value_alias_map[range_key_expression_components[-1]]
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
range_values = [value_alias_map[range_key_expression_components[2]]]
|
range_values = [value_alias_map[range_key_expression_components[2]]]
|
||||||
else:
|
else:
|
||||||
|
@ -2630,6 +2630,44 @@ def test_scan_by_non_exists_index():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_query_by_non_exists_index():
|
||||||
|
dynamodb = boto3.client("dynamodb", region_name="us-east-1")
|
||||||
|
|
||||||
|
dynamodb.create_table(
|
||||||
|
TableName="test",
|
||||||
|
KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}],
|
||||||
|
AttributeDefinitions=[
|
||||||
|
{"AttributeName": "id", "AttributeType": "S"},
|
||||||
|
{"AttributeName": "gsi_col", "AttributeType": "S"},
|
||||||
|
],
|
||||||
|
ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
|
||||||
|
GlobalSecondaryIndexes=[
|
||||||
|
{
|
||||||
|
"IndexName": "test_gsi",
|
||||||
|
"KeySchema": [{"AttributeName": "gsi_col", "KeyType": "HASH"}],
|
||||||
|
"Projection": {"ProjectionType": "ALL"},
|
||||||
|
"ProvisionedThroughput": {
|
||||||
|
"ReadCapacityUnits": 1,
|
||||||
|
"WriteCapacityUnits": 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
with assert_raises(ClientError) as ex:
|
||||||
|
dynamodb.query(
|
||||||
|
TableName="test",
|
||||||
|
IndexName="non_exists_index",
|
||||||
|
KeyConditionExpression="CarModel=M",
|
||||||
|
)
|
||||||
|
|
||||||
|
ex.exception.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||||
|
ex.exception.response["Error"]["Message"].should.equal(
|
||||||
|
"Invalid index: non_exists_index for table: test. Available indexes are: test_gsi"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_batch_items_returns_all():
|
def test_batch_items_returns_all():
|
||||||
dynamodb = _create_user_table()
|
dynamodb = _create_user_table()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user