gpt4 book ai didi

php - 使用 PHP 在 AWS DynamoDB 中使用 JOIN 查询

转载 作者:可可西里 更新时间:2023-11-01 06:30:02 24 4
gpt4 key购买 nike

我目前使用 MySQL 作为我的 PHP 应用程序的数据库。但是现在需要迁移到 AWS DynamoDB。由于我是 DynamoDB 的新手,有人可以帮助我在 DynamoDB 中使用 JOIN 吗?

根据我的发现,我发现 JOIN 可以通过 Hive 和 Amazon EMR 使用。但是这里也存在一个问题,即没有资源可用于将 Hive 与 PHP 一起使用。

最佳答案

你好,你可以试试这个

连接两个 DynamoDB 表连接在集群上计算并返回。连接不会在 DynamoDB 中发生。此示例返回客户列表以及他们下了两个以上订单的客户的购买情况。

CREATE EXTERNAL TABLE hive_purchases(customerId bigint, total_cost double, items_purchased array<String>) 
STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler'
TBLPROPERTIES ("dynamodb.table.name" = "Purchases",
"dynamodb.column.mapping" = "customerId:CustomerId,total_cost:Cost,items_purchased:Items");

CREATE EXTERNAL TABLE hive_customers(customerId bigint, customerName string, customerAddress array<String>)
STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler'
TBLPROPERTIES ("dynamodb.table.name" = "Customers",
"dynamodb.column.mapping" = "customerId:CustomerId,customerName:Name,customerAddress:Address");

Select c.customerId, c.customerName, count(*) as count from hive_customers c
JOIN hive_purchases p ON c.customerId=p.customerId
GROUP BY c.customerId, c.customerName HAVING count > 2;

连接来自不同来源的两个表

在以下示例中,Customer_S3 是一个 Hive 表,用于加载存储在 Amazon S3 中的 CSV 文件,而 hive_purchases 是一个引用 DynamoDB 中数据的表。以下示例将作为 CSV 文件存储在 Amazon S3 中的客户数据与存储在 DynamoDB 中的订单数据结合在一起,以返回一组数据,该数据表示名称中包含“Miller”的客户所下的订单。

创建外部表 hive_purchases(customerId bigint,total_cost double,items_purchased 数组)由 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler' 存储TBLPROPERTIES ("dynamodb.table.name"= "采购","dynamodb.column.mapping"= "customerId:CustomerId,total_cost:Cost,items_purchased:Items");

CREATE EXTERNAL TABLE Customer_S3(customerId bigint, customerName string, customerAddress array<String>)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION 's3://bucketname/path/subpath/';

Select c.customerId, c.customerName, c.customerAddress from
Customer_S3 c
JOIN hive_purchases p
ON c.customerid=p.customerid
where c.customerName like '%Miller%';

有关更多信息,您可以阅读文档 DynamoDB Export , Import Querys

祝你好运,试试

关于php - 使用 PHP 在 AWS DynamoDB 中使用 JOIN 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34677707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com