What is the order of returned columns in a failed IF expression in YCQL

[Question posted by a user on YugabyteDB Community Slack ]

I am trying to perform Light weight transaction using update statement. Is there any guarantee on the order of columns returned if the IF expression is failed. Below is my table model & the query I’m trying to attempt:

$ create table test.sample (ip inet, hr int, source text, source_id text, g map<int, int>, b map<int, int>, r map<int, int>, c map<int, blob>, primary key(ip, hr, source, source_id));
$ insert into sample(ip, hr, source, source_id, g, b, r, c) values('1.2.3.4',456, 'alpha', 'a',{0:1},{1:2},{2:1},{0:0x12});
$ update sample set g[1]=10 where ip='1.2.3.4' and hr=456 and source='alpha' and source_id='a' if g[0]=1 and b[1]=3;
 [applied] | ip      | hr  | source | source_id | b      | g
-----------+---------+-----+--------+-----------+--------+--------
     False | 1.2.3.4 | 456 |  alpha |         a | {1: 2} | {0: 1}
$ update sample set g[1]=10 where ip='1.2.3.4' and hr=456 and source='alpha' and source_id='a' if g[0]=1 and b[1]=3 and r[0]=2 and c[0]=0xaf;;
 [applied] | ip      | hr  | source | source_id | c         | r      | b      | g
-----------+---------+-----+--------+-----------+-----------+--------+--------+--------
     False | 1.2.3.4 | 456 |  alpha |         a | {0: 0x12} | {2: 1} | {1: 2} | {0: 1}
  1. how to determine the order of columns returned, such that I can utilize them for retry?
  2. what is the logic in deciding which columns should be returned for a failed LWT statement? Is it amalgamation of (where & IF expressions)

The order will be primary key columns (in the order from the primary key declaration) first, then static columns (if any), and then regular (non-key, non-static) columns.

I don’t think we define an order within the static columns and regular columns groups. However, the result is a proper (Y)CQL result set containing the metadata too (e.g. column names/types, etc). So, if possible, I’d recommend using those so that you don’t rely on the order itself.

The exact code snippet would depend on the driver/API you are using but for instance in the Row class of the Java driver there are, for each type, functions to get the value by index (e.g. row.getInt(2) ) or by name (e.g. row.getInt("hr") ).

See some examples in our code (tests) in: TestConditionalDml.java#L742. That’s correct, the result set for a failed conditional DML statement will contain exactly the set of columns referenced in the WHERE or IF clause.

[credit @mihnea ]

1 Like