我正在使用
val df5 = spark.sql("select str_to_map('fruits=banana|sports=football','\\|','=') as json_temp")
但产出并不像预期的那样
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|json_temp |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|[f ->, r ->, u ->, i ->, t ->, s ->, -> , b ->, a ->, n ->, a ->, n ->, a ->, | ->, s ->, p ->, o ->, r ->, t ->, s ->, -> , f ->, o ->, o ->, t ->, b ->, a ->, l ->, l ->, ->]|
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
它无法读取分隔符和分隔符。
我希望输出像
fruits -> banana, sports -> football
2条答案
按热度按时间x4shl7ld1#
在scala中对正则表达式转义使用四个反斜杠:
或者使用带两个反斜杠的三重引号:
x759pob22#
您需要转义管道角色。你可以把它放进去
[]
: