本文介绍了CAS中的声明在PIG中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  SUBSTRING(geocode,0, 2)---->代码
00-51 ----> 01
70 ----> 03
61-78 ----> 04
Else ----> 00

现在获得的'code'值必须与'geocode'值(前缀)和(后缀)再次与00连接以形成'vertex_code'例如: geocode = 44556677

/ p>

if SUBSTRING(geocode,0,2)介于 00-51 ,然后 code = 01



因此vertex_code = 014455667700

以下是我的脚本:

  item = load'/user/item.txt'使用PigStorage(' |')AS(load_id:chararray,record_type:chararray,geocode:chararray); 

newitem = FOREACH item GENERATE load_id,record_type,
(CASE(SUBSTRING(geocode,0,2))
当00-51那么'CONCAT(01,CONCAT(geocode (03,CONCAT(geocode,00))'
当61-78那么'CONCAT(04,CONCAT(geocode,00))'
ELSE'CONCAT(00,CONCAT(geocode,00))'
END)AS vertex_code;

DUMP newitem;

我得到以下错误:

非常感谢帮助。 p>

解决方案

您必须将其转换为int,然后进行比较

  newitem = FOREACH item GENERATE load_id,record_type,
(CASE
WHEN((int)SUBSTRING(geocode,0,2)< = 51 THEN CONCAT('01', CONCAT(geocode,'00'))
WHEN((int)SUBSTRING(geocode,0,2)= 70 THEN CONCAT('03',CONCAT(geocode,'00'))
WHEN (int)SUBSTRING(geocode,0,2)> = 61和((int)SUBSTRING(geocode,0,2)< = 78 THEN CONCAT('04',CONCAT(geocode,'00'))
ELSE CONCAT('00',CONCAT(geocode,'00'))
END)as vertex_code;

DUMP newitem;


I am trying to extract 'vertex_code' from 'geocode' based on few conditions:

SUBSTRING(geocode,0,2) ----> Code
00-51 ----> 01
70    ----> 03
61-78 ----> 04
Else ----> 00

Now the obtained 'code' value has to be concatenated with 'geocode' value (prefix) and again concatenated with 00 at the end (suffix) to form the 'vertex_code'

eg: geocode = 44556677

if SUBSTRING(geocode,0,2) is between 00-51, then code=01

hence vertex_code = 014455667700

Below is my script:

item = load '/user/item.txt' USING PigStorage('|') AS (load_id:chararray, record_type:chararray, geocode:chararray);

newitem = FOREACH item GENERATE load_id, record_type,
(CASE (SUBSTRING(geocode,0,2))
 WHEN 00-51 THEN 'CONCAT(01,CONCAT(geocode,00))'
 WHEN 70 THEN 'CONCAT(03,CONCAT(geocode,00))'
 WHEN 61-78 THEN 'CONCAT(04,CONCAT(geocode,00))'
 ELSE 'CONCAT(00,CONCAT(geocode,00))'
 END) AS vertex_code;

DUMP newitem;

I get the below error:

Help is greatly appreciated.

解决方案

You have to cast it to int and then compare

newitem = FOREACH item GENERATE load_id, record_type,
(CASE
 WHEN ((int)SUBSTRING(geocode,0,2) <= 51  THEN CONCAT('01',CONCAT(geocode,'00'))
 WHEN ((int)SUBSTRING(geocode,0,2) = 70 THEN CONCAT('03',CONCAT(geocode,'00'))
 WHEN ((int)SUBSTRING(geocode,0,2) >= 61 and ((int)SUBSTRING(geocode,0,2) <=78 THEN CONCAT('04',CONCAT(geocode,'00'))
 ELSE CONCAT('00',CONCAT(geocode,'00'))
 END) AS vertex_code;

DUMP newitem;

这篇关于CAS中的声明在PIG中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 07:46