diff --git ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFSplit.java ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFSplit.java index 88a03ef..b4f0f2d 100644 --- ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFSplit.java +++ ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFSplit.java @@ -19,11 +19,13 @@ package org.apache.hadoop.hive.ql.udf.generic; import java.util.ArrayList; +import java.util.regex.Pattern; 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.metadata.HiveException; +import org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; @@ -40,6 +42,7 @@ + " [\"one\", \"two\", \"three\"]") public class GenericUDFSplit extends GenericUDF { private transient ObjectInspectorConverters.Converter[] converters; + private transient Pattern constPattern; @Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { @@ -54,6 +57,12 @@ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumen PrimitiveObjectInspectorFactory.writableStringObjectInspector); } + ObjectInspector rightArg = arguments[1]; + if (rightArg instanceof ConstantObjectInspector) { + constPattern = Pattern.compile(((ConstantObjectInspector) rightArg). + getWritableConstantValue().toString()); + } + return ObjectInspectorFactory .getStandardListObjectInspector(PrimitiveObjectInspectorFactory .writableStringObjectInspector); @@ -68,14 +77,18 @@ public Object evaluate(DeferredObject[] arguments) throws HiveException { } Text s = (Text) converters[0].convert(arguments[0].get()); - Text regex = (Text) converters[1].convert(arguments[1].get()); - ArrayList result = new ArrayList(); - for (String str : s.toString().split(regex.toString(), -1)) { - result.add(new Text(str)); + if (constPattern == null) { + Text regex = (Text) converters[1].convert(arguments[1].get()); + for (String str : s.toString().split(regex.toString(), -1)) { + result.add(new Text(str)); + } + } else { + for (String str : constPattern.split(s.toString(), -1)) { + result.add(new Text(str)); + } } - return result; }