cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sylvain Lebresne (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CASSANDRA-6526) CQLSSTableWriter addRow(Map<String, Object> values) does not work as documented.
Date Mon, 03 Mar 2014 11:08:20 GMT

     [ https://issues.apache.org/jira/browse/CASSANDRA-6526?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Sylvain Lebresne updated CASSANDRA-6526:
----------------------------------------

    Attachment: 6526.txt

Attaching simple patch to fix the bug mentioned and add some doc on when you should lowercase
column names.

> CQLSSTableWriter addRow(Map<String, Object> values) does not work as documented.
> --------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-6526
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-6526
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Core
>            Reporter: Yariv Amar
>             Fix For: 2.0.6
>
>         Attachments: 6526.txt
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> There are 2 bugs in the method
> {code}
> addRow(Map<String, Object> values)
> {code}
> First issue is that the map <b>must</b> contain all the column names as keys
in the map otherwise the addRow fails (with InvalidRequestException "Invalid number of arguments,
expecting %d values but got %d").
> Second Issue is that the keys in the map must be in lower-case otherwise they may not
be found in the map, which will result in a NPE during decompose.
> h6. SUGGESTED SOLUTION:
> Fix the addRow method with:
> {code}
> public CQLSSTableWriter addRow(Map<String, Object> values)
>     throws InvalidRequestException, IOException
> {
>     int size = boundNames.size();
>     Map<String, ByteBuffer> rawValues = new HashMap<>(size);
>     for (int i = 0; i < size; i++) {
>         ColumnSpecification spec = boundNames.get(i);
>         String colName = spec.name.toString();
>         rawValues.put(colName, values.get(colName) == null ? null : ((AbstractType)spec.type).decompose(values.get(colName)));
>     }
>     return rawAddRow(rawValues);
> }
> {code}
> When creating the new Map for the insert we need to go over all columns and apply null
to missing columns.
> Fix the method documentation add this line:
> {code}
>      * <p>
>      * Keys in the map <b>must</b> be in lower case, otherwise their value
will be null.
>      *
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message