如何使用R中的会话令牌连接到Amazon Athena?

时间:2018-08-15 20:29:01

标签: r amazon-athena

我正在尝试使用R来使用包含会话令牌的临时凭证连接到Amazon Athena。过去,不需要会话令牌,因此我可以使用如下所示的R代码​​进行连接:

library(RJDBC)

fil <- "~/Data/AthenaJDBC41-1.1.0.jar"
drv <- JDBC(driverClass = "com.amazonaws.athena.jdbc.AthenaDriver", fil, identifier.quote="'")

con <- dbConnect(drv, "jdbc:awsathena://athena.us-east-1.amazonaws.com:443/",
                 s3_staging_dir = "...", user = "...", password = "...")

现在,我需要使用会话令牌,但是我无法弄清楚如何将令牌作为dbConnect的选项包括在内。这可能吗?怎么办?

1 个答案:

答案 0 :(得分:0)

一个同事给了我答案。一个例子是:

SELECT COALESCE(provider_organizations.id, lr_send.provider_organization_id, lr_open.provider_organization_id,
                lr_click.provider_organization_id, lr_unsub.provider_organization_id) po_id,
       COALESCE(lr_send.email_send_date, lr_open.email_open_date, lr_click.email_click_date,
                lr_unsub.email_unsub_date)     as                                     collection_date,
       COALESCE(lr_send.email_send_count, 0)   as                                     email_send_count,
       COALESCE(lr_open.email_open_count, 0)   as                                     email_open_count,
       COALESCE(lr_click.email_click_count, 0) as                                     email_click_count,
       COALESCE(lr_unsub.email_unsub_count, 0) as                                     email_unsub_count
FROM provider_organizations
         FULL OUTER JOIN (SELECT list_records.provider_organization_id,
                                 COUNT(list_records.id)        as email_send_count,
                                 list_records.email_send::date as email_send_date
                          FROM list_records
                          WHERE list_records.email_send::date IS NOT NULL
                          GROUP BY list_records.provider_organization_id, list_records.email_send::date) lr_send
                         ON provider_organizations.id = lr_send.provider_organization_id
         FULL OUTER JOIN (SELECT list_records.provider_organization_id,
                                 COUNT(list_records.id)        as email_open_count,
                                 list_records.email_open::date as email_open_date
                          FROM list_records
                          WHERE list_records.email_open::date IS NOT NULL
                          GROUP BY list_records.provider_organization_id, list_records.email_open::date) lr_open
                         ON provider_organizations.id = lr_open.provider_organization_id AND
                            lr_open.email_open_date = lr_send.email_send_date
         FULL OUTER JOIN (SELECT list_records.provider_organization_id,
                                 COUNT(list_records.id)         as email_click_count,
                                 list_records.email_click::date as email_click_date
                          FROM list_records
                          WHERE list_records.email_click::date IS NOT NULL
                          GROUP BY list_records.provider_organization_id, list_records.email_click::date) lr_click
                         ON provider_organizations.id = lr_click.provider_organization_id AND
                            lr_click.email_click_date = lr_open.email_open_date AND
                            lr_click.email_click_date = lr_send.email_send_date
         FULL OUTER JOIN (SELECT list_records.provider_organization_id,
                                 COUNT(list_records.id)         as email_unsub_count,
                                 list_records.email_unsub::date as email_unsub_date
                          FROM list_records
                          WHERE list_records.email_unsub::date IS NOT NULL
                          GROUP BY list_records.provider_organization_id, list_records.email_unsub::date) lr_unsub
                         ON provider_organizations.id = lr_unsub.provider_organization_id AND
                            lr_click.email_click_date = lr_unsub.email_unsub_date
ORDER BY po_id, collection_date