Включает C, C ++, Delphi, EditPad, Java, JavaScript, Perl, PHP (preg), PostgreSQL, PowerGREP, PowerShell, Python, REALbasic, Real Studio, Ruby , TCL, VB.Net, VBScript, wxWidgets, XML Schema, Xojo, XRegExp.PCRE совместимость может различаться
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Anywhere: . ^ $ * + - ? ( ) [ ] { } \ |
Включает поддержку awk, ed, egrep, emacs, GNUlib, grep, PHP (ereg), MySQL, Oracle, R, sed.PCRE версии или с помощью расширений
ERE / awk / egrep / emacs
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; Вне класса символов: . ^ $ * + ? ( ) [ { } \ |
& nbsp; & nbsp; & nbsp; & nbsp; Внутри класса символов: ^ - [ ]
BRE / ed / grep / sed
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; ; & nbsp; внутри класса символов: ^ - [ ]
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; g16]
\xFF
] -
требуется только экранирование в классе символов, но я сохранил их в одном списке для простоты "(\")(/)(\\.)"
по сравнению с /(")(\/)(\.)/
в JavaScript) Explode
Ваш столбец, используя split
по пробелам и агрегатам.
Это демонстрационная версия в Hive:
with your_data as
(
select Column_A,Column_B from
(
select stack(3,
'AAA','1 23 56 89 74 52',
'BBB','63 99 44 2 80 87 58 63',
'CCC','96 45 23 84 62 74'
) as (Column_A,Column_B)
)s
) --Use your table instead of this CTE
select Column_A,Column_B, sum(cast(b.val_b as int)) as Column_C
from your_data a
lateral view outer explode(split(Column_B,' ')) b as val_b
group by Column_A,Column_B;
Результат:
OK
AAA 1 23 56 89 74 52 295
BBB 63 99 44 2 80 87 58 63 496
CCC 96 45 23 84 62 74 384
Time taken: 53.228 seconds, Fetched: 3 row(s)
В качестве альтернативы, если фиксированное максимальное количество элементов в списке, вы можете сделать то же самое без взрыва, это будет работать намного быстрее:
create temporary macro cast_value(s string) nvl(cast(s as int),0);
with your_data as
(
select Column_A,Column_B from
(
select stack(3,
'AAA','1 23 56 89 74 52',
'BBB','63 99 44 2 80 87 58 63',
'CCC','96 45 23 84 62 74'
) as (Column_A,Column_B)
)s
) --Use your table instead of this CTE
select Column_A,Column_B,
cast_value(col_B_array[0])+
cast_value(col_B_array[1])+
cast_value(col_B_array[2])+
cast_value(col_B_array[3])+
cast_value(col_B_array[4])+
cast_value(col_B_array[5])+
cast_value(col_B_array[6])+
cast_value(col_B_array[7])+
cast_value(col_B_array[8])+
cast_value(col_B_array[9]) as Column_C
from(
select Column_A,Column_B, split(Column_B,' ') col_B_array
from your_data a
)s
Результат:
OK
AAA 1 23 56 89 74 52 295
BBB 63 99 44 2 80 87 58 63 496
CCC 96 45 23 84 62 74 384
Time taken: 0.82 seconds, Fetched: 3 row(s)