简体   繁体   English

如何使用DynamoDB表中的数据在AWS云中进行算术运算(+,-,/,*,%)

[英]How to do arithmetic operations (+,-,/,*,%) inside a AWS cloud with the Data in a DynamoDB table

Can some one help me and please let me know,Which tool in AWS I should use to perform math operations such as add/sub/mul/div/mod etc with data inside a dynamodb table? 有人可以帮我吗,请让我知道,我应该使用哪个AWS工具来对dynamodb表中的数据执行数学运算,例如add / sub / mul / div / mod等? Currently I am hosting my data inside DynamoDB via raspberry Pi using python as my programming language. 目前,我正在使用python作为编程语言通过raspberry Pi将数据托管在DynamoDB中。 But with that raw data I need to do some computations. 但是,利用这些原始数据,我需要进行一些计算。 Initially,I want to start with trying small computations. 最初,我想从尝试小型计算开始。

So Which tool is helpful to do computations inside cloud such as doing some math and finding whether the number is even number or not ,giving some input and performing some algorithm and finding the result? 那么,哪个工具对在云内部进行计算(例如做一些数学运算以及查找数字是否为偶数,给出一些输入并执行一些算法并找到结果)有用呢? I just want to pick data from my table residing in DynamoDB and do these computations.I saw Redshift in google but its little expensive,will it be possible to use that and load the data from dynamoDB to redshift and do the math operations or there any better alternate options? 我只想从驻留在DynamoDB中的表中选择数据并进行这些计算。我在Google中看到Redshift,但是它有点贵,是否可以使用它并从dynamoDB加载数据以进行redshift并进行数学运算或进行任何其他操作更好的替代选择? Will you please share me any links that will help me to start with? 您能否分享给我任何可以帮助我入手的链接?

Thank you very much . 非常感谢你 。

In DynamoDB, you can only increment and decrement numeric attributes using the + (plus) and - (minus) operators in the SET action of an UpdateExpression in update_item or the ADD action if only both; 在DynamoDB,你只能增加或减少使用+(加号)和数字属性- (减号)运营商在SET的作用UpdateExpressionupdate_itemADD动作如果只有两个; the existing attribute is a number and the value is also a number. 现有属性是数字,值也是数字。

Otherwise, you should perform your desired math operations against attribute values before updating them in DynamoDB. 否则,您应该在DynamoDB中更新属性值之前对属性值执行所需的数学运算。

Note on ADD : 注意 ADD

If you use ADD to increment or decrement a number value for an item that doesn't exist before the update, DynamoDB uses 0 as the initial value. 如果使用ADD递增或递减更新前不存在的项目的数值,则DynamoDB使用0作为初始值。 Similarly, if you use ADD for an existing item to increment or decrement an attribute value that doesn't exist before the update, DynamoDB uses 0 as the initial value. 同样,如果对现有项目使用ADD来增加或减少更新之前不存在的属性值,则DynamoDB会将0用作初始值。

For example: 例如:

response = client.update_item(
    ExpressionAttributeNames={
        '#C': 'Count'
    },
    ExpressionAttributeValues={
        ':val': {
            'N': '1'
        }
    },
    Key={
        'ItemId': {
            'S': 'BC3AB494-EDD8-4F47-B80F-32ACA92D8C5C'
        }
    },
    ReturnValues='ALL_NEW',
    TableName='MyTable',
    UpdateExpression='SET #C = #C - :val'
)

print(response)

See also: Incrementing and Decrementing Numeric Attributes . 另请参阅: 递增和递减数值属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何写入 AWS DynamoDB 表? - How do I write to an AWS DynamoDB table? AWS-如何将DynamoDb表数据传递给Lambda函数 - AWS - how to pass DynamoDb table data to Lambda function 如何将数据从一个表传输到另一个表(AWS 上的 DynamoDB) - How to transfer data from one table to another (DynamoDB on AWS) 如何从 AWS DynamoDB 导出数据(表和数据)并导入到本地 DynamoDB? - How do I export data (tables and data) from AWS DynamoDB and import into a local DynamoDB? 如何使用 Javascript 访问和更新云中的 AWS DynamoDB 表? - How can I access and update an AWS DynamoDB table in the cloud using Javascript? MQTT数据未通过AWS IoT写入DynamoDB表 - MQTT data not writing to DynamoDB table with AWS IoT 如何*连续*将数据从.NET Windows应用程序(SQL Server数据库)移动到托管在云(DynamoDB)中的应用程序(AWS)? - How to *CONTINUOUSLY* move data from .NET Windows Application (SQL Server DB) to an Application (AWS) hosted in Cloud (DynamoDB)? 如何从 AWS Lambda 内部访问 Dynamodb? - How to access Dynamodb from inside AWS Lambda? 如何使用 docker CMD 指令和正在运行的容器内的 AWS CLI 创建 DynamoDB 表? - How to create DynamoDB table using docker CMD instruction and the AWS CLI inside running container? 如何遍历AWS DynamoDB中的表? - How to iterate through a table in AWS DynamoDB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM