Cassandra
  1. Cassandra
  2. CASSANDRA-5017

Preparing UPDATE queries with collections returns suboptimal metadata

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Fix Version/s: 1.2.0 rc1
    • Component/s: None
    • Labels:
      None

      Description

      CQL3, binary protocol.

      collections (id int primary key, amap map<int, varchar>);

      preparing "UPDATE test.collections SET amap[?] = ? WHERE id = ?" returns the following metadata:
      [{column,<<"test">>,<<"collections">>,<<"amap">>,
      {map,int,varchar}},
      {column,<<"test">>,<<"collections">>,<<"amap">>,
      {map,int,varchar}},

      {column,<<"test">>,<<"collections">>,<<"id">>,int}

      ]

      Ideally it should return [int, varchar, int] types. Less ideally [

      {map, int, varchar}

      , int] and expect an encoded map with a single key-value pair. But certainly not what it currently returns.

        Issue Links

          Activity

          Hide
          Sylvain Lebresne added a comment -

          Attaching 3 small patches that fixes a number of problems with prepared queries and collections, including this one, the fact that you weren't allowed to prepare a list index and the fact that delete wasn't working correctly when either a list index or a map key was prepared.

          I note we have a small "problem" for the metadata return in all those cases, in that if you do

          UPDATE foo SET amap[?] = ? WHERE ...
          

          then it's unclear what name to return for the prepared variables in the metadata. The choice made by the patch is to return 'key(amap)' and 'value(amap)' respectively (and when preparing a list index, we return 'index(alist)').

          Show
          Sylvain Lebresne added a comment - Attaching 3 small patches that fixes a number of problems with prepared queries and collections, including this one, the fact that you weren't allowed to prepare a list index and the fact that delete wasn't working correctly when either a list index or a map key was prepared. I note we have a small "problem" for the metadata return in all those cases, in that if you do UPDATE foo SET amap[?] = ? WHERE ... then it's unclear what name to return for the prepared variables in the metadata. The choice made by the patch is to return 'key(amap)' and 'value(amap)' respectively (and when preparing a list index, we return 'index(alist)').
          Hide
          Aleksey Yeschenko added a comment -

          CASSANDRA-5018 in indeed no longer an issue. Also I do get the right columns in my metadata now:

          {ok, R}

          = seestar_client:prepare(Pid, "update test.collections set amap[?] = ? WHERE id = ?").
          {ok,{prepared,<<21,71,235,65,143,167,200,103,53,75,239,64,
          92,235,243,145>>,
          [

          {column,<<"test">>,<<"collections">>,<<"key(amap)">>,int}

          ,

          {column,<<"test">>,<<"collections">>,<<"value(amap)">>, varchar}

          ,

          {column,<<"test">>,<<"collections">>,<<"id">>,int}

          ]}}

          However, when I try to execute the query (or just run it in cqlsh), I get "Bad Request: List operations are only supported on List typed columns, but org.apache.cassandra.db.marshal.MapType(org.apache.cassandra.db.marshal.Int32Type,org.apache.cassandra.db.marshal.UTF8Type) given" error.

          Show
          Aleksey Yeschenko added a comment - CASSANDRA-5018 in indeed no longer an issue. Also I do get the right columns in my metadata now: {ok, R} = seestar_client:prepare(Pid, "update test.collections set amap [?] = ? WHERE id = ?"). {ok,{prepared,<<21,71,235,65,143,167,200,103,53,75,239,64, 92,235,243,145>>, [ {column,<<"test">>,<<"collections">>,<<"key(amap)">>,int} , {column,<<"test">>,<<"collections">>,<<"value(amap)">>, varchar} , {column,<<"test">>,<<"collections">>,<<"id">>,int} ]}} However, when I try to execute the query (or just run it in cqlsh), I get "Bad Request: List operations are only supported on List typed columns, but org.apache.cassandra.db.marshal.MapType(org.apache.cassandra.db.marshal.Int32Type,org.apache.cassandra.db.marshal.UTF8Type) given" error.
          Hide
          Sylvain Lebresne added a comment -

          Right, forgot to update the validation of ListType. Fourth patch attached to fix that.

          Show
          Sylvain Lebresne added a comment - Right, forgot to update the validation of ListType. Fourth patch attached to fix that.
          Hide
          Aleksey Yeschenko added a comment -

          Everything works now (prepared and unprepared). +1

          Show
          Aleksey Yeschenko added a comment - Everything works now (prepared and unprepared). +1
          Hide
          Sylvain Lebresne added a comment -

          My bad, forgot to resolve, but that has been committed a few days ago.

          Show
          Sylvain Lebresne added a comment - My bad, forgot to resolve, but that has been committed a few days ago.

            People

            • Assignee:
              Sylvain Lebresne
              Reporter:
              Aleksey Yeschenko
              Reviewer:
              Aleksey Yeschenko
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development