猪条件运算符 [英] Pig Conditional Operators

查看:71
本文介绍了猪条件运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下关系

test = LOAD 'input' USING PigStorage(',') as (a:chararray, b:chararray);

有没有办法实现以下目标

Is there a way to achieve the following

if (b == 1) {
    a = 'abc';
else if (b == 2) {
    a = 'xyz';
else 
    // retain whatever is there in the column 'a'

推荐答案

您可以执行FOREACH并使用三元运算符,如下所示.

You can do a FOREACH and use the ternary operator as follows.

test2 = FOREACH test GENERATE (b=='1' ? 'abc' : (b=='2' ? 'xyz' : a)) AS a, b;

这篇关于猪条件运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆