2012-02-13 6 views
5

L'entità che sto interrogando ha un & a RangeKey (numero). Quando uso batchGetItem su di esso, ottengo il seguente errore:Errore nell'API batchGetItem in java

AWS Error Code: ValidationException, AWS Error Message: One or more parameter values were invalid: Mismatching attribute types between location and schema

schema:

Table: Daily

Hash Key: CustId (String)

Range Key: Dated (Number)

dati:

CustId : VisioNerdy

Dated : 1329071400000

Codice:

List<Key> fkeys = new ArrayList<Key>(); //tableName="Daily", keys=["VisioNerdy"], ranges=[1329071400000] 
    Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>(); 
    for(int i = 0; i < keys.size(); i++) 
    { 
     String key = keys.get(i); 
     if(ranges == null) 
      fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key))); 
     else 
      fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key)) 
        .withRangeKeyElement(new AttributeValue().withS(ranges.get(i).toString()))); 
    } 
    requestItems.put(tableName, new KeysAndAttributes().withKeys(fkeys)); 
    BatchGetItemRequest batchGetItemRequest = new BatchGetItemRequest().withRequestItems(requestItems); 
    BatchGetItemResult result = client.batchGetItem(batchGetItemRequest); 

Degli indizi?

+0

La prego di aggiungere il eventualmente condensato) schema (e il frammento di codice esegue la query per facilitare analisi? Grazie! –

+1

Hai modificato la domanda per includerli. Grazie! –

+0

Hai "if (ranges == null)" ma se una tabella ha una chiave di intervallo, è richiesto un valore; non puoi ometterlo –

risposta

8

Hai definito l'attributo raggio d'azione del Hash and Range Type Primary Key come tipo Numero, ma preparare il suo valore di attributo tramite withS() come tipo String per la vostra richiesta:

fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key)) 
     .withRangeKeyElement(new AttributeValue().withS(ranges.get(i).toString()))); 

Modifica withS(String s)-withN(String s) dovrebbe risolvere il problema di conseguenza (entrambi i metodi richiedono in modo confuso un parametro di tipo Stringa):

fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key)) 
     .withRangeKeyElement(new AttributeValue().withN(ranges.get(i).toString()))); 

Certo, l'implicito tipizzazione debole la presentazione DynamoDB data types sulla base di String parametri solo non è esattamente la facilità di sviluppo;)

+0

Trovato! Grazie! –

+0

@Mani: Sono contento di poterti aiutare - potresti per favore passare in rassegna e soprattutto accettare la risposta, se risolvesse il tuo problema? Ciò è desiderato qui, sia per tenere il problema lontano dagli occhi sia per dare spazio a problemi aperti di altri, oltre a garantire che gli utenti rimangano motivati ​​ad aiutarsi a vicenda;) Vedere le FAQ [Che cos'è la reputazione?] (Http: // stackoverflow .com/faq # reputation) per i dettagli - grazie! –

+1

Fatto! Grazie per la guida! –