How to create a small permanent relationship (table) in a pig?

Is there a way to create a small constant relationship (table) in a pig? I need to create a relationship with only one tuple that contains constant values. sort of:

A = LOAD using ConstantLoader('{(1,2,3)}'); 

thank you ido

+4
source share
3 answers

The quick answer is no.

I asked about this on the pig-dev mailing list .

+1
source

I'm not sure why you need this, but here's an ugly solution:

 A = LOAD 'some/sample/file' ; B = FOREACH A GENERATE '' ; C = LIMIT A 1 ; 

Now you can use 'C' as an "empty relation" having one empty tuple.

+2
source
 DEFINE GenerateRelationFromString(string) RETURNS relation { temp = LOAD 'somefile'; tempLimit1 = LIMIT temp 1; $relation = FOREACH tempLimit1 GENERATE FLATTEN(TOKENIZE('$string', ',')); }; 

using:

 fourRows = GenerateRelationFromString('1,2,3,4'); myConstantRelation = FOREACH fourRows GENERATE ( CASE $0 WHEN '1' THEN (1, 'Ivan') WHEN '2' THEN (2, 'Boris') WHEN '3' THEN (3, 'Vladimir') WHEN '4' THEN (4, 'Olga') END ) as myTuple; 

This is certainly a hack, and the correct way, in my opinion, would be to implement StringLoader (), which would work as follows:

 fourRows = LOAD '1,2,3,4' USING StringLoader(','); 

The argument commonly used for file location will only be used as an input to the litral line.

+1
source

Source: https://habr.com/ru/post/1446412/


All Articles