如何处理 Redshift 中的地图<string, string>列

问题描述 投票:0回答:1

我在 amazone athena 中有一个表,其列为 datatypevmap。该列称为属性,它看起来像这样(示例):

{"isAutomaticRemindersEnabled":"False","isDuplicated":"False","isParticipantsHidden":"False", "browser":"Chrome","description":"meeting is created successfully","timezone":"Europe/Madrid","isDeadlineEnabled":"False","numberOfOptions":"75","organizationFormActionType":"edit","isDescriptionAdded":"False","planType":"free","browserVersion":"99.0.4844.51","country":"ES","deviceCategory":"desktop","operatingSystem":"Windows NT 10.0","language":"es","isInTrial":"False","meetingType":"group","category":"meeting","userId":"lh9qjecjqri3fccn3tnfomw9l77nbq26","slotDurationInMinutes":"120","isLoggedIn":"True","isAllDayChosen":"False"}.

从这里,我只想获取meetingType。当我向 Athena 查询时,这很容易做到。但我想在 Redshift 中运行查询。该表将照原样成为 dbt 中临时层的一部分,无需任何更改。从那时起,将应用转换,包括仅使用 meetType。有什么建议如何处理吗?到目前为止还没有任何效果。

我尝试转换为文本,并使用正则表达式,但是 Redshift 无法识别正则表达式函数。

sql amazon-redshift sqldatatypes
1个回答
0
投票

Redshift 拥有一整套正则表达式函数 - 请参阅:https://docs.aws.amazon.com/redshift/latest/dg/String_functions_header.html

但是,更好的方法是使用 Redshift 的 json 解析功能。 JSON_EXTRACT_PATH_TEXT() 可以从有效的 json 文本中提取您要查找的密钥。

JSON_EXTRACT_PATH_TEXT(json_col, 'meetingType')

应该可以解决问题。

此外,您可以将此数据转换为超级数据类型并直接解析它,无需 json 函数,但这对于您所描述的用例来说太过分了。

© www.soinside.com 2019 - 2024. All rights reserved.