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

San*_*hit 9 php mysql amazon-web-services amazon-dynamodb

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

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

小智 4

嗨也许你可以试试这个

连接两个 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;
Run Code Online (Sandbox Code Playgroud)

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

在以下示例中,Customer_S3 是加载 Amazon S3 中存储的 CSV 文件的 Hive 表,hive_purchases 是引用 DynamoDB 中的数据的表。以下示例将 Amazon S3 中以 CSV 文件形式存储的客户数据与 DynamoDB 中存储的订单数据结合在一起,以返回一组数据,这些数据代表姓名中包含“Miller”的客户所下的订单。

创建外部表 hive_purchases(customerId bigint,total_cost double, items_purchased array) 存储于 '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 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%';
Run Code Online (Sandbox Code Playgroud)

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

祝你好运并尝试