AWS DynamoDB 的 r 语言支持 [英] r language support for AWS DynamoDB

查看:16
本文介绍了AWS DynamoDB 的 r 语言支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对此的后续/更新问题:

This is a follow up / updated question to this:

AWS dynamodb 对R"的支持编程语言

我正在寻找有关如何将表从 DynamoDB 读入 R 的示例或文档.

I am looking for examples or documentation on how to read in a table from DynamoDB into R.

这个问题为我指明了正确的方向:

This question pointed me in the right direction:

R + httr 和 EC2 api 身份验证问题

(由伟大的@hadley 本人回答!).

(answered by the great @hadley himself!).

如果我必须使用 httr 然后解析 json 响应也没关系,但我什至无法弄清楚如何格式化 POST 请求.

It's ok if I have to use httr and then parse a json response, but I can't even figure out how to format the POST request.

谢谢!

推荐答案

here 重复我的回答,因为有人给我发了这个页面,问了一个类似的问题.

Repeating my answer from here since someone sent me this page asking a similar question.

这是我用于将数据从 DynamoDB 读取到 R 中的简化版本.它依赖于 R 和 Python 可以交换数据的事实,以及一个名为 boto 使得从 DynamoDB 获取数据变得非常容易.如果这都是一个 R 包,那就太好了,但考虑到您可以从亚马逊获得 25GB 的免费存储空间,我不会抱怨.

Here's a simplified version of what I'm using for reading data from DynamoDB into R. It relies on the fact that R and Python can exchange data, and a library called boto in Python makes it really easy to get data from DynamoDB. It would be neat if this was all an R package, but I won't complain given the 25GB of free storage you can get from Amazon.

首先,您需要一个像 query_dynamo.py 这样的 Python 脚本:

First, you need a Python script like so named query_dynamo.py:

import boto3
import time

dynamodb = boto3.resource('dynamodb',
                          aws_access_key_id='<GET ME FROM AWS>',
                          aws_secret_access_key='<ALSO GET ME FROM AWS CONSOLE>',
                          region_name='us-east-1')

table = dynamodb.Table('comment')  ###Your table name in DynamoDB here

response = table.scan()
data = response['Items']

while 'LastEvaluatedKey' in response:
    response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
    data.extend(response['Items'])

然后在 R 中执行此操作.如果你在 Windows 上尝试这个,你可能想试试 rPython-win .我在 Ubuntu Linux 16.04 LTS 上完成了这一切.

Then in R you do this. If you're trying this on Windows, you may want to try rPython-win instead. I did all this on Ubuntu Linux 16.04 LTS.

library(rPython)


python.load("query_dynamo.py")
temp = as.data.frame(python.get('data'))
df = as.data.frame(t(temp))
rm(temp)

现在您将拥有一个名为df"的数据框,其中包含您放入 DynamoDB 中的任何内容.

Now you'll have a dataframe called "df" with the contents of whatever you put in DynamoDB.

这篇关于AWS DynamoDB 的 r 语言支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆