我在Cassandra中定义了一个表。只有一列属于地图数据类型。我想在此列上实现Pivot,使键将成为列名,并且与该键关联的值将成为列的值。 有什么特别的方法吗?我是否必须在CQL中定义UDF或UDA?表的定义,数据和预期的输出如下:
create table test_data(
... id int,
... product_name text,
... machine_address text,
... test_id int,
... result map<text,text>,
... PRIMARY KEY (id));
``` Table Data:
id | machine_address | product_name | result | test_id
------+-----------------+--------------+----------------------------------------------------------------------------------------------+---------
1101 | AEI-T4 | Saker | {'comment': 'Pass', 'start_time': '2018-02-06T00:00:00', 'stop_time': '2018-02-06T00:00:00'} | 124
1103 | AEI-T5 | Saker2 | {'comment': 'Pass', 'start_time': '2018-05-07T00:60:00', 'stop_time': '2018-06-07T00:00:00'} | 141
1102 | AEI-T4 | Saker1 | {'comment': 'Fail', 'start_time': '2018-02-07T00:60:00', 'stop_time': '2018-02-07T00:00:00'} | 124
The expected output after implementing Pivot on the map column 'result' should be like:
start_time | stop_time | comment
------+-----------------+--------------+------------
2018-02-06T00:00:00 | 2018-02-06T00:00:00 | Pass
2018-05-07T00:60:00 | 2018-06-07T00:00:00 | Pass
2018-02-07T00:60:00 | 2018-02-07T00:00:00 | Fail