Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取特定分区的最新/最新条目_Java_Amazon Web Services_Amazon Dynamodb - Fatal编程技术网

Java 获取特定分区的最新/最新条目

Java 获取特定分区的最新/最新条目,java,amazon-web-services,amazon-dynamodb,Java,Amazon Web Services,Amazon Dynamodb,我有一个表,表中的项目结构如下: [PartitionKey] | [RangeKey] | [Attribute] Id Start End 现在我想在不知道范围键的情况下获取最新或最新的条目。我只知道PartitionKey。最新条目具有最新的开始时间 我无法使用load功能,因为缺少RangeKey。所以我必须使用一个查询。但我不知道是哪一个 您知道哪种查询最适合解决此类问题吗?可以使用ScanIndexForward按顺序排列排序键 如果S

我有一个表,表中的项目结构如下:

[PartitionKey] | [RangeKey] | [Attribute]  
Id               Start        End
现在我想在不知道
范围键的情况下获取最新或最新的条目。我只知道
PartitionKey
。最新条目具有最新的
开始时间

我无法使用
load
功能,因为缺少
RangeKey
。所以我必须使用一个查询。但我不知道是哪一个


您知道哪种查询最适合解决此类问题吗?

可以使用
ScanIndexForward
按顺序排列排序键

如果ScanIndexForward为true,则DynamoDB将按顺序返回结果 它们存储在其中(按排序键值)。这是默认设置 行为。如果ScanIndexForward为false,则DynamoDB将在中读取结果 按排序键值反转顺序,然后将结果返回给 客户

示例代码:-

下面的代码通过分区键按降序排列排序键来检索数据

    Table table = dynamoDB.getTable("Movies");

    QuerySpec querySpec = new QuerySpec();

    querySpec.withKeyConditionExpression("yearkey = :yearval")
            .withValueMap(
                    new ValueMap().withNumber(":yearval", yearkey))
            .withScanIndexForward(false);

    IteratorSupport<Item, QueryOutcome> iterator = table.query(querySpec).iterator();

    while (iterator.hasNext()) {
        Item movieItem = iterator.next();
        System.out.println("Movie data ====================>" + movieItem.toJSONPretty());
        moviesJsonList.add(movieItem.toJSON());
    }
Table Table=dynamoDB.getTable(“电影”);
QuerySpec QuerySpec=新QuerySpec();
querySpec.withKeyConditionExpression(“yearkey=:yearval”)
.withValueMap(
新的ValueMap().withNumber(“:yearval”,yearkey))
.使用CANINDEXFORWARD(假);
迭代器支持迭代器=table.query(querySpec.iterator();
while(iterator.hasNext()){
Item movieItem=iterator.next();
System.out.println(“电影数据====================>”+movieItem.toJSONPretty());
添加(movieItem.toJSON());
}

可以使用
ScanIndexForward
按顺序排列排序键

如果ScanIndexForward为true,则DynamoDB将按顺序返回结果 它们存储在其中(按排序键值)。这是默认设置 行为。如果ScanIndexForward为false,则DynamoDB将在中读取结果 按排序键值反转顺序,然后将结果返回给 客户

示例代码:-

下面的代码通过分区键按降序排列排序键来检索数据

    Table table = dynamoDB.getTable("Movies");

    QuerySpec querySpec = new QuerySpec();

    querySpec.withKeyConditionExpression("yearkey = :yearval")
            .withValueMap(
                    new ValueMap().withNumber(":yearval", yearkey))
            .withScanIndexForward(false);

    IteratorSupport<Item, QueryOutcome> iterator = table.query(querySpec).iterator();

    while (iterator.hasNext()) {
        Item movieItem = iterator.next();
        System.out.println("Movie data ====================>" + movieItem.toJSONPretty());
        moviesJsonList.add(movieItem.toJSON());
    }
Table Table=dynamoDB.getTable(“电影”);
QuerySpec QuerySpec=新QuerySpec();
querySpec.withKeyConditionExpression(“yearkey=:yearval”)
.withValueMap(
新的ValueMap().withNumber(“:yearval”,yearkey))
.使用CANINDEXFORWARD(假);
迭代器支持迭代器=table.query(querySpec.iterator();
while(iterator.hasNext()){
Item movieItem=iterator.next();
System.out.println(“电影数据====================>”+movieItem.toJSONPretty());
添加(movieItem.toJSON());
}

排序键可以是存储项的任何属性?或者它需要是分区键吗?排序键只是RangeKey。在您的例子中,它是“开始”。排序键可以是存储项的任何属性?或者它需要是分区键吗?排序键只是RangeKey。在您的情况下,它是“开始”。