【问题标题】:Apache Pig: How to concat strings in load function?Apache Pig:如何在加载函数中连接字符串?
【发布时间】:2018-08-12 06:59:16
【问题描述】:

我是 Pig 新手,我想使用 Pig 从路径加载数据。该路径是动态的,并存储在一个 txt 文件中。假设我们有一个名为 pigInputPath.txt 的 txt 文件 在 pig 脚本中,我打算做以下事情:

首先使用以下方式加载路径:

InputPath = Load 'pigInputPath.txt' USING PigStorage();

第二次从路径加载数据使用:

Data = Load 'someprefix' + InputPath + 'somepostfix' USING PigStorage();

但这行不通。我也尝试过 CONCAT,但它也给了我一个错误。有人可以帮我弄这个吗。非常感谢!

【问题讨论】:

    标签: bash apache-pig


    【解决方案1】:

    首先,找到一种将输入路径作为参数传递的方法。 (参考:Hadoop Pig: Passing Command Line Argumentshttps://wiki.apache.org/pig/ParameterSubstitution

    假设您将脚本调用为pig -f script.pig -param inputPath=blah

    然后您可以从该路径使用所需的前缀和后缀LOAD,如下所示:

    Data = LOAD 'someprefix$inputPath/somepostfix' USING PigStorage();
    

    somepostfix 字符串的问题是需要使用/ 或其他此类特殊字符将其与参数分开,以告诉 pig 该字符串不是参数名称的一部分。

    避免使用特殊字符的一种方法是执行以下操作:

    %default prefix 'someprefix'
    %default postfix 'somepostfix'
    Data = LOAD '$prefix$inputPath$postfix' USING PigStorage();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 2016-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      相关资源
      最近更新 更多