如何在presto中获取查询中的数字?

时间:2017-02-16 08:35:02

标签: sql url hive presto

例如,

查询的值为:

currentView=/review_list_renewal_page&page=SDP&vendorItemID=3081429363&categoryID=&itemID=52159373&eventReferrer=/click_top_button&itemProductID=&pdpStyle=BRAND_SDP_FASHION&content=option_picker&type=brandSDPFashion&q=&logCategory=event&logType=click&productID=12257000&optionStatus=normal&searchId=&memberID=6339421&rank=&request_time=1487114662328&tz=+0900&appVersion=4.5.2&wl_mo=LG-F460S&wl_ma=LGE&wl_sn=Android&wl_v=5.0.1&wl_r=1440x2392&wl_l=ko&wl_c=KR

我使用STR_TO_MAP(query,“&”,“=”)[“productId”]来获取映射到Hive中productId的数字。但现在在presto,功能似乎无效。那么如何从查询中检索它? 我认为查询格式不严格。

1 个答案:

答案 0 :(得分:1)

split_to_map(query,'&','=')['productId'] 

https://prestodb.io/docs/current/functions/string.html https://prestodb.io/docs/current/functions/map.html

演示

presto> select split_to_map('currentView=/review_list_renewal_page&page=SDP&vendorItemID=3081429363&categoryID=&itemID=52159373&eventReferrer=/click_top_button&itemProductID=&pdpStyle=BRAND_SDP_FASHION&content=option_picker&type=brandSDPFashion&q=&logCategory=event&logType=click&productID=12257000&optionStatus=normal&searchId=&memberID=6339421&rank=&request_time=1487114662328&tz=+0900&appVersion=4.5.2&wl_mo=LG-F460S&wl_ma=LGE&wl_sn=Android&wl_v=5.0.1&wl_r=1440x2392&wl_l=ko&wl_c=KR^J','&','=')['productID'];
  _col0
----------
 12257000