2017-10-10 22 views
0

AWSのドキュメントは悪いです。フィルタ付きAWS DynamoDBのスキャン

app_code = "TEST"のレコードのテーブル "apps"のレコードに対してDynamoDBをスキャンするにはどうすればよいですか?

次のコードは動作していない。ここで

AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard() 
       .withRegion(Regions.US_EAST_1) 
       .build(); 


     Map<String, AttributeValue> expressionAttributeValues = 
       new HashMap<String, AttributeValue>(); 
      expressionAttributeValues.put(":val", new AttributeValue().withN("0")); 

     ScanRequest scanRequest = new ScanRequest() 
       .withTableName("apps") 
       .withFilterExpression("app_code = TEST") 
       .withProjectionExpression("Id") 
       .withExpressionAttributeValues(expressionAttributeValues); 

     ScanResult scanResult = client.scan(scanRequest); 
     for (Map<String, AttributeValue> item : scanResult.getItems()) { 
      System.out.println(item); 
     } 

は私のエラーです:

Exception in thread "main" com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: Value provided in ExpressionAttributeValues unused in expressions: keys: {:val} (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: UNASODL7AHEETORAJ1Q1AF2EE3VV4KQNSO5AEMVJF66Q9ASUAAJG) 
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1638) 
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1303) 
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1055) 
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743) 
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717) 
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699) 
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667) 
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649) 
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513) 
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:2186) 
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2162) 
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeScan(AmazonDynamoDBClient.java:1678) 
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.scan(AmazonDynamoDBClient.java:1654) 
    at com.amazonaws.samples.Sessions.main(Sessions.java:46) 
+1

属性 'val'を指定しましたが、実際にスキャンで使用しませんでした。 DynamoDBはあなた自身からあなたを救おうとしています。スキャンの例は次のとおりです。http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ScanJavaDocumentAPI.html – jarmod

答えて

0

:valプレースホルダにFilterExpressionでTESTを変更してください。

ScanRequest scanRequest = new ScanRequest() 
      .withTableName("apps") 
      .withFilterExpression("app_code = :val") 
      .withProjectionExpression("Id") 
      .withExpressionAttributeValues(expressionAttributeValues); 
関連する問題