无法将pig中的字符数组转换为十进制

eit6fx6z  于 2021-06-25  发布在  Pig
关注(0)|答案(1)|浏览(321)

嗨,我是Pig编程新手。我有一个csv文件和制表符作为分隔符。在我的价格栏里我有拉克和克。看起来像这样 40.85 Lacs , 36.73 Lacs , 2.01 cr . 我想像这样转换成十进制

40.85 Lacs - 40,85,000
36.73 Lacs - 36,73,000
2.01 cr - 2,01,00000

我尝试了以下代码:

a = LOAD '/user/user1/input/city/cityname.CSV' using PigStorage('|') as (SourceWebSite:chararray,PropertyID:chararray,ListedOn:chararray,ContactName:chararray,TotalViews:int,Price:chararray,PriceperArea:chararray,NoOfBedRooms:int,NoOfBathRooms:int,FloorNoOfProperty:chararray,TotalFloors:int,Possession:chararray,BuiltUpArea:chararray,Furnished:chararray,Ownership:chararray,NewResale:chararray,Facing:chararray,title:chararray,PropertyAddress:chararray,NearByFacilities:chararray,PropertyFeatures:chararray,Sellerinfo:chararray,Description:chararray);
DUMP a;
b = FOREACH a GENERATE Price;
dump b;
c = FILTER b BY (Price matches '.*Lacs.*');
d = FOREACH c GENERATE Price * 10000.0,SUBSTRING(Price,00000);
d = foreach c generate Price,TOKENIZE(REPLACE(Price,'.','')) AS e;

我在这里挣扎了两天。任何帮助都将不胜感激。

vc6uscn9

vc6uscn91#

使用 REGEX_EXTRACT 若要获取值的第一部分,直到空白,将其转换为BigDigMall,然后将其相乘。使用此输入数据,例如:

(40.85 Lacs,1)
(36.73 Lacs,2)
(2.01 cr,3)

以下代码将起作用:

A = load 'data' using PigStorage(';');
B = foreach A generate (bigdecimal)REGEX_EXTRACT($0, '(.*) (.*)', 1) * 1000000;
dump B;

结果是:

(40850000.00)
(36730000.00)
(2010000.00)

相关问题