Author: ecapriolo
Date: Sun Jul  7 20:20:47 2013
New Revision: 1500531

URL: http://svn.apache.org/r1500531
Log:
HIVE-3475 INLINE UDTF does not convert types properly (Igor Kabiljo and Navis 
Ryu via egc)

Submitted by:   Navis Ryu and Igor Kabiljo
Reviewed by:    Edward Capriolo

Modified:
    
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTFInline.java
    hive/trunk/ql/src/test/queries/clientpositive/udf_inline.q
    hive/trunk/ql/src/test/results/clientpositive/udf_inline.q.out

Modified: 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTFInline.java
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTFInline.java?rev=1500531&r1=1500530&r2=1500531&view=diff
==============================================================================
--- 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTFInline.java
 (original)
+++ 
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTFInline.java
 Sun Jul  7 20:20:47 2013
@@ -1,27 +1,40 @@
+/**
+ * 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.hadoop.hive.ql.udf.generic;
 
-import java.util.List;
 import org.apache.hadoop.hive.ql.exec.Description;
 import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
-import org.apache.hadoop.hive.ql.udf.generic.GenericUDFUtils;
-import org.apache.hadoop.hive.ql.udf.generic.GenericUDTF;
 import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
-import org.apache.hadoop.hive.serde2.objectinspector.StructField;
 import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
 
+import java.util.ArrayList;
+
 @Description(name ="inline", value= "_FUNC_( ARRAY( STRUCT()[,STRUCT()] "
 + "- explodes and array and struct into a table")
 public class GenericUDTFInline extends GenericUDTF {
 
-  private Object[] forwardObj;
   private ListObjectInspector li;
-  private StructObjectInspector daStruct;
 
   public GenericUDTFInline(){
-
   }
 
   @Override
@@ -39,29 +52,13 @@ public class GenericUDTFInline extends G
     if (sub.getCategory() != Category.STRUCT){
       throw new UDFArgumentException("The sub element must be struct, but was 
"+sub.getTypeName());
     }
-    daStruct = (StructObjectInspector) sub;
-    forwardObj = new Object[daStruct.getAllStructFieldRefs().size()];
-    return daStruct;
+    return (StructObjectInspector) sub;
   }
 
   @Override
   public void process(Object[] os) throws HiveException {
-    //list is always one item
-    List l = li.getList(os);
-    List<? extends StructField> fields = this.daStruct.getAllStructFieldRefs();
-    for (Object linner: l ){
-      List<List> innerList = (List) linner;
-      for (List rowList : innerList){
-        int i=0;
-        for (StructField f: fields){
-          GenericUDFUtils.ReturnObjectInspectorResolver res
-            = new GenericUDFUtils.ReturnObjectInspectorResolver();
-          res.update(f.getFieldObjectInspector());
-          this.forwardObj[i]=res.convertIfNecessary(rowList.get(i), 
f.getFieldObjectInspector());
-          i++;
-        }
-        forward(this.forwardObj);
-      }
+    for (Object row : new ArrayList<Object>(li.getList(os[0]))) {
+      forward(row);
     }
   }
 

Modified: hive/trunk/ql/src/test/queries/clientpositive/udf_inline.q
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_inline.q?rev=1500531&r1=1500530&r2=1500531&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_inline.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_inline.q Sun Jul  7 
20:20:47 2013
@@ -16,3 +16,11 @@ SELECT inline( 
   )
 )  as (id, text) FROM SRC limit 2;
 
+-- HIVE-3475 INLINE UDTF doesn't convert types properly
+select * from (SELECT
+  ARRAY(
+    STRUCT (1,'dude!'),
+    STRUCT (2,'Wheres'),
+    STRUCT (3,'my car?')
+  ) as value FROM SRC limit 1) input
+ LATERAL VIEW inline(value) myTable AS id, text;

Modified: hive/trunk/ql/src/test/results/clientpositive/udf_inline.q.out
URL: 
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_inline.q.out?rev=1500531&r1=1500530&r2=1500531&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_inline.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_inline.q.out Sun Jul  7 
20:20:47 2013
@@ -75,3 +75,28 @@ POSTHOOK: Input: default@src
 #### A masked pattern was here ####
 1      dude!
 2      Wheres
+PREHOOK: query: -- HIVE-3475 INLINE UDTF doesn't convert types properly
+select * from (SELECT
+  ARRAY(
+    STRUCT (1,'dude!'),
+    STRUCT (2,'Wheres'),
+    STRUCT (3,'my car?')
+  ) as value FROM SRC limit 1) input
+ LATERAL VIEW inline(value) myTable AS id, text
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: -- HIVE-3475 INLINE UDTF doesn't convert types properly
+select * from (SELECT
+  ARRAY(
+    STRUCT (1,'dude!'),
+    STRUCT (2,'Wheres'),
+    STRUCT (3,'my car?')
+  ) as value FROM SRC limit 1) input
+ LATERAL VIEW inline(value) myTable AS id, text
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+[{"col1":1,"col2":"dude!"},{"col1":2,"col2":"Wheres"},{"col1":3,"col2":"my 
car?"}]     1       dude!
+[{"col1":1,"col2":"dude!"},{"col1":2,"col2":"Wheres"},{"col1":3,"col2":"my 
car?"}]     2       Wheres
+[{"col1":1,"col2":"dude!"},{"col1":2,"col2":"Wheres"},{"col1":3,"col2":"my 
car?"}]     3       my car?


Reply via email to