[
https://issues.apache.org/jira/browse/PIG-2330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13662567#comment-13662567
]
Viraj Bhat commented on PIG-2330:
---------------------------------
Hi,
The issue here is not related to : PIG-3322. The 1 line fix should solve the
above problem.
Consider a change in the script to add TOTUPLE: The below works to generate the
following
{code}
A = load 'input.txt' AS (name1:chararray, name2:chararray);
B = foreach A generate TOTUPLE($0);
dump B;
store B into 'singlefieldoutput' using
org.apache.pig.piggybank.storage.avro.AvroStorage('{"schema": {"type":
"record", "name": "main", "fields": [{"name": "name", "type": ["null",
"string"]}]}}')
{code}
Output
{noformat}
((Viraj))
((Roh))
((Govind))
{noformat}
The table provided in: https://cwiki.apache.org/PIG/avrostorage.html shows that
it is possible to convert from Pig Tuple to Avro Record as they are set of
ordered fields. But is not possible to convert from "chararray" to "record". In
Pig you cannot generate a single chararray, it is always wrapped by a tuple.
Try loading the output generated by the older Pig script.
{code}
A = load 'singlefieldoutput' using
org.apache.pig.piggybank.storage.avro.AvroStorage();
describe A;
dump A;
{code}
Now we see the following:
{noformat}
(Viraj)
(Roh)
(Govind)
{noformat}
Which is different from "dump B"
Viraj
> Problem in org.apache.pig.piggybank.storage.avro.AvroStorage when storing a
> record with a single field.
> -------------------------------------------------------------------------------------------------------
>
> Key: PIG-2330
> URL: https://issues.apache.org/jira/browse/PIG-2330
> Project: Pig
> Issue Type: Bug
> Components: piggybank
> Affects Versions: 0.9.0
> Reporter: Stan Rosenberg
> Attachments: AvroStorage.patch, input.txt
>
>
> Running the following script yields a RuntimeException. If the schema is
> changed to contain two fields, then A can be stored successfully.
> {noformat}
> REGISTER 'piggybank.jar'
> REGISTER 'avro-1.5.4.jar'
> REGISTER 'json-simple-1.1.jar'
> A = load 'input.txt' AS (name1:chararray, name2:chararray);
> B = foreach A generate $0;
> store B into './output' using
> org.apache.pig.piggybank.storage.avro.AvroStorage(
> '{"schema": {"type": "record", "name": "main", "fields": [{"name": "name",
> "type": ["null", "string"]}]}}');
> {noformat}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira