Return-Path: X-Original-To: apmail-hadoop-hdfs-user-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AE9FCDCDE for ; Mon, 19 Nov 2012 19:12:06 +0000 (UTC) Received: (qmail 29017 invoked by uid 500); 19 Nov 2012 19:12:01 -0000 Delivered-To: apmail-hadoop-hdfs-user-archive@hadoop.apache.org Received: (qmail 28902 invoked by uid 500); 19 Nov 2012 19:12:01 -0000 Mailing-List: contact user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hadoop.apache.org Delivered-To: mailing list user@hadoop.apache.org Received: (qmail 28893 invoked by uid 99); 19 Nov 2012 19:12:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2012 19:12:01 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of harsh@cloudera.com designates 209.85.210.176 as permitted sender) Received: from [209.85.210.176] (HELO mail-ia0-f176.google.com) (209.85.210.176) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2012 19:11:55 +0000 Received: by mail-ia0-f176.google.com with SMTP id k32so2123381iak.35 for ; Mon, 19 Nov 2012 11:11:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:x-gm-message-state; bh=XH2lciOvo73tda4J8AeVZFn/f1LUpIZ+t18rNWQW2jY=; b=UXJACHAqiLy7ccEf9nD/yh7dk+U1Gv1wYZe7uRhHismYLdJZBOwYtN6SeaSiU5zv1x um5SurpTsLAtbs9etkm6XpOxZ5ZqVZxfcTUM4Opn1D7xG2Fho0VLNJWKJRl+l+TNNK8u gExhw8ShG0bgMN+9evMOmaIlXv+TNB2nnLGEYyAiewcrGiXNghjTC+Pa96xbmsBlkrKL GJr0Pibq6Z97SVaTXcHoNCsDMPnMrRlnqLE1HyLqEZ1IxP7pboij18NKW+YZsvUneLxi TVX1oVFrkPCLIry/fX3nuCeSmEo0Fl3qI8EJMQRFDEkzTQ19W0S87/mDBhPSF97tcNuy 6ivw== Received: by 10.50.140.103 with SMTP id rf7mr7566127igb.56.1353352294264; Mon, 19 Nov 2012 11:11:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.64.41 with HTTP; Mon, 19 Nov 2012 11:11:13 -0800 (PST) In-Reply-To: <1353292543.91431.YahooMailNeo@web125404.mail.ne1.yahoo.com> References: <1353292543.91431.YahooMailNeo@web125404.mail.ne1.yahoo.com> From: Harsh J Date: Tue, 20 Nov 2012 00:41:13 +0530 Message-ID: Subject: Re: java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to java.lang.String To: user@hadoop.apache.org, Utester Utester Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQncwqXlyXVUBqjvtdPfV8BFAjiyRoeucSKfq/hEitOaHjuPAkkRqiv0mCA2B6XX7RvNjlKZ X-Virus-Checked: Checked by ClamAV on apache.org Hi, 1. Map/Reduce in 1.x. does not know how to efficiently and automatically serialize regular Java types such as String, Long, etc.. There is experimental (and I wouldn't recommend using it either) Java serialization support for such types in 2.x releases if you enable the JavaSerialization classes. Please use Writable-based native type classes (such as Text for String, LongWritable for long, etc.). 2. The type checking is done based on configuration at runtime. What you set as JobConf.setOutput[Key/Value]Class and JobConf.setMapOutput[Key/Value]Class (or similar new API equivalents) will be checked for passing instances of key and value objects during runtime. By default, these are LongWritable (key) and Text (value) and you see the former in your error. On Mon, Nov 19, 2012 at 8:05 AM, Utester Utester wrote: > Hi, > > I have Hadoop 1.0.3 running on Ubuntu Linux. I am playing around with a > simple Map-Reduce job. > > Details of the code > ============= > 1. Since this exercise is mainly to learn basic Hadoop APIs and learn how to > run these jobs, the logic in the Map job is irrelevant. > 2. The code snippet is below with just the APIs (which I believe is causing > a problem - PLEASE correct me if I am wrong and I will post the entire code > snippet) > public > class JobOrganizer > > .... > .... > public > static class JobOrganizerMapper extends MapReduceBase implements > Mapper { > > @Override > public void map(String sourceKey, String sourceValue, > OutputCollector outputC, > Reporter reporter) throws IOException { > ... > ... > } > > } > > Exception: > > hduser@utester-VirtualBox:/usr/local/hadoop/bin$ > /usr/local/hadoop/bin/hadoop jar > ~/HadoopCodeProjectsFolder/JobOrganizerMapRedProject/11182012/HadoopMapRedProject.jar > org.u.hadoopmapred.JobOrganizer > Warning: $HADOOP_HOME is deprecated. > 12/11/18 16:36:22 WARN mapred.JobClient: Use GenericOptionsParser for > parsing the arguments. Applications should implement Tool for the same. > 12/11/18 16:36:22 INFO util.NativeCodeLoader: Loaded the native-hadoop > library > 12/11/18 16:36:22 WARN snappy.LoadSnappy: Snappy native library not loaded > 12/11/18 16:36:22 INFO mapred.FileInputFormat: Total input paths to process > : 1 > 12/11/18 16:36:22 INFO mapred.JobClient: Running job: job_201211181608_0002 > 12/11/18 16:36:23 INFO mapred.JobClient: map 0% reduce 0% > 12/11/18 16:36:42 INFO mapred.JobClient: Task Id : > attempt_201211181608_0002_m_000000_0, Status : FAILED > java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be > cast to java.lang.String > at > org.u.hadoopmapred.JobOrganizer$JobOrganizerMapper.map(JobOrganizer.java:1) > at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:50) > at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:436) > > > The Mapper Interface as per the javadoc is: Interface Mapper V2> and its map function is: map(K1 key, V1 value, OutputCollector > output, Reporter). I wanted to parameterize K1, V1, K2, V2 to all be String. > Is something wrong in the way I am thinking? Is this what is wrong? I have > found similar questions on the internet but the asnwers did not clarify how > I am breaking the Mapper contract (I did not have any compile errors - just > a runtime error). > > > > Thanks -- Harsh J