Author: daijy
Date: Sun Sep 26 21:16:47 2010
New Revision: 1001519

URL: http://svn.apache.org/viewvc?rev=1001519&view=rev
Log:
PIG-1643: join fails for a query with input having 'load using pigstorage 
without schema' + 'foreach'

Added:
    hadoop/pig/trunk/test/org/apache/pig/test/TestForEachStar.java
Modified:
    hadoop/pig/trunk/CHANGES.txt
    
hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java
    
hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=1001519&r1=1001518&r2=1001519&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Sun Sep 26 21:16:47 2010
@@ -207,6 +207,9 @@ PIG-1309: Map-side Cogroup (ashutoshc)
 
 BUG FIXES
 
+PIG-1643: join fails for a query with input having 'load using pigstorage
+without schema' + 'foreach' (daijy)
+
 PIG-1645: Using both small split combination and temporary file compression on 
a query of ORDER BY may cause crash (yanz)
 
 PIG-1635: Logical simplifier does not simplify away constants under AND and 
OR; after simplificaion the ordering of operands of

Modified: 
hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java?rev=1001519&r1=1001518&r2=1001519&view=diff
==============================================================================
--- 
hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java
 (original)
+++ 
hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/LogicalExpression.java
 Sun Sep 26 21:16:47 2010
@@ -72,9 +72,9 @@ public abstract class LogicalExpression 
      * @return data type, one of the static bytes of DataType
      */
     public byte getType() throws FrontendException {
-        if (getFieldSchema()!=null)
+        if (getFieldSchema()!=null && getFieldSchema().type!=DataType.NULL)
             return getFieldSchema().type;
-        return DataType.UNKNOWN;
+        return DataType.BYTEARRAY;
     }
     
     public String toString() {

Modified: 
hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java?rev=1001519&r1=1001518&r2=1001519&view=diff
==============================================================================
--- 
hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java
 (original)
+++ 
hadoop/pig/trunk/src/org/apache/pig/newplan/logical/expression/ProjectExpression.java
 Sun Sep 26 21:16:47 2010
@@ -149,11 +149,8 @@ public class ProjectExpression extends C
                 if (findReferent().getSchema()!=null)
                     fieldSchema = findReferent().getSchema().getField(0);
             }
-            if(fieldSchema == null){
-                fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, 
DataType.BYTEARRAY);
-            }
-            uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
-            
+            if (fieldSchema!=null)
+                uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
         }
         else {
             if (schema == null) {

Added: hadoop/pig/trunk/test/org/apache/pig/test/TestForEachStar.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestForEachStar.java?rev=1001519&view=auto
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestForEachStar.java (added)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestForEachStar.java Sun Sep 26 
21:16:47 2010
@@ -0,0 +1,95 @@
+/*
+ * 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 static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.pig.ExecType;
+import org.apache.pig.PigServer;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.DataByteArray;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.impl.logicalLayer.parser.ParseException;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * Test "foreach alias generate *"
+ */
+public class TestForEachStar {
+    
+
+    
+    
+    private static final String INPUT_FILE = "TestForEachStarInput";
+
+
+
+    @BeforeClass
+    public static void oneTimeSetup() throws Exception{
+        String[] input = { "one\ttwo" };
+        Util.createLocalInputFile(INPUT_FILE, input);
+    }
+    @AfterClass
+    public static void oneTimeTearDown() throws Exception {
+        new File(INPUT_FILE).delete();
+    }
+ 
+    
+    @Before
+    public void setUp() throws Exception {
+
+    }
+  
+
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @Test
+    public void testForeachStarSchemaUnkown() throws IOException, 
ParseException{
+        PigServer pig = new PigServer(ExecType.LOCAL);
+        String query =
+            "  l1 = load '" + INPUT_FILE + "' ;"
+            + "f1 = foreach l1 generate * ;"
+        ; 
+        Util.registerMultiLineQuery(pig, query);
+        Iterator<Tuple> it = pig.openIterator("f1");
+        
+        Tuple expectedResCharArray = 
(Tuple)Util.getPigConstant("('one','two')");
+        Tuple expectedRes = TupleFactory.getInstance().newTuple();
+        for(Object field :  expectedResCharArray.getAll() ){
+            expectedRes.append(new DataByteArray(field.toString()));
+        }
+        assertTrue("has output", it.hasNext());
+        assertEquals(expectedRes, it.next());
+    }
+    
+    
+    
+}


Reply via email to