袋子和Pig中的Tuple Schema

时间:2016-04-02 16:28:59

标签: hadoop tuples schema apache-pig cloudera

我试图为尝试使用JsonLoader加载的某些数据指定架构,我要上传的数据格式为

Features:["Speedy","New","Automatic",..]

对于每条记录,功能的数量不固定,它可以是不同的。我在模式中表示为:

Features: bag{a: tuple(t:chararray)}

然而它不起作用。有人可以用正确的语法帮助我,并指出我错在哪里。

1 个答案:

答案 0 :(得分:0)

字段名称规范是不必要的,因为您有没有任何字段名称的简单数组。试试这个:

#include <iostream>
#include <cstdlib>
using namespace std;

void delete_element(double x[], int& n, int k);

int main()
{
    // example of a function
    int mass[10]={1,2,3,45,12,87,100,101,999,999};
    int len = 10;

    for(int i=0;i<10;i++)
    {
        cout<<mass[i]<<" ";
    };

    delete_element(mass[10],10&,4);

    for(int i=0;i<10;i++)
        cout<<mass[i]<<" ";

    return 0;
}

void delete_element(double x[], int& n, int k)
{
    if(k<1 || k>n)
    {
        cout<<"Wrong index of k "<<k<<endl;
        exit(1); // end program
    }

    for(int i = k-1;i<n-1;i++)
        x[i]=x[i+1];

    n--;
} 

Json文件:

a = load 'a.json' using JsonLoader('value:int,feature:{(chararray)}');

输出:

{"value":1, "feature":[1, 2, 3] }
{"value":2, "feature":[2,3,4]}
{"value":3, "feature":[12,13,14]}
{"value":4, "feature":[2]}