【问题标题】:How to check data type inside pig UDF如何检查猪 UDF 中的数据类型
【发布时间】:2016-01-02 19:25:05
【问题描述】:

我是 Pig 脚本的新手。

我想编写一个过滤器 udf,而不考虑列的数据类型。

iput_data = load data '/emp.csv' using PigStorage(',') as (empid int, name chararray);

output = FILTER input_data by FilterUDF(empid);//data type is int

input_data1 = load data '/dept.csv' using pigStorage(',') as (deptid chararray, deptname chararray);

output1 = FILTER input_data by FilterUDF(deptid); //data type is chararray

现在,在 PigUdf 中,如何识别输入参数的数据类型? (即 input.get(0) 的数据类型)

import org.apache.pig.FilterFunc;
import java.io.IOException;
import org.apache.pig.data.Tuple;


public class FilterUDF extends FilterFunc {

    public Boolean exec(Tuple input) throws IOException {
        //How to check data type inside UDF
    }
}

【问题讨论】:

    标签: hadoop apache-pig udf


    【解决方案1】:

    您可能希望使用 getType() 方法来查找元组中各个元素的数据类型。看到这个link

    类似

    if (input.getType(0) == INTEGER) {
        // Do something here
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多