From b85e99463f1a4c46789ba541f62e813094fc7cf4 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Mon, 23 Oct 2023 10:16:10 +0000 Subject: [PATCH] DynamoDB: execute_statement() - improve support Where-clauses (#6939) --- setup.cfg | 18 +++--- .../test_dynamodb/test_dynamodb_statements.py | 62 +++++++++++++++++++ 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/setup.cfg b/setup.cfg index 992845b0a..c49febb48 100644 --- a/setup.cfg +++ b/setup.cfg @@ -52,7 +52,7 @@ all = openapi-spec-validator>=0.2.8 pyparsing>=3.0.7 jsondiff>=1.1.2 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 aws-xray-sdk!=0.96,>=0.93 setuptools multipart @@ -67,7 +67,7 @@ proxy = openapi-spec-validator>=0.2.8 pyparsing>=3.0.7 jsondiff>=1.1.2 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 aws-xray-sdk!=0.96,>=0.93 setuptools multipart @@ -82,7 +82,7 @@ server = openapi-spec-validator>=0.2.8 pyparsing>=3.0.7 jsondiff>=1.1.2 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 aws-xray-sdk!=0.96,>=0.93 setuptools flask!=2.2.0,!=2.2.1 @@ -116,7 +116,7 @@ cloudformation = openapi-spec-validator>=0.2.8 pyparsing>=3.0.7 jsondiff>=1.1.2 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 aws-xray-sdk!=0.96,>=0.93 setuptools cloudfront = @@ -139,10 +139,10 @@ dms = ds = sshpubkeys>=3.1.0 dynamodb = docker>=3.0.0 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 dynamodbstreams = docker>=3.0.0 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 ebs = sshpubkeys>=3.1.0 ec2 = sshpubkeys>=3.1.0 ec2instanceconnect = @@ -205,15 +205,15 @@ resourcegroupstaggingapi = openapi-spec-validator>=0.2.8 pyparsing>=3.0.7 jsondiff>=1.1.2 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 route53 = route53resolver = sshpubkeys>=3.1.0 s3 = PyYAML>=5.1 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 s3crc32c = PyYAML>=5.1 - py-partiql-parser==0.4.0 + py-partiql-parser==0.4.1 crc32c s3control = sagemaker = diff --git a/tests/test_dynamodb/test_dynamodb_statements.py b/tests/test_dynamodb/test_dynamodb_statements.py index 549035eaa..285c4f61c 100644 --- a/tests/test_dynamodb/test_dynamodb_statements.py +++ b/tests/test_dynamodb/test_dynamodb_statements.py @@ -198,3 +198,65 @@ class TestBatchExecuteStatement(TestCase): "TableName": "table1", } in items assert {"TableName": "table2", "Item": self.item1} in items + + +@pytest.mark.aws_verified +@dynamodb_aws_verified +def test_execute_statement_with_all_clauses(table_name=None): + dynamodb_client = boto3.client("dynamodb", "us-east-1") + + items = [ + { + "pk": {"S": "0"}, + "Name": {"S": "Lambda"}, + "NameLower": {"S": "lambda"}, + "Description": {"S": "Run code in under 15 minutes"}, + "DescriptionLower": {"S": "run code in under 15 minutes"}, + "Price": {"N": "2E-7"}, + "Unit": {"S": "invocation"}, + "Category": {"S": "free"}, + "FreeTier": {"N": "1E+6"}, + }, + { + "pk": {"S": "1"}, + "Name": {"S": "Auto Scaling"}, + "NameLower": {"S": "auto scaling"}, + "Description": { + "S": "Automatically scale the number of EC2 instances with demand", + }, + "DescriptionLower": { + "S": "automatically scale the number of ec2 instances with demand" + }, + "Price": {"N": "0"}, + "Unit": {"S": "group"}, + "Category": {"S": "free"}, + "FreeTier": {"NULL": True}, + }, + { + "pk": {"S": "2"}, + "Name": {"S": "EC2"}, + "NameLower": {"S": "ec2"}, + "Description": {"S": "Servers in the cloud"}, + "DescriptionLower": {"S": "servers in the cloud"}, + "Price": {"N": "7.2"}, + "Unit": {"S": "instance"}, + "Category": {"S": "trial"}, + }, + { + "pk": {"S": "3"}, + "Name": {"S": "Config"}, + "NameLower": {"S": "config"}, + "Description": {"S": "Audit the configuration of AWS resources"}, + "DescriptionLower": {"S": "audit the configuration of aws resources"}, + "Price": {"N": "0.003"}, + "Unit": {"S": "configuration item"}, + "Category": {"S": "paid"}, + }, + ] + + for item in items: + dynamodb_client.put_item(TableName=table_name, Item=item) + + partiql_statement = f"SELECT pk FROM \"{table_name}\" WHERE (contains(\"NameLower\", 'code') OR contains(\"DescriptionLower\", 'code')) AND Category = 'free' AND Price >= 0 AND Price <= 1 AND FreeTier IS NOT MISSING AND attribute_type(\"FreeTier\", 'N')" + items = dynamodb_client.execute_statement(Statement=partiql_statement)["Items"] + assert items == [{"pk": {"S": "0"}}]