简体   繁体   English

是否有 Hiveql function 我们可以使用它从 JSON 类型列具有特定键值的表中提取记录?

[英]Is there a Hiveql function using which we can pull records from a table where a JSON type column has a specific value for a key?

I'm looking to get count of records in which a column(type) of json type has certain key:value in table named product_type.我正在寻找记录数,其中 json 类型的列(类型)在名为 product_type 的表中具有特定键:值。

_______________________________________________________
id  |   product |            type                     |

1    | product_1  | {"costly": true, "l_type": true}  |
2    | product_2  | {"costly": false, "l_type": true} |
3    | product_3  | {"costly": false, "l_type": true} |
4    | product_4  | {"costly": false, "l_type": true} |
_______________________________________________________

Something like-就像是-

select count(id) from product_table where type has {"costly": false}

What I have tried:我试过的:

select count(*) from product_table where type LIKE '%"costly": false%' 

-> which is not yielding any results. -> 没有产生任何结果。

Expecting to get: 3 ( as there are 3 records that has value as false in type column for the key costly.)期望得到:3(因为有 3 条记录在 type 列中的值为 false,键成本高。)

I got it resolved:我解决了:

select count(*) from product_table where get_json_object(type,$.costly) is true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM