Author: gates Date: Fri Oct 23 17:01:24 2009 New Revision: 829126 URL: http://svn.apache.org/viewvc?rev=829126&view=rev Log: PIG-1027: Number of bytes written are always zero in local mode.
Added: hadoop/pig/trunk/test/org/apache/pig/test/TestPigStats.java Modified: hadoop/pig/trunk/CHANGES.txt hadoop/pig/trunk/src/org/apache/pig/tools/pigstats/PigStats.java Modified: hadoop/pig/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=829126&r1=829125&r2=829126&view=diff ============================================================================== --- hadoop/pig/trunk/CHANGES.txt (original) +++ hadoop/pig/trunk/CHANGES.txt Fri Oct 23 17:01:24 2009 @@ -78,6 +78,8 @@ BUG FIXES +PIG-1027: Number of bytes written are always zero in local mode (zjffdu via gates). + PIG-976: Multi-query optimization throws ClassCastException (rding via pradeepkth) Modified: hadoop/pig/trunk/src/org/apache/pig/tools/pigstats/PigStats.java URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/tools/pigstats/PigStats.java?rev=829126&r1=829125&r2=829126&view=diff ============================================================================== --- hadoop/pig/trunk/src/org/apache/pig/tools/pigstats/PigStats.java (original) +++ hadoop/pig/trunk/src/org/apache/pig/tools/pigstats/PigStats.java Fri Oct 23 17:01:24 2009 @@ -102,11 +102,19 @@ stats.put(op.toString(), jobStats); POCounter counter = (POCounter) php.getPredecessors(op).get(0); jobStats.put("PIG_STATS_LOCAL_OUTPUT_RECORDS", (Long.valueOf(counter.getCount())).toString()); - jobStats.put("PIG_STATS_LOCAL_BYTES_WRITTEN", (Long.valueOf((new File(((POStore)op).getSFile().getFileName())).length())).toString()); + String localFilePath=normalizeToLocalFilePath(((POStore)op).getSFile().getFileName()); + jobStats.put("PIG_STATS_LOCAL_BYTES_WRITTEN", (Long.valueOf(new File(localFilePath).length())).toString()); } return stats; } + private String normalizeToLocalFilePath(String fileName) { + if (fileName.startsWith("file:")){ + return fileName.substring(5); + } + return fileName; + } + private Map<String, Map<String, String>> accumulateMRStats() throws ExecException { for(Job job : jc.getSuccessfulJobs()) { Added: hadoop/pig/trunk/test/org/apache/pig/test/TestPigStats.java URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestPigStats.java?rev=829126&view=auto ============================================================================== --- hadoop/pig/trunk/test/org/apache/pig/test/TestPigStats.java (added) +++ hadoop/pig/trunk/test/org/apache/pig/test/TestPigStats.java Fri Oct 23 17:01:24 2009 @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.pig.test; + +import java.io.File; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.apache.pig.ExecType; +import org.apache.pig.PigServer; +import org.apache.pig.tools.pigstats.PigStats; + +public class TestPigStats extends TestCase { + + public void testBytesWritten_JIRA_1027() { + + File outputFile = null; + try { + outputFile = File.createTempFile("JIAR_1027", ".out"); + PigServer pig = new PigServer(ExecType.LOCAL); + pig + .registerQuery("A = load 'test/org/apache/pig/test/data/passwd';"); + PigStats stats = pig.store("A", outputFile.getAbsolutePath()) + .getStatistics(); + assertEquals(outputFile.length(), stats.getBytesWritten()); + } catch (IOException e) { + fail("IOException happened"); + } finally { + if (outputFile != null) { + outputFile.delete(); + } + } + + } +}