为什么'get_json_object'在spark和sql工具中运行时返回不同的结果 [英] Why does 'get_json_object' return different results when run in spark and sql tool

查看:55
本文介绍了为什么'get_json_object'在spark和sql工具中运行时返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个 hive 查询,它使用横向视图和 get_json_object 来解压一些 json.该查询使用 jdbc 客户端(dbvisualizer)针对 hive 数据库运行良好,但是当从 java 应用程序作为 spark sql 运行时,在相同的数据上,它不返回任何内容.我已将问题追溯到函数get_json_object"返回的差异.

I have developed a hive query that uses lateral views and get_json_object to unpack some json. The query works well enough using a jdbc client (dbvisualizer) against a hive database but when run as spark sql from a java application, on the same data, it returns nothing. I have tracked down the problem to differences in what the function 'get_json_object' returns.

这个问题可以通过这种类型的查询来说明

The issue can be illustrated by this type of query

select concat_ws( "|", get_json_object('{"product_offer":[
{"productName":"Plan A"},
{"productName":"Plan B"}]}', 
'$.product_offer.productName') )

在针对 Hive 数据库的 dbvisualizer 中运行时,我在 json 数组中得到一个包含 2 个产品名称的数组:["Plan A","Plan B"].当相同的查询从 Java 应用程序作为 spark sql 运行时,返回 null.

When run in dbvisualizer against a Hive database I get an array of the 2 product names in the json array: ["Plan A","Plan B"]. When the same query is run as spark sql from a java application, null is returned.

我注意到另一个区别:路径 '$.product_offer[0].productName' 在 db 可视化工具中返回 'Plan A',而在 spark 中没有任何内容.

I have noticed another difference: the path '$.product_offer[0].productName' returns 'Plan A' in db visualizer and nothing in spark.

推荐答案

提取产品名称数组的路径为

The path to extract the array of product names is

select concat_ws( "|", get_json_object('{"product_offer":[{"productName":"Plan A"},{"productName":"Plan B"}]}', '$.product_offer[*].productName'

在 spark dbvisualizer 中都可以使用.

which works both in spark dbvisualizer.

这篇关于为什么'get_json_object'在spark和sql工具中运行时返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆