When I use session.execute
in cassandra
, I notice that the ResultSet
's structure is different for the same table. If I am querying the table to get a record using Where
, the ResultSet
contains the data fetched from the table.
val resultSet = session.execute(whereClause)
gives
ResultSet[ exhausted: false, Columns[year(bigint), month(bigint),
creation_time_hour(bigint), creation_time_minute(bigint),
question_id(uuid), question_description(varchar)]]
But if I use Insert
, I get something totally different.
ResultSet[ exhausted: false, Columns[[applied](boolean)]]
Is this expected behavior? Is there a way to get the data "inserted" by cassandra
in the table in the ResultSet
returned by execute
method?
Usually, the INSERT
doesn't return the inserted values back to user. The exception is insert that triggers lightweight transaction - if you use IF NOT EXISTS
. In this case, it may return:
[applied]
with true
value - this means that data were inserted;cqlsh:test> insert into test.u2(id,u) values(5, {id:1, t1:3}) if not exists;
[applied]
-----------
True
[applied]
with false
value - this happens when row with given primary key already exists.cqlsh:test> insert into test.u2(id,u) values(1, {id:1, t1:2});
cqlsh:test> insert into test.u2(id,u) values(1, {id:1, t1:3}) if not exists;
[applied] | id | u
-----------+----+----------------
False | 1 | {id: 1, t1: 2}