Support Questions

# Pig Incompatable schema vamsi123
Contributor

my input file is below

```a.txt

aaa.kyl,data,data
bbb.kkk,data,data
cccccc.hj,data,data
qa.dff,data,data
```

A = LOAD '/pigdata/a.txt' USING PigStorage(',') AS(a1:chararray,a2:chararray,a3:chararray);

How to resolve below error and what is the reason for this error

```ERROR:-
C = FOREACH A GENERATE STRSPLIT(a1,'\\u002E') as (a1:chararray, a1of1:chararray),a2,a3;
2017-02-03 00:45:42,803 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1031: Incompatable schema: left is "a1:chararray,a1of1:chararray", right is ":tuple()"
```
1 ACCEPTED SOLUTION adnanalvee
Expert Contributor

You need to flatten the STRSPLIT before you can project.

```C = FOREACH A GENERATE FLATTEN(STRSPLIT(a1,'\\u002E')) as (a1:chararray, a1of1:chararray),a2,a3;
```
7 REPLIES 7 adnanalvee
Expert Contributor

You need to flatten the STRSPLIT before you can project.

```C = FOREACH A GENERATE FLATTEN(STRSPLIT(a1,'\\u002E')) as (a1:chararray, a1of1:chararray),a2,a3;
``` vamsi123
Contributor

Thanks for input.what is the problem with my relation C.

STRSPLIT will generate tuple as output.Here it will consists of two fields in a tuple.

(a1:chararray, a1of1:chararray) is also a tuple since it is enclosed in parentheses and also consists of two fields vamsi123
Contributor

Any input on my clarification adnanalvee
Expert Contributor

@vamsi valiveti

The result of the code you wrote gives the schema tike this

```((a1),(a1of1)),(a2),(a3)
```

Now your projection wouldn't work in a data schema like this as Pig still considers the first two rows which is

"((a1),(a1of1))" as one. You need to use flatten for this case to make it into two separate columns.

Thats exactly what my code is doing. I tested your data using my code. works perfectly. pminovic Guru

The output of STRSPLIT is a tuple, so if you want to provide its schema you need to explicitly say for example "t1:tuple", like below, and after that you can refer to it as t1.a1 and t1.a1of1. With FLATTEN you get rid of the tuple. So you can choose which way to declare it.

```grunt> b = FOREACH a generate STRSPLIT(a1,'\\u002E') as (t1:tuple(a1:chararray,a1of1:chararray)), a2, a3;
grunt> describe b;
b: {t1: (a1: chararray,a1of1: chararray),a2: chararray,a3: chararray}
grunt> c = foreach b generate t1.a1, a3;``` pminovic Guru vamsi123
Contributor

Thanks for comments.I will do it definately starting from this post. Take a Tour of the Community
Don't have an account?
{"ft_lang_label":"__label__en","ft_lang_prob":0.9081554,"math_prob":0.8468647,"size":3031,"snap":"2022-27-2022-33","text_gpt3_token_len":899,"char_repetition_ratio":0.13941196,"word_repetition_ratio":0.06681035,"special_character_ratio":0.29198283,"punctuation_ratio":0.18534483,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95978886,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-30T18:41:51Z\",\"WARC-Record-ID\":\"<urn:uuid:15537f69-6679-494c-a30c-0378892da4a6>\",\"Content-Length\":\"296660\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:85af2189-ea99-41d5-947a-8c942a5b8d61>\",\"WARC-Concurrent-To\":\"<urn:uuid:3e909670-edab-4ade-a340-3c771b5c89ed>\",\"WARC-IP-Address\":\"18.67.76.81\",\"WARC-Target-URI\":\"https://community.cloudera.com/t5/Support-Questions/Pig-Incompatable-schema/m-p/133942\",\"WARC-Payload-Digest\":\"sha1:EZZT27KJYDRT6ZCDX6A2UZAHGBC3S6RD\",\"WARC-Block-Digest\":\"sha1:XBXHSE5Q6MF6HW2CF4PAYJ7L7LUGNKHB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103877410.46_warc_CC-MAIN-20220630183616-20220630213616-00588.warc.gz\"}"}