嗨,我在BigQuery列中有这样的字符串
cancellation_amount: 602000
after_cancellation_transaction_amount: 144500
refund_time: '2022-07-31T06:05:55.215203Z'
cancellation_amount: 144500
after_cancellation_transaction_amount: 0
refund_time: '2022-08-01T01:22:45.94919Z'我已经使用这个逻辑来获得cancellation_amount
regexp_extract(file,r'.*cancellation_amount:\s*([^\n\r]*)')但是输出的数量只有602000,我需要输出602000和144500变成不同的列。
感谢你的帮助
发布于 2022-09-24 07:04:36
如果输入中的行(最终将变成列)是固定的,则可以使用多个regexp_extract来获取所有值。
SELECT
regexp_extract(file,r'cancellation_amount:\s*([^\n\r]*)') as cancellation_amount
regexp_extract(file,r'. after_cancellation_transaction_amount:\s*([^\n\r]*)') as after_cancellation_transaction_amount
FROM table_name我在regex表达式中发现的一个问题是,.*cancellation_amount与after_cancellation_transaction_amount不匹配。
还有一个名为regexp_extract_all的函数,它将所有匹配作为数组返回,您以后可以将其分解为列,但是如果有有限的值将它们分隔在不同的列中,则会更容易。
https://stackoverflow.com/questions/73834201
复制相似问题