将文本拆分为数组或将数组拆分为更多数组
splitting text into array or splitting an array into more arrays
我对在 snowflake(和 dbt)中使用数组还很陌生。
我正在拆分我在前端填写为连接名称时拥有的供应商名称。现在,我将它们拆分(参见下面的示例),但我想知道是否可以拆分已经拆分的数组或我可以用来拆分文本的另一个函数。
在下面的例子中,前 3 条记录被正确分割,但后面的 3 条记录没有被正确分割,这是我希望输入的地方。
我目前使用的简单案例语句是:
,case
when upper(vendor_name) like '% AND %' then split(upper(vendor_name), ' AND ')
when vendor_name like '%&%' then split(upper(vendor_name), ' & ')
else array_construct(upper(vendor_name))
end as arr_vendor_name
您可以分两步完成此操作:
- 将“&”、“AND”、“、”替换为“,”。
- 然后拆分为“,”。
split(
replace(replace(replace(vendor_name, ' AND ', ','), ' & ', ','), ', ', ',')
, ','
)
奖励:您将不再需要 case
,array_construct
也将消失。
我对在 snowflake(和 dbt)中使用数组还很陌生。 我正在拆分我在前端填写为连接名称时拥有的供应商名称。现在,我将它们拆分(参见下面的示例),但我想知道是否可以拆分已经拆分的数组或我可以用来拆分文本的另一个函数。 在下面的例子中,前 3 条记录被正确分割,但后面的 3 条记录没有被正确分割,这是我希望输入的地方。 我目前使用的简单案例语句是:
,case
when upper(vendor_name) like '% AND %' then split(upper(vendor_name), ' AND ')
when vendor_name like '%&%' then split(upper(vendor_name), ' & ')
else array_construct(upper(vendor_name))
end as arr_vendor_name
您可以分两步完成此操作:
- 将“&”、“AND”、“、”替换为“,”。
- 然后拆分为“,”。
split(
replace(replace(replace(vendor_name, ' AND ', ','), ' & ', ','), ', ', ',')
, ','
)
奖励:您将不再需要 case
,array_construct
也将消失。