简体   繁体   中英

How to get the SUM of a Column from Dynamo DB using JAVA

My table is in the below format:

|ID(primary)|date(String)|Result(number)|Accuracy(Number)|
|   edfca   |   20180101 |    12        |     59.99      |
|    yrdfa  |  20180109  |    72        |     91.49      |
| arfead    | 20180101   |    122       |     32.12      |
|  readssda | 20180112   |     12       |       33       |
| geeddar   | 20180123   |    3         |     81.11      | 
|  rogeasa  |  20180203  |     14       |       81       |
| swiwads   | 20180205   |     32       |      13.12     |

I want to get the sum of the Accuracy column. Do dynamoDB provide the Sum of the column similar to the SQL:

SQL query:

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Is there any query similar to the Above.

From the below article: There is a reserved keyword 'SUM' https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html

But I'm Not able to find an example where the Keyword SUM is used in Java.

From the below link they have mentioned an example using HiveQL : https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/EMRforDynamoDB.Querying.html#w2ab1c33c13c17c11

Is there any option I can get the SUM of the column using Java.

I have an alternate option that is to get all the items using SCAN operation and then perform the addition of the column for all items. But this is a slow process takes a lot of time if there is a huge data.

IMHO the aggregate functions (or rather lack of them) is one of the pains when using DynamoDB. Hive SQL under the hood will scan/query anyway.

If you know what aggregates will be needed, you could keep them updated in other tables using dynamodb streams (and lambda and atomic counter).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM