Author: jvs
Date: Tue Nov 29 21:22:56 2011
New Revision: 1208075
URL: http://svn.apache.org/viewvc?rev=1208075&view=rev
Log:
HIVE-2561 [jira] Add an annotation to UDFs to allow them to specify additional
FILE/JAR resources necessary for execution
Summary:
Add requirements.
Often times UDFs will have dependencies to external JARs/FILEs. It makes sense
for these to be encoded by the UDF (rather than having the caller remember the
set of files that need to be ADDed). Let's add an annotation to UDFs which will
cause these resources to be auto-added.
Test Plan: EMPTY
Reviewers: JIRA, jsichi
Reviewed By: jsichi
CC: jsichi, jonchang, atfiore
Differential Revision: 507
Added:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInFile.java
hive/trunk/ql/src/test/queries/clientpositive/udf_in_file.q
hive/trunk/ql/src/test/results/clientpositive/udf_in_file.q.out
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDF.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBridge.java
hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java
hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=1208075&r1=1208074&r2=1208075&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
Tue Nov 29 21:22:56 2011
@@ -161,6 +161,7 @@ import org.apache.hadoop.hive.ql.udf.gen
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFIf;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFIn;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFIndex;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDFInFile;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFInstr;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFLocate;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFMap;
@@ -426,6 +427,7 @@ public final class FunctionRegistry {
registerGenericUDF("hash", GenericUDFHash.class);
registerGenericUDF("coalesce", GenericUDFCoalesce.class);
registerGenericUDF("index", GenericUDFIndex.class);
+ registerGenericUDF("in_file", GenericUDFInFile.class);
registerGenericUDF("instr", GenericUDFInstr.class);
registerGenericUDF("locate", GenericUDFLocate.class);
registerGenericUDF("elt", GenericUDFElt.class);
@@ -710,7 +712,7 @@ public final class FunctionRegistry {
GenericUDAFEvaluator udafEvaluator = null;
ObjectInspector args[] = new ObjectInspector[argumentOIs.size()];
- // Can't use toArray here because Java is dumb when it comes to
+ // Can't use toArray here because Java is dumb when it comes to
// generics + arrays.
for (int ii = 0; ii < argumentOIs.size(); ++ii) {
args[ii] = argumentOIs.get(ii);
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDF.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDF.java?rev=1208075&r1=1208074&r2=1208075&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDF.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/UDF.java Tue Nov 29
21:22:56 2011
@@ -22,14 +22,14 @@ import org.apache.hadoop.hive.ql.udf.UDF
/**
* A User-defined function (UDF) for the use with Hive.
- *
+ *
* New UDF classes need to inherit from this UDF class.
- *
+ *
* Required for all UDF classes: 1. Implement one or more methods named
* "evaluate" which will be called by Hive. The following are some examples:
* public int evaluate(); public int evaluate(int a); public double
evaluate(int
* a, double b); public String evaluate(String a, int b, String c);
- *
+ *
* "evaluate" should never be a void method. However it can return "null" if
* needed.
*/
@@ -57,7 +57,7 @@ public class UDF {
/**
* Sets the resolver.
- *
+ *
* @param rslv
* The method resolver to use for method resolution.
*/
@@ -71,4 +71,16 @@ public class UDF {
public UDFMethodResolver getResolver() {
return rslv;
}
+
+ /**
+ * These can be overriden to provide the same functionality as the
+ * correspondingly named methods in GenericUDF.
+ */
+ public String[] getRequiredJars() {
+ return null;
+ }
+
+ public String[] getRequiredFiles() {
+ return null;
+ }
}
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java?rev=1208075&r1=1208074&r2=1208075&view=diff
==============================================================================
---
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java
(original)
+++
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeGenericFuncDesc.java
Tue Nov 29 21:22:56 2011
@@ -212,6 +212,25 @@ public class ExprNodeGenericFuncDesc ext
}
ObjectInspector oi = genericUDF.initializeAndFoldConstants(childrenOIs);
+
+ String[] requiredJars = genericUDF.getRequiredJars();
+ String[] requiredFiles = genericUDF.getRequiredFiles();
+ SessionState ss = SessionState.get();
+
+ if (requiredJars != null) {
+ SessionState.ResourceType t = SessionState.find_resource_type("JAR");
+ for (String jarPath : requiredJars) {
+ ss.add_resource(t, jarPath);
+ }
+ }
+
+ if (requiredFiles != null) {
+ SessionState.ResourceType t = SessionState.find_resource_type("FILE");
+ for (String filePath : requiredFiles) {
+ ss.add_resource(t, filePath);
+ }
+ }
+
return new ExprNodeGenericFuncDesc(oi, genericUDF, children);
}
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java?rev=1208075&r1=1208074&r2=1208075&view=diff
==============================================================================
---
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java
(original)
+++
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java
Tue Nov 29 21:22:56 2011
@@ -75,7 +75,7 @@ public abstract class GenericUDF {
/**
* Initialize this GenericUDF. This will be called once and only once per
* GenericUDF instance.
- *
+ *
* @param arguments
* The ObjectInspector for the arguments
* @throws UDFArgumentException
@@ -97,6 +97,13 @@ public abstract class GenericUDF {
ObjectInspector oi = initialize(arguments);
+ // If the UDF depends on any external resources, we can't fold because the
+ // resources may not be available at compile time.
+ if (getRequiredFiles() != null ||
+ getRequiredJars() != null) {
+ return oi;
+ }
+
boolean allConstant = true;
for (int ii = 0; ii < arguments.length; ++ii) {
if (!ObjectInspectorUtils.isConstantObjectInspector(arguments[ii])) {
@@ -127,6 +134,19 @@ public abstract class GenericUDF {
}
/**
+ * The following two functions can be overridden to automatically include
+ * additional resources required by this UDF. The return types should be
+ * arrays of paths.
+ */
+ public String[] getRequiredJars() {
+ return null;
+ }
+
+ public String[] getRequiredFiles() {
+ return null;
+ }
+
+ /**
* Evaluate the GenericUDF with the arguments.
*
* @param arguments
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBridge.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBridge.java?rev=1208075&r1=1208074&r2=1208075&view=diff
==============================================================================
---
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBridge.java
(original)
+++
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBridge.java
Tue Nov 29 21:22:56 2011
@@ -37,10 +37,10 @@ import org.apache.hadoop.util.Reflection
/**
* GenericUDFBridge encapsulates UDF to provide the same interface as
* GenericUDF.
- *
+ *
* Note that GenericUDFBridge implements Serializable because the name of the
* UDF class needs to be serialized with the plan.
- *
+ *
*/
public class GenericUDFBridge extends GenericUDF implements Serializable {
/**
@@ -66,7 +66,7 @@ public class GenericUDFBridge extends Ge
/**
* Greate a new GenericUDFBridge object.
- *
+ *
* @param udfName
* The name of the corresponding udf.
* @param isOperator
@@ -210,4 +210,14 @@ public class GenericUDFBridge extends Ge
}
}
+ @Override
+ public String[] getRequiredJars() {
+ return udf.getRequiredJars();
+ }
+
+ @Override
+ public String[] getRequiredFiles() {
+ return udf.getRequiredFiles();
+ }
+
}
Added:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInFile.java
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInFile.java?rev=1208075&view=auto
==============================================================================
---
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInFile.java
(added)
+++
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFInFile.java
Tue Nov 29 21:22:56 2011
@@ -0,0 +1,142 @@
+/**
+ * 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.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import java.util.HashSet;
+
+import org.apache.hadoop.hive.ql.exec.Description;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
+import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
+import
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
+import
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils;
+
+/**
+ * IN_FILE(str, filename) returns true if 'str' appears in the file specified
+ * by 'filename'. A string is considered to be in the file if it that string
+ * appears as a line in the file.
+ *
+ * If either argument is NULL then NULL is returned.
+ */
+@Description(name = "in_file",
+ value = "_FUNC_(str, filename) - Returns true if str appears in the file")
+public class GenericUDFInFile extends GenericUDF {
+
+ HashSet<String> set;
+ ObjectInspector strObjectInspector;
+ ObjectInspector fileObjectInspector;
+
+ @Override
+ public ObjectInspector initialize(ObjectInspector[] arguments)
+ throws UDFArgumentException {
+ if (arguments.length != 2) {
+ throw new UDFArgumentLengthException(
+ "IN_FILE() accepts exactly 2 arguments.");
+ }
+
+ for (int i = 0; i < arguments.length; i++) {
+ if (!String.class.equals(
+ PrimitiveObjectInspectorUtils.
+ getJavaPrimitiveClassFromObjectInspector(arguments[i]))) {
+ throw new UDFArgumentTypeException(i, "The "
+ + GenericUDFUtils.getOrdinal(i + 1)
+ + " argument of function IN_FILE must be a string but "
+ + arguments[i].toString() + " was given.");
+ }
+ }
+
+ strObjectInspector = arguments[0];
+ fileObjectInspector = arguments[1];
+
+ if (!ObjectInspectorUtils.isConstantObjectInspector(fileObjectInspector)) {
+ throw new UDFArgumentTypeException(1,
+ "The second argument of IN_FILE() must be a constant string but " +
+ fileObjectInspector.toString() + " was given.");
+ }
+
+ return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector;
+ }
+
+ @Override
+ public String[] getRequiredFiles() {
+ return new String[] {
+ ObjectInspectorUtils.getWritableConstantValue(fileObjectInspector)
+ .toString()
+ };
+ }
+
+ @Override
+ public Object evaluate(DeferredObject[] arguments) throws HiveException {
+ if (arguments[0].get() == null || arguments[1].get() == null) {
+ return null;
+ }
+
+ String str = (String)ObjectInspectorUtils.copyToStandardJavaObject(
+ arguments[0].get(), strObjectInspector);
+
+ if (set == null) {
+ String fileName = (String)ObjectInspectorUtils.copyToStandardJavaObject(
+ arguments[1].get(), fileObjectInspector);
+ try {
+ load(new FileInputStream((new File(fileName)).getName()));
+ } catch (FileNotFoundException e) {
+ throw new HiveException(e);
+ }
+ }
+
+ return Boolean.valueOf(set.contains(str));
+ }
+
+ /**
+ * Load the file from an InputStream.
+ * @param is The InputStream contains the file data.
+ * @throws HiveException
+ */
+ public void load(InputStream is) throws HiveException {
+ BufferedReader reader =
+ new BufferedReader(new InputStreamReader(is));
+
+ set = new HashSet<String>();
+
+ try {
+ String line;
+ while((line = reader.readLine()) != null) {
+ set.add(line);
+ }
+ } catch (Exception e) {
+ throw new HiveException(e);
+ }
+ }
+
+ @Override
+ public String getDisplayString(String[] children) {
+ assert (children.length == 2);
+ return "in_file(" + children[0] + ", " + children[1] + ")";
+ }
+}
Added: hive/trunk/ql/src/test/queries/clientpositive/udf_in_file.q
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_in_file.q?rev=1208075&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_in_file.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_in_file.q Tue Nov 29
21:22:56 2011
@@ -0,0 +1,12 @@
+DESCRIBE FUNCTION in_file;
+
+EXPLAIN
+SELECT in_file("303", "../data/files/test2.dat"),
+ in_file("304", "../data/files/test2.dat"),
+ in_file(CAST(NULL AS STRING), "../data/files/test2.dat")
+FROM src LIMIT 1;
+
+SELECT in_file("303", "../data/files/test2.dat"),
+ in_file("304", "../data/files/test2.dat"),
+ in_file(CAST(NULL AS STRING), "../data/files/test2.dat")
+FROM src LIMIT 1;
Modified: hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out?rev=1208075&r1=1208074&r2=1208075&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
(original)
+++ hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out Tue Nov
29 21:22:56 2011
@@ -76,6 +76,7 @@ histogram_numeric
hour
if
in
+in_file
index
instr
int
@@ -203,6 +204,7 @@ double
e
explode
from_unixtime
+in_file
json_tuple
lcase
like
Added: hive/trunk/ql/src/test/results/clientpositive/udf_in_file.q.out
URL:
http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_in_file.q.out?rev=1208075&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_in_file.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_in_file.q.out Tue Nov 29
21:22:56 2011
@@ -0,0 +1,68 @@
+PREHOOK: query: DESCRIBE FUNCTION in_file
+PREHOOK: type: DESCFUNCTION
+POSTHOOK: query: DESCRIBE FUNCTION in_file
+POSTHOOK: type: DESCFUNCTION
+in_file(str, filename) - Returns true if str appears in the file
+PREHOOK: query: EXPLAIN
+SELECT in_file("303", "../data/files/test2.dat"),
+ in_file("304", "../data/files/test2.dat"),
+ in_file(CAST(NULL AS STRING), "../data/files/test2.dat")
+FROM src LIMIT 1
+PREHOOK: type: QUERY
+POSTHOOK: query: EXPLAIN
+SELECT in_file("303", "../data/files/test2.dat"),
+ in_file("304", "../data/files/test2.dat"),
+ in_file(CAST(NULL AS STRING), "../data/files/test2.dat")
+FROM src LIMIT 1
+POSTHOOK: type: QUERY
+ABSTRACT SYNTAX TREE:
+ (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME src))) (TOK_INSERT
(TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION
in_file "303" "../data/files/test2.dat")) (TOK_SELEXPR (TOK_FUNCTION in_file
"304" "../data/files/test2.dat")) (TOK_SELEXPR (TOK_FUNCTION in_file
(TOK_FUNCTION TOK_STRING TOK_NULL) "../data/files/test2.dat"))) (TOK_LIMIT 1)))
+
+STAGE DEPENDENCIES:
+ Stage-1 is a root stage
+ Stage-0 is a root stage
+
+STAGE PLANS:
+ Stage: Stage-1
+ Map Reduce
+ Alias -> Map Operator Tree:
+ src
+ TableScan
+ alias: src
+ Select Operator
+ expressions:
+ expr: in_file('303', '../data/files/test2.dat')
+ type: boolean
+ expr: in_file('304', '../data/files/test2.dat')
+ type: boolean
+ expr: in_file(UDFToString(null), '../data/files/test2.dat')
+ type: boolean
+ outputColumnNames: _col0, _col1, _col2
+ Limit
+ File Output Operator
+ compressed: false
+ GlobalTableId: 0
+ table:
+ input format: org.apache.hadoop.mapred.TextInputFormat
+ output format:
org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
+
+ Stage: Stage-0
+ Fetch Operator
+ limit: 1
+
+
+PREHOOK: query: SELECT in_file("303", "../data/files/test2.dat"),
+ in_file("304", "../data/files/test2.dat"),
+ in_file(CAST(NULL AS STRING), "../data/files/test2.dat")
+FROM src LIMIT 1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output:
file:/var/folders/71/h_j6fpg10r33hvx1lcxlgttcw61_4s/T/jonchang/hive_2011-11-20_01-14-47_787_473222432824773238/-mr-10000
+POSTHOOK: query: SELECT in_file("303", "../data/files/test2.dat"),
+ in_file("304", "../data/files/test2.dat"),
+ in_file(CAST(NULL AS STRING), "../data/files/test2.dat")
+FROM src LIMIT 1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output:
file:/var/folders/71/h_j6fpg10r33hvx1lcxlgttcw61_4s/T/jonchang/hive_2011-11-20_01-14-47_787_473222432824773238/-mr-10000
+true false NULL
Modified:
hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java
URL:
http://svn.apache.org/viewvc/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java?rev=1208075&r1=1208074&r2=1208075&view=diff
==============================================================================
---
hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java
(original)
+++
hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java
Tue Nov 29 21:22:56 2011
@@ -208,6 +208,9 @@ public final class ObjectInspectorUtils
return copyToStandardObject(o, oi, ObjectInspectorCopyOption.DEFAULT);
}
+ public static Object copyToStandardJavaObject(Object o, ObjectInspector oi) {
+ return copyToStandardObject(o, oi, ObjectInspectorCopyOption.JAVA);
+ }
public static Object copyToStandardObject(Object o, ObjectInspector oi,
ObjectInspectorCopyOption objectInspectorOption) {
@@ -490,7 +493,7 @@ public final class ObjectInspectorUtils
ObjectInspector valueOI = mapOI.getMapValueObjectInspector();
Map<?, ?> map = mapOI.getMap(o);
for (Map.Entry entry : map.entrySet()) {
- r += hashCode(entry.getKey(), keyOI) ^
+ r += hashCode(entry.getKey(), keyOI) ^
hashCode(entry.getValue(), valueOI);
}
return r;
@@ -564,7 +567,7 @@ public final class ObjectInspectorUtils
ObjectInspector oi2) {
return compare(o1, oi1, o2, oi2, new FullMapEqualComparer());
}
-
+
/**
* Compare two objects with their respective ObjectInspectors.
*/
@@ -667,7 +670,7 @@ public final class ObjectInspectorUtils
for (int i = 0; i < minimum; i++) {
int r = compare(soi1.getStructFieldData(o1, fields1.get(i)), fields1
.get(i).getFieldObjectInspector(), soi2.getStructFieldData(o2,
- fields2.get(i)), fields2.get(i).getFieldObjectInspector(),
+ fields2.get(i)), fields2.get(i).getFieldObjectInspector(),
mapEqualComparer);
if (r != 0) {
return r;
@@ -921,6 +924,10 @@ public final class ObjectInspectorUtils
}
}
+ public static Object getWritableConstantValue(ObjectInspector oi) {
+ return ((ConstantObjectInspector)oi).getWritableConstantValue();
+ }
+
public static boolean supportsConstantObjectInspector(ObjectInspector oi) {
switch (oi.getCategory()) {
case PRIMITIVE:
Modified:
hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java
URL:
http://svn.apache.org/viewvc/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java?rev=1208075&r1=1208074&r2=1208075&view=diff
==============================================================================
---
hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java
(original)
+++
hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java
Tue Nov 29 21:22:56 2011
@@ -33,6 +33,8 @@ import org.apache.hadoop.hive.serde2.io.
import org.apache.hadoop.hive.serde2.lazy.ByteArrayRef;
import org.apache.hadoop.hive.serde2.lazy.LazyInteger;
import org.apache.hadoop.hive.serde2.lazy.LazyLong;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
import
org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory;
import org.apache.hadoop.io.BooleanWritable;
@@ -796,6 +798,16 @@ public final class PrimitiveObjectInspec
return result;
}
+ public static Class<?>
getJavaPrimitiveClassFromObjectInspector(ObjectInspector oi) {
+ if (oi.getCategory() != Category.PRIMITIVE) {
+ return null;
+ }
+ PrimitiveObjectInspector poi = (PrimitiveObjectInspector)oi;
+ PrimitiveTypeEntry t =
+ getTypeEntryFromPrimitiveCategory(poi.getPrimitiveCategory());
+ return t == null ? null : t.primitiveJavaClass;
+ }
+
private PrimitiveObjectInspectorUtils() {
// prevent instantiation
}