2016-04-02 9 views
1

Welche Unterschiede bestehen zwischen QueryRequest und 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); 

Mit QuerySpec - arbeitet

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); 
    } 

Mit dem gleichen QueryRequest - nicht funktioniert.

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

Amazon Version: Kompilierung 'com.amazonaws: aws-java-sdk: 1.10.65'

Dank!

+0

Bitte teilen Sie die Variablen Daten für QueryRequest, einer von ihnen ist falsch. –

+0

Ich habe Variablen für die Anfrage hinzugefügt. – yazabara

Antwort

0

Für QueryRequest benötigen Filter verwenden Karte:

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

Alle Werke!

Verwandte Themen