Error quering Avro Data using PIG, Utf8 cannot be cast to java.lang.String

857 views Asked by At

I have downloaded twitter data using flume into HDFS, but when I am trying to query it using PIG I am geting a class cast exception, cannot convert from utf-8 to String.

grunt> A= LOAD '/apps/hive/warehouse/twtr_uk.db/twitterdata_09062015/' USING AvroStorage ('{
>>   "type" : "record",
>>   "name" : "Doc",
>>   "doc" : "adoc",
>>   "fields" : [
>>   {
>>     "name" : "id",
>>     "type" : "string"
>>   },
>>   {
>>     "name" : "user_friends_count",
>>     "type" : [ "int", "null" ]
>>   },
>>   {
>>     "name" : "user_location",
>>     "type" : [ "string", "null" ]
>>   },
>>   {
>>     "name" : "user_description",
>>     "type" : [ "string", "null" ]
>>   }, {
>>     "name" : "user_statuses_count",
>>     "type" : [ "int", "null" ]
>>   }, {
>>     "name" : "user_followers_count",
>>     "type" : [ "int", "null" ]
>>   }, {
>>     "name" : "user_name",
>>     "type" : [ "string", "null" ]
>>   }, {
>>     "name" : "user_screen_name",
>>     "type" : [ "string", "null" ]
>>   }, {
>>     "name" : "created_at",
>>     "type" : [ "string", "null" ]
>>   }, {
>>     "name" : "text",
>>     "type" : [ "string", "null" ]
>>   }, {
>>     "name" : "retweet_count",
>>     "type" : [ "long", "null" ]
>>   }, {
>>     "name" : "retweeted",
>>     "type" : [ "boolean", "null" ]
>>   }, {
>>     "name" : "in_reply_to_user_id",
>>     "type" : [ "long", "null" ]
>>   }, {
>>     "name" : "source",
>>     "type" : [ "string", "null" ]
>>   }, {
>>     "name" : "in_reply_to_status_id",
>>     "type" : [ "long", "null" ]
>>   }, {
>>     "name" : "media_url_https",
>>     "type" : [ "string", "null" ]
>>   }, {
>>     "name" : "expanded_url",
>>     "type" : [ "string", "null" ]
>>   } ]
>> }');
grunt> illustrate A;
2015-06-11 10:07:05,361 [main] INFO  org.apache.pig.backend.hadoop.executionengine.HExecutionEngine - Connecting to hadoop file system at: hdfs://sandbox.hortonworks.com:8020
2015-06-11 10:07:05,382 [main] WARN  org.apache.pig.data.SchemaTupleBackend - SchemaTupleBackend has already been initialized
2015-06-11 10:07:05,382 [main] INFO  org.apache.pig.newplan.logical.optimizer.LogicalPlanOptimizer - {RULES_ENABLED=[ConstantCalculator, LoadTypeCastInserter, PredicatePushdownOptimizer, StreamTypeCastInserter], RULES_DISABLED=[AddForEach, ColumnMapKeyPrune, GroupByConstParallelSetter, LimitOptimizer, MergeFilter, MergeForEach, PartitionFilterOptimizer, PushDownForEachFlatten, PushUpFilter, SplitFilter]}
2015-06-11 10:07:05,383 [main] INFO  org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MRCompiler - File concatenation threshold: 100 optimistic? false
2015-06-11 10:07:05,384 [main] INFO  org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MultiQueryOptimizer - MR plan size before optimization: 1
2015-06-11 10:07:05,384 [main] INFO  org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.MultiQueryOptimizer - MR plan size after optimization: 1
2015-06-11 10:07:05,385 [main] INFO  org.apache.pig.tools.pigstats.mapreduce.MRScriptState - Pig script settings are added to the job
2015-06-11 10:07:05,385 [main] INFO  org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.JobControlCompiler - mapred.job.reduce.markreset.buffer.percent is not set, set to default 0.3
2015-06-11 10:07:05,426 [main] WARN  org.apache.pig.data.SchemaTupleBackend - SchemaTupleBackend has already been initialized
2015-06-11 10:07:05,426 [main] INFO  org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigMapOnly$Map - Aliases being processed per job phase (AliasName[line,offset]): M: A[123,3] C:  R:
2015-06-11 10:07:05,436 [main] INFO  org.apache.hadoop.mapreduce.lib.input.FileInputFormat - Total input paths to process : 6
2015-06-11 10:07:05,436 [main] INFO  org.apache.pig.backend.hadoop.executionengine.util.MapRedUtil - Total input paths to process : 6
java.lang.ClassCastException: org.apache.avro.util.Utf8 cannot be cast to java.lang.String
        at org.apache.pig.impl.util.avro.AvroTupleWrapper.getMemorySize(AvroTupleWrapper.java:201)
        at org.apache.pig.impl.util.avro.AvroTupleWrapper.getMemorySize(AvroTupleWrapper.java:178)
        at org.apache.pig.pen.util.ExampleTuple.getMemorySize(ExampleTuple.java:97)
        at org.apache.pig.data.DefaultAbstractBag.sampleContents(DefaultAbstractBag.java:101)

ERROR 2997: Encountered IOException. Exception

1

There are 1 answers

2
gbharat On

If you have avro data in hdfs you don't need to specify avro schema explicitly, try running like this below.

A= LOAD '/apps/hive/warehouse/twtr_uk.db/twitterdata_09062015/' USING AvroStorage ();