2016-04-02 93 views
1

QueryRequest和QuerySpec之間有什麼區別?dynamo DB:QuerySpec vs QueryRequest

QuerySpec spec = new QuerySpec() 
     .withKeyConditionExpression("#n_channel = :v_channel") 
     .withFilterExpression("#n_type = :v_type") 
     .withNameMap(new NameMap() 
      .with("#n_type", DATABASE_CONTENT_TYPE_NAME) 
      .with("#n_channel", PRIMARY_KEY_NAME)) 
     .withValueMap(new ValueMap() 
      .withString(":v_type", type) 
      .withString(":v_channel",channelId)) 
     .withConsistentRead(true); 

隨着QuerySpec - 工程

keyConditions.put(PRIMARY_KEY_NAME, new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(channelId))); 
keyConditions.put(RANGE_KEY_NAME, new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL));//default value 
typeFilterExpression = "#n_type = :v_type"; 
nameMap.with("#n_type", DATABASE_CONTENT_TYPE_NAME); 
values.put(":v_type", new AttributeValue().withS(type)); 

// 
    QueryRequest request = new QueryRequest().withTableName(tableName) 
     .withKeyConditions(keyConditions).withLimit(QUERY_LIMIT) 
     .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withConsistentRead(false); 
    if(StringUtils.isNotBlank(typeFilterExpression)) { 
     request.withFilterExpression(typeFilterExpression); 
    } 
    if(!MapUtils.isEmpty(nameMap)) { 
     request.withExpressionAttributeNames(nameMap); 
    } 
    if(!MapUtils.isEmpty(values)) { 
     request.withExpressionAttributeValues(values); 
    } 

與同QueryRequest - 不工作。

com.amazonaws.AmazonServiceException: Attempted conditional constraint is not an indexable operation 

亞馬遜版本: 編譯 'com.amazonaws:AWS-Java的SDK:65年1月10日'

謝謝!

+0

請分享QueryRequest的變量數據,其中一個是錯誤的。 –

+0

我已經爲請求添加了變量。 – yazabara

回答

0

對於QueryRequest需要使用過濾器映射:

filters.put(TYPE, new Condition() // 
     .withComparisonOperator(ComparisonOperator.EQ) // 
     .withAttributeValueList(// 
      new AttributeValue() // 
       .withS(type.name()) // 
     ) // 
    ); 
request.withQueryFilter(filters); 

所有作品!