pyspark Hive SQL转换阵列(Map(varchar,varchar))到串行的字符串
我想
array(map(varchar, varchar))
从Jupyter Notebook Python3中编程地将Prestpark Hive SQL在Presto db上的表行转换为Presto DB上的一行。
示例
user_id sport_ids
'aca' [ {'sport_id': '5818'}, {'sport_id': '6712'}, {'sport_id': '1065'} ]
的结果
user_id. sport_ids
'aca'. '5815'
'aca'. '5712'
'aca'. '1065'
我尝试过
sql_q= """
select distinct, user_id, transform(sport_ids, x -> element_at(x, 'sport_id')
from tab """
spark.sql(sql_q)
,但出现了错误:
'->' cannot be resolved
我也尝试过,
sql_q= """
select distinct, user_id, sport_ids
from tab"""
spark.sql(sql_q)
但出错了:
org.apache.spark.sql.AnalysisException: Cannot have map type columns in DataFrame which calls set operations(intersect, except, etc.), but the type of column request_features[0] is map<string,string>;;
我错过了什么吗?
我尝试过,但是很有帮助 hive convert convert arnay&lt arnay&lt and string,string string,string&gt;&gt;&gt;到字符串 提取地图(varchar,array(varray(var charh))-Hive sql
谢谢
I would like to transform a column of
array(map(varchar, varchar))
to string as rows of a table on presto db by pyspark hive sql programmatically from jupyter notebook python3.
example
user_id sport_ids
'aca' [ {'sport_id': '5818'}, {'sport_id': '6712'}, {'sport_id': '1065'} ]
expected results
user_id. sport_ids
'aca'. '5815'
'aca'. '5712'
'aca'. '1065'
I have tried
sql_q= """
select distinct, user_id, transform(sport_ids, x -> element_at(x, 'sport_id')
from tab """
spark.sql(sql_q)
but got error:
'->' cannot be resolved
I have also tried
sql_q= """
select distinct, user_id, sport_ids
from tab"""
spark.sql(sql_q)
but got error:
org.apache.spark.sql.AnalysisException: Cannot have map type columns in DataFrame which calls set operations(intersect, except, etc.), but the type of column request_features[0] is map<string,string>;;
Did I miss something ?
I have tried this, but helpful
hive convert array<map<string, string>> to string
Extract map(varchar, array(varchar)) - Hive SQL
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我们尝试使用高阶功能查找地图值并爆炸到单个行中
Lets try use higher order functions to find map values and explode into individual rows
您可以处理JSON数据(
JSON_PARSE
,铸造为JSON和JSON_EXTRACT_SCALAR
- 有关更多JSON函数 - 请参阅此处)和扁平(
)unnest
输出:
You can process json data (
json_parse
, cast to array of json andjson_extract_scalar
- for more json functions - see here) and flatten (unnest
) on presto side:Output: