【发布时间】:2015-03-20 20:07:01
【问题描述】:
如何在amazon dynamodb中使用java对countryCode列数据进行升序或降序排序
如何在代码中使用SortOrder enum。
SortOrder 枚举在 packagecom.amazonaws.services.codedeploy.model.SortOrder 中可用。
import java.io.Serializable;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
@DynamoDBTable(tableName = "cd_country")
public class Country implements Serializable {
private static final long serialVersionUID = 5698425418072128936L;
@DynamoDBAutoGeneratedKey
@DynamoDBHashKey
private String countryId;
private String countryCode;
private String countryName;
private Long isActive;
public String getCountryId() {
return countryId;
}
public void setCountryId(String countryId) {
this.countryId = countryId;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public Long getIsActive() {
return isActive;
}
public void setIsActive(Long isActive) {
this.isActive = isActive;
}
}
【问题讨论】:
-
是什么让您认为
com.amazonaws.services.codedeploy.model.SortOrder将用于 DynamoDB? AWS 开发工具包本质上是按服务拆分的。 -
@MikeKobit 在
SortOrder类中,它包含Ascending("ascending"), Descending("descending");。你能告诉我如何在java中按升序/降序对countryCode列数据进行排序。 -
SortOrder特定于 AWS CodyDeploy。正如我在回答中所说,您需要使用Scan操作来读取整个表并将结果拉入内存中,您必须对其进行排序。另一种选择是使用DynamoDB Online Indexing announced yesterday 在表上创建索引,然后您可以使用Query操作来获取排序结果,您可以分页而无需先读取整个表。 -
@MikeKobit 你能发个代码吗。
标签: java amazon-web-services sorting amazon-dynamodb amazon