Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

cql - How to select from the Cassandra using JSON child object in a column?

Below is how an entry looks like in the Cassandra:

id | address                     | age | family  | name | siblings
-----------------------------------------------------------------
 1 | {'city': 'c1', 'rue': 'r1'} |  23 |      si |   si | {'b', 'd'}

I want to select based on the city which is a child of JSON in the address column:

I am not sure if the following are the correct statements:

select address from Persons address.city='f';  
select address.city from Persons ;   
question from:https://stackoverflow.com/questions/65849926/how-to-select-from-the-cassandra-using-json-child-object-in-a-column

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unfortunately, that cannot be done in Cassandra (at least for now).

One possible option is to change your model to something like

 id | city | rue | age | family  | name | siblings
----+------+-----+-------------------------------
  1 |   c1 |  r1 |  23 |      si |   si | {'b', 'd'}

then you will be able to execute query:

select json city, rue from addresses where city = 'c1';  

to achieve "ready-to-use" json in result:

 [json]
-----------------------------
{"city": "c1", "rue": "r1"}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...