Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 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 Answer

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"}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...