2013-02-26 3 views
0

나는 나의 다이나모 DB 테이블이 있습니다.발전기 DB 쿼리

이제 hashkey 집합을 기반으로 쿼리를 수행하고 싶습니다. 가장 최근의 값만 가져오고 싶습니다. 메모리 정렬 작업을 수행하고 가장 최근의 버전을 고르고 싶지 않습니다.

어떤 방식 으로든이를 수행 할 수 있습니까?

사용 사례 내가 bulkget을 할 것입니다 및 hashkey (100 말)의 설정 패스 있다는 것입니다, 그래서 당신은 (현재) 배치에 제약 조건을 설정할 수있는 각 hashkey

답변

0

에 대해 하나 개의 레코드를 가져 할 수 . http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_BatchGetItems.html

그러나 단일 해시 키의 경우 ScanIndexForward를 사용하여 방향을 설정할 수 있습니다. 자세한 내용은 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_Query.html을 참조하십시오.

샘플 자바 코드 :

new QueryRequest().withTableName("table-name") 
    .withScanIndexForward(false) 
    .withLimit(1) 
    .withHashKeyValue(new AttributeValue().withS("hash-key")); 

이 전화 100 번을해야하므로 그것은,하지만 매우 효율적되지 않습니다. scanIndexForward 값이 true 표시된 경우, ID를 기반으로 최신 기능을 반환 fetchLatestEvents

0
Use ScanIndexForward(true for ascending and false for descending) and can also limit the result using setLimit value of Query Expression. 

Please find below the code where used QueryPage for finding the single record. 

public EventLogEntitySave fetchLatestEvents(String id) { 
    EventLogEntitySave entity = new EventLogEntitySave(); 
    entity.setId(id); 

    DynamoDBQueryExpression<EventLogEntitySave> queryExpression = new DynamoDBQueryExpression<EventLogEntitySave>().withHashKeyValues(entity); 
    queryExpression.setScanIndexForward(false); 
    queryExpression.withLimit(1); 
    queryExpression.setLimit(1); 

    List<EventLogEntitySave> result = dynamoDBMapper.queryPage(EventLogEntitySave.class, queryExpression).getResults(); 
    System.out.println("size of records = "+result.size()); 
    result.get(0); 
} 

@DynamoDBTable(tableName = "PROD_EA_Test") 
public class EventLogEntitySave { 

     @DynamoDBHashKey 
     private String id; 
     private String reconciliationProcessId; 
     private String vin; 
     private String source; 
} 

public class DynamoDBConfig { 
    @Bean 
    public AmazonDynamoDB amazonDynamoDB() { 

      String accesskey = ""; 
      String secretkey = ""; 
      // 
      // creating dynamo client 
      BasicAWSCredentials credentials = new BasicAWSCredentials(accesskey, secretkey); 
      AmazonDynamoDB dynamo = new AmazonDynamoDBClient(credentials); 
      dynamo.setRegion(Region.getRegion(Regions.US_WEST_2)); 
      return dynamo; 
     } 
+0

ID가 hashkey과 타임 스탬프는 정렬 키이며, 가장 오래된 이벤트와 최근의 이벤트를 반환합니다 거짓 값을 반환하고, 분류는 것 대신 메모리에서 일어나지 않는다. –