【问题标题】:Data abruptly stops writing into a csv file from Dynamo DB数据突然停止从 Dynamo DB 写入 csv 文件
【发布时间】:2014-11-09 06:50:00
【问题描述】:

我已成功将数据集加载到 Dynamo DB。然后我想从 dynamo DB 中读取数据并加载到 .csv 文件中。 weka 使用这个文件来开发集群。不幸的是,只有少数从 dynamo DB 读取的数据被加载到 .csv 文件中。下面是从 Dynamo DB 中读取数据的 sn-p。我的 Dynamo DB 中有 2201 条记录,但它突然停止在第 1986 条记录和第 3 列中写入文件。我已经尝试了我在网上找到的所有可能的解决方案,但无法解决。请有人帮助我。

//从dynamobb扫描数据

ScanRequest scanRequest = new ScanRequest().withTableName(tablename[2]);
ScanResult result = client.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()){
        printItem(item,writer);
}

//将数据附加到一个空的 CSV 文件中

private static void printItem(Map<String, AttributeValue> attributeList,FileWriter writer) {
    int i=1;
    System.out.println("Inside printItem");
    try{
        int k=1;
    for (Map.Entry<String, AttributeValue> item : attributeList.entrySet()) {
        AttributeValue value = item.getValue();
        String valueName= value.getS();
        writer.append(valueName);
        if(k<=4){
        writer.append(',');
        }
        ++i;
        ++k;
    }
    writer.append('\n');
    ++count;
    }
    catch (IOException e) {
        e.printStackTrace();
}
}

【问题讨论】:

  • 您确定首先返回了完整的数据集吗?
  • 我刚刚检查过了。它不是读取整个数据。所以从 Dynamo DB 中读取的语句是错误的。
  • 您应该查看丢失了哪些记录并使用它来找出原因。

标签: java csv amazon-dynamodb export-to-csv filewriter


【解决方案1】:

Scan 是一个分页 API,因此您必须通过传入 LastEvaluatedKey 作为 ExclusiveStartKey 不断重复调用它。更多细节在developer guide和api docs。

DynamoDBMapper sdk 和文档 SDK(均随 aws-java-sdk 一起提供)提供了一些自动分页 API,这样您就可以将您的表视为一个 Iterable 而不是自己分页。在this section of the developer guide 中有一个使用低级 Java SDK 的示例,就像您正在做的那样进行分页。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-11
  • 1970-01-01
  • 1970-01-01
  • 2012-05-17
  • 1970-01-01
  • 2017-11-03
  • 1970-01-01
相关资源
最近更新 更多