繁体   English   中英

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无法提交对帐单。 编译语句时出错:
失败:ParseException第3:29行无法识别'^''(('?'
在选择表达式[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;

临时表:

temp.col_value

普鲁巴表:

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;

编辑:我已经附上了截图。 我的系统运行正常。 不知道为什么不对您执行。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM