从下面选择响应。如何添加where子句以过滤请求的到达时间之间的航班。
cqlsh:api_itl> select * from generic_response_1;
trace-id | result-index | api | base_price | fare_selection | fare_type | flights | sale_price | special_instructions | total_duration
--------------------------------------+--------------+-----+------------+----------------+-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+----------------------+----------------
39485363-cc22-4eff-a502-6d860931c3fb | IB56 | tbo | 8400 | Retail | ADT | [{arrival_date_time: '23-03-2019 14:10', carrier_iata: 'UK', carrier_id: 'UK 816', carrier_name: 'Air Vistara', class_code: 'Q', departure_date_time: '23-03-2019 11:30', flight_duration: 160, field_7_: 'BLR', to: 'DEL', via: ''}, {arrival_date_time: '23-03-2019 22:40', carrier_iata: 'UK', carrier_id: 'UK 835', carrier_name: 'Air Vistara', class_code: 'Q', departure_date_time: '23-03-2019 19:55', flight_duration: 165, field_7_: 'DEL', to: 'MAA', via: ''}] | 9485 | null | 670
39485363-cc22-4eff-a502-6d860931c3fb | OB4 | tbo | 1000 | Retail | ADT | [{arrival_date_time: '08-03-2019 14:55', carrier_iata: '6E', carrier_id: '6E 119', carrier_name: 'Indigo', class_code: 'Q', departure_date_time: '08-03-2019 13:55', flight_duration: 60, field_7_: 'MAA', to: 'BLR', via: ''}] | 1770 | null | 60
(2 rows)
cqlsh:api_itl>
给定输出的数据库结构
CREATE TYPE api_itl.flight (
arrival_date_time text,
carrier_iata text,
carrier_id text,
carrier_name text,
class_code text,
departure_date_time text,
flight_duration int,
"from" text,
"to" text,
via text
);
CREATE TABLE api_itl.generic_response_1(
"trace-id" uuid,
"result-index" text,
api text,
base_price float,
fare_selection text,
fare_type text,
flights list<frozen<flight>>,
sale_price float,
special_instructions list<text>,
total_duration int,
PRIMARY KEY ("trace-id", "result-index")
)
答案 0 :(得分:0)
不能使用CQL过滤属于TYPE的数据。相反,请考虑更改数据模型。
首先,将TYPE设为TABLE。
CREATE TABLE api_itl.flight ( arrival_date_time timestamp, carrier_iata text, carrier_id text, carrier_name text, class_code text, departure_date_time text, flight_duration int, "from" text, "to" text, via text, "trace-id" uuid, "result-index" text, PRIMARY KEY ("carrier_id", "arrival_date_time") );
接下来,从原始表格中删除排期list<frozen<flight>>
。
现在,您可以使用两个查询来获得所需的结果。