Cassandra throws bad query: package with conditions cannot span multiple tables

Cassandra docs and blog says that batches with conditional update operations work with section granularity, and the section is defined by the first key in the primary key So I have the following keys:

CREATE TABLE SOCIAL_PROFILE (
soc_net_type text,
soc_net_user_id text,
user_prof_id text,
PRIMARY KEY (soc_net_type, soc_net_user_id)); 

CREATE TABLE SOCIAL_PROFILE_CONTACT (
soc_prof_soc_net_type text,
soc_prof_soc_net_user_id text,
soc_net_user_id text,
PRIMARY KEY (soc_prof_soc_net_type, soc_prof_soc_net_user_id, soc_net_user_id));

      

And the insert statement:

BEGIN BATCH INSERT INTO social_profile (soc_net_type, soc_net_user_id, user_prof_id) VALUES ('vk', '1', '100') IF NOT EXISTS; INSERT INTO social_profile_contact (soc_prof_soc_net_type, soc_prof_soc_net_user_id, soc_net_user_id) VALUES ('vk', '1', '2'); INSERT INTO social_profile_contact (soc_prof_soc_net_type, soc_prof_soc_net_user_id, soc_net_user_id) VALUES ('vk', '1', '3'); INSERT INTO social_profile_contact (soc_prof_soc_net_type, soc_prof_soc_net_user_id, soc_net_user_id) VALUES ('vk', '1', '4'); APPLY BATCH;

And social_profile_contact.soc_prof_soc_net_type = social_profile.soc_net_type they both have the same values ​​and must be in the same section, but Cassandra throws: Bad query: package with conditions cannot span multiple tables

I didn't find a word about tables in the docs, what am I doing wrong?

cqlsh 4.1.1 | Cassandra 2.0.11 | CQL spec 3.1.1 | Thrift Protocol 19.39.0

+3


source to share


2 answers


"Conditions package cannot span multiple tables"



Two different column families (tables) that use the same primary key are still two different partitions.

+5


source


You need to move the statement with IF NOT EXISTS to an independent batch. INSERT INTO social_profile (soc_net_type, soc_net_user_id, user_prof_id) VALUES ('vk', '1', '100') IF NOT EXISTING,



The IF NOT EXISTS conditional package insert can contain only one type.

+1


source







All Articles