Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-6526

CQLSSTableWriter addRow(Map<String, Object> values) does not work as documented.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • 2.0.6
    • None
    • None
    • Normal

    Description

      There are 2 bugs in the method

      addRow(Map<String, Object> values)
      

      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.

      SUGGESTED SOLUTION:

      Fix the addRow method with:

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

      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:

           * <p>
           * Keys in the map <b>must</b> be in lower case, otherwise their value will be null.
           *
      

      Attachments

        1. 6526.txt
          4 kB
          Sylvain Lebresne

        Activity

          People

            slebresne Sylvain Lebresne
            yarix Yariv Amar
            Sylvain Lebresne
            Tom Hobbs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified