hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hashut...@apache.org
Subject svn commit: r1540489 - in /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql: exec/UDTFOperator.java parse/SemanticAnalyzer.java udf/generic/GenericUDTF.java
Date Sun, 10 Nov 2013 16:33:08 GMT
Author: hashutosh
Date: Sun Nov 10 16:33:08 2013
New Revision: 1540489

URL: http://svn.apache.org/r1540489
Log:
HIVE-5737 : Provide StructObjectInspector for UDTFs rather than ObjectInspect[] (Navis via
Ashutosh Chauhan)

Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTF.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java?rev=1540489&r1=1540488&r2=1540489&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDTFOperator.java Sun Nov 10 16:33:08
2013
@@ -44,7 +44,7 @@ public class UDTFOperator extends Operat
 
   protected final Log LOG = LogFactory.getLog(this.getClass().getName());
 
-  ObjectInspector[] udtfInputOIs = null;
+  StructObjectInspector udtfInputOI = null;
   Object[] objToSendToUDTF = null;
 
   GenericUDTF genericUDTF;
@@ -63,22 +63,16 @@ public class UDTFOperator extends Operat
 
     genericUDTF.setCollector(collector);
 
-    // Make an object inspector [] of the arguments to the UDTF
-    List<? extends StructField> inputFields =
-        ((StructObjectInspector) inputObjInspectors[0]).getAllStructFieldRefs();
-
-    udtfInputOIs = new ObjectInspector[inputFields.size()];
-    for (int i = 0; i < inputFields.size(); i++) {
-      udtfInputOIs[i] = inputFields.get(i).getFieldObjectInspector();
-    }
-    objToSendToUDTF = new Object[inputFields.size()];
+    udtfInputOI = (StructObjectInspector) inputObjInspectors[0];
+
+    objToSendToUDTF = new Object[udtfInputOI.getAllStructFieldRefs().size()];
 
     MapredContext context = MapredContext.get();
     if (context != null) {
       context.setup(genericUDTF);
     }
-    StructObjectInspector udtfOutputOI = genericUDTF.initialize(
-        udtfInputOIs);
+    StructObjectInspector udtfOutputOI = genericUDTF.initialize(udtfInputOI);
+
     if (conf.isOuterLV()) {
       outerObj = Arrays.asList(new Object[udtfOutputOI.getAllStructFieldRefs().size()]);
     }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1540489&r1=1540488&r2=1540489&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Sun Nov 10
16:33:08 2013
@@ -20,6 +20,7 @@ package org.apache.hadoop.hive.ql.parse;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -166,6 +167,8 @@ import org.apache.hadoop.hive.serde2.laz
 import org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
+import org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector;
 import org.apache.hadoop.hive.serde2.objectinspector.StructField;
 import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
 import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
@@ -5708,7 +5711,9 @@ public class SemanticAnalyzer extends Ba
       colNames.add(inputCols.get(i).getInternalName());
       colOIs[i] = inputCols.get(i).getObjectInspector();
     }
-    StructObjectInspector outputOI = genericUDTF.initialize(colOIs);
+    StandardStructObjectInspector rowOI =
+        ObjectInspectorFactory.getStandardStructObjectInspector(colNames, Arrays.asList(colOIs));
+    StructObjectInspector outputOI = genericUDTF.initialize(rowOI);
 
     int numUdtfCols = outputOI.getAllStructFieldRefs().size();
     if (colAliases.isEmpty()) {

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTF.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTF.java?rev=1540489&r1=1540488&r2=1540489&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTF.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTF.java Sun Nov
10 16:33:08 2013
@@ -18,10 +18,13 @@
 
 package org.apache.hadoop.hive.ql.udf.generic;
 
+import java.util.List;
+
 import org.apache.hadoop.hive.ql.exec.MapredContext;
 import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructField;
 import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
 
 /**
@@ -43,6 +46,16 @@ public abstract class GenericUDTF {
   public void configure(MapredContext mapredContext) {
   }
 
+  public StructObjectInspector initialize(StructObjectInspector argOIs)
+      throws UDFArgumentException {
+    List<? extends StructField> inputFields = argOIs.getAllStructFieldRefs();
+    ObjectInspector[] udtfInputOIs = new ObjectInspector[inputFields.size()];
+    for (int i = 0; i < inputFields.size(); i++) {
+      udtfInputOIs[i] = inputFields.get(i).getFieldObjectInspector();
+    }
+    return initialize(udtfInputOIs);
+  }
+
   /**
    * Initialize this GenericUDTF. This will be called only once per instance.
    *
@@ -53,8 +66,11 @@ public abstract class GenericUDTF {
    *         field names are unimportant as they will be overridden by user
    *         supplied column aliases.
    */
-  public abstract StructObjectInspector initialize(ObjectInspector[] argOIs)
-      throws UDFArgumentException;
+  @Deprecated
+  public StructObjectInspector initialize(ObjectInspector[] argOIs)
+      throws UDFArgumentException {
+    throw new IllegalStateException("Should not be called directly");
+  }
 
   /**
    * Give a set of arguments for the UDTF to process.



Mime
View raw message