声明一个逗号分隔的字符串常量 [英] Declare a comma seperated string constant

查看:26
本文介绍了声明一个逗号分隔的字符串常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:声明一个逗号分隔的字符串常量

    test.csv
    =========
    a
    b
    c
    d
    e
    f

猪脚本:

  %declare ACTIVE_VALUES 'a', 'b','c' ; 

  -- Declaring constant like this using "" (double quotes) or even using escape characters (\) is resulting in a WARN message as below 
  -- WARN  org.apache.pig.tools.parameters.PreprocessorContext - Warning : Multiple values found for ACTIVE_VALUES

  A = LOAD 'test.csv' using PigStorage(',') AS (value:chararray);
  B = FILTER A BY value in ($ACTIVE_VALUES);
  dump B;

预期输出:

 a
 b
 c

在 Pig 中声明逗号分隔字符串常量的任何输入.

Any inputs on declaring a comma separated string constant in Pig.

-- 像这样使用"(双引号)甚至使用转义字符(\)声明常量会导致如下警告消息

-- Declaring constant like this using "" (double quotes) or even using escape characters (\) is resulting in a WARN message as below

-- 警告 org.apache.pig.tools.parameters.PreprocessorContext - 警告:为 ACTIVE_VALUES 找到多个值

-- WARN org.apache.pig.tools.parameters.PreprocessorContext - Warning : Multiple values found for ACTIVE_VALUES

推荐答案

您可以使用单个逗号分隔的字符串 ('a,b,c') 并使用 STRSPLIT (https://pig.apache.org/docs/r0.9.1/func.html#strsplit) ACTIVE_VALUES 函数获取字符包,可以将其压平以创建多个记录.可以将这些数据与测试文件中的数据进行 INNER JOIN,以获得所需的结果.

You can use a single comma delimited string ('a,b,c') and use STRSPLIT (https://pig.apache.org/docs/r0.9.1/func.html#strsplit) function on ACTIVE_VALUES to get bag of characters, which can be FLATTEN'd to create multiple records. This data can be INNER JOIN'ed with data from test file to get the desired results.

这篇关于声明一个逗号分隔的字符串常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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