Apache Hive 正则表达式错误
Error in Apache Hive regular expression
我在配置单元中遇到正则表达式问题,它无法识别“;”。
insert overwrite table prueba
SELECT
regexp_extract(col_value, '^(?:([^;]*)\;?){1}', 1) VARIABLE,
regexp_extract(col_value, '^(?:([^;]*)\;?){2}', 1) TipoType
from temp;
发生的错误是:
H110 Unable to submit statement. Error while compiling statement:
FAILED: ParseException line 3:29 cannot recognize input near '^' ' (' '?'
In select expression [ERROR_STATUS]
示例数据:
VARIABLE;Tipo/Type;
FECHA;DATE;
ID_CLIENTE;CHAR;
CUS_TYPE;CHAR;
CUS_SUBTYPE;CHAR;
NUEVOTITU;NUMBER;
TITULAR;NUMBER;
BAJATITU;NUMBER;
.
.
.
代码:
drop table temp;
drop table prueba;
create table temp (col_value string);
LOAD DATA INPATH '/tmp/data/prueba.csv' OVERWRITE INTO TABLE temp;
create table prueba(variable string, tipotype string);
insert overwrite table prueba
SELECT
regexp_extract(col_value, '^(([^\;]*)\;){1}', 1) variable,
regexp_extract(col_value, '^(([^\;]*)\;){2}', 1) tipotype
from temp;
温度table:
temp.col_value
普鲁巴table:
prueba.variable prueba.tipotype
我认为你需要转义 \
,所以试试这个
^(?:([^;]*)\;?){1}
使用
SELECT
regexp_extract(col_value, '^(([^\;]*)\;){1}', 1) VARIABLE,
regexp_extract(col_value, '^(([^\;]*)\;){2}', 1) TipoType
from temp;
如果您需要不带“;”的列值, 使用:
SELECT regexp_extract(col_value, '^(([^\;]*)){1}', 1) VARIABLE,regexp_extract(col_value, '(([^\;]*)\;){2}', 2) TipoType from temp;
编辑:我附上了屏幕截图。它在我的系统上运行良好。不知道为什么不在你的身上执行。
我在配置单元中遇到正则表达式问题,它无法识别“;”。
insert overwrite table prueba
SELECT
regexp_extract(col_value, '^(?:([^;]*)\;?){1}', 1) VARIABLE,
regexp_extract(col_value, '^(?:([^;]*)\;?){2}', 1) TipoType
from temp;
发生的错误是:
H110 Unable to submit statement. Error while compiling statement:
FAILED: ParseException line 3:29 cannot recognize input near '^' ' (' '?'
In select expression [ERROR_STATUS]
示例数据:
VARIABLE;Tipo/Type;
FECHA;DATE;
ID_CLIENTE;CHAR;
CUS_TYPE;CHAR;
CUS_SUBTYPE;CHAR;
NUEVOTITU;NUMBER;
TITULAR;NUMBER;
BAJATITU;NUMBER;
.
.
.
代码:
drop table temp;
drop table prueba;
create table temp (col_value string);
LOAD DATA INPATH '/tmp/data/prueba.csv' OVERWRITE INTO TABLE temp;
create table prueba(variable string, tipotype string);
insert overwrite table prueba
SELECT
regexp_extract(col_value, '^(([^\;]*)\;){1}', 1) variable,
regexp_extract(col_value, '^(([^\;]*)\;){2}', 1) tipotype
from temp;
温度table:
temp.col_value
普鲁巴table:
prueba.variable prueba.tipotype
我认为你需要转义 \
,所以试试这个
^(?:([^;]*)\;?){1}
使用
SELECT
regexp_extract(col_value, '^(([^\;]*)\;){1}', 1) VARIABLE,
regexp_extract(col_value, '^(([^\;]*)\;){2}', 1) TipoType
from temp;
如果您需要不带“;”的列值, 使用:
SELECT regexp_extract(col_value, '^(([^\;]*)){1}', 1) VARIABLE,regexp_extract(col_value, '(([^\;]*)\;){2}', 2) TipoType from temp;
编辑:我附上了屏幕截图。它在我的系统上运行良好。不知道为什么不在你的身上执行。