You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by da...@apache.org on 2010/06/11 19:51:37 UTC

svn commit: r953792 - in /hadoop/pig/trunk: CHANGES.txt src/org/apache/pig/data/DefaultTuple.java test/org/apache/pig/test/TestTuple.java test/org/apache/pig/test/TestTupleFormat.java

Author: daijy
Date: Fri Jun 11 17:51:36 2010
New Revision: 953792

URL: http://svn.apache.org/viewvc?rev=953792&view=rev
Log:
PIG-1443: DefaultTuple underestimate the memory footprint for string

Added:
    hadoop/pig/trunk/test/org/apache/pig/test/TestTuple.java
Removed:
    hadoop/pig/trunk/test/org/apache/pig/test/TestTupleFormat.java
Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/data/DefaultTuple.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=953792&r1=953791&r2=953792&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Fri Jun 11 17:51:36 2010
@@ -79,6 +79,8 @@ PIG-1309: Map-side Cogroup (ashutoshc)
 
 BUG FIXES
 
+PIG-1443: DefaultTuple underestimate the memory footprint for string (daijy)
+
 PIG-1446: OOME in a query having a bincond in the inner plan of a Foreach.(hashutosh)
 
 PIG-1433: pig should create success file if

Modified: hadoop/pig/trunk/src/org/apache/pig/data/DefaultTuple.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/data/DefaultTuple.java?rev=953792&r1=953791&r2=953792&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/data/DefaultTuple.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/data/DefaultTuple.java Fri Jun 11 17:51:36 2010
@@ -300,7 +300,8 @@ public class DefaultTuple implements Tup
 
             case DataType.CHARARRAY: {
                 String s = (String)o;
-                return s.length() * 2 + 12;
+                // See PIG-1443 for a reference for this formula
+                return 8 * (((s.length() * 2) + 45) / 8);
             }
 
             case DataType.TUPLE: {

Added: hadoop/pig/trunk/test/org/apache/pig/test/TestTuple.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestTuple.java?rev=953792&view=auto
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestTuple.java (added)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestTuple.java Fri Jun 11 17:51:36 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.BagFactory;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.impl.util.TupleFormat;
+
+public class TestTuple extends TestCase {
+
+    public void testTupleFormat() {
+
+        try {
+            Tuple tuple = TupleFactory.getInstance().newTuple(7);
+            tuple.set(0, 12);
+            Map<String, String> map = new HashMap<String, String>();
+            map.put("pig", "scalability");
+            tuple.set(1, map);
+            tuple.set(2, null);
+            tuple.set(3, 12L);
+            tuple.set(4, 1.2F);
+
+            Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
+            innerTuple.set(0, "innerTuple");
+            tuple.set(5, innerTuple);
+
+            DataBag bag = BagFactory.getInstance().newDefaultBag();
+            bag.add(innerTuple);
+            tuple.set(6, bag);
+
+            assertEquals(
+                    "(12,[pig#scalability],,12,1.2,(innerTuple),{(innerTuple)})",
+                    TupleFormat.format(tuple));
+        } catch (ExecException e) {
+            e.printStackTrace();
+            fail();
+        }
+
+    }
+    
+    // See PIG-1443
+    public void testTupleSizeWithString() {
+        Tuple t = Util.createTuple(new String[] {"1234567", "bar"});
+        long size = t.getMemorySize();
+        assertTrue(size==156);
+    }
+}