use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project presto by prestodb.
the class HiveBucketing method getHiveBucket.
public static Optional<HiveBucket> getHiveBucket(List<Entry<ObjectInspector, Object>> columnBindings, int bucketCount) {
try {
@SuppressWarnings("resource") GenericUDFHash udf = new GenericUDFHash();
ObjectInspector[] objectInspectors = new ObjectInspector[columnBindings.size()];
DeferredObject[] deferredObjects = new DeferredObject[columnBindings.size()];
int i = 0;
for (Entry<ObjectInspector, Object> entry : columnBindings) {
objectInspectors[i] = getJavaObjectInspector(entry.getKey());
deferredObjects[i] = getJavaDeferredObject(entry.getValue(), entry.getKey());
i++;
}
ObjectInspector udfInspector = udf.initialize(objectInspectors);
IntObjectInspector inspector = (IntObjectInspector) udfInspector;
Object result = udf.evaluate(deferredObjects);
HiveKey hiveKey = new HiveKey();
hiveKey.setHashCode(inspector.get(result));
int bucketNumber = new DefaultHivePartitioner<>().getBucket(hiveKey, null, bucketCount);
return Optional.of(new HiveBucket(bucketNumber, bucketCount));
} catch (HiveException e) {
log.debug(e, "Error evaluating bucket number");
return Optional.empty();
}
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project presto by prestodb.
the class HiveScalarFunctionInvoker method evaluate.
@Override
public Object evaluate(Object... inputs) {
try {
DeferredObject[] objects = new DeferredObject[inputs.length];
for (int i = 0; i < inputs.length; i++) {
objects[i] = inputs[i] == null ? new DeferredJavaObject(null) : new DeferredJavaObject(argumentDecoders[i].decode(inputs[i]));
}
Object evaluated = udfSupplier.get().evaluate(objects);
return objectEncoder.encode(evaluated);
} catch (HiveException e) {
throw executionError(e);
}
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class GenericUDFParamUtils method getBinaryValue.
public static BytesWritable getBinaryValue(DeferredObject[] arguments, int i, Converter[] converters) throws HiveException {
Object obj;
if ((obj = arguments[i].get()) == null) {
return null;
}
Object writableValue = converters[i].convert(obj);
return (BytesWritable) writableValue;
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFCeil method testShort.
@Test
public void testShort() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
ShortWritable input = new ShortWritable((short) -74);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(-74L, res.get());
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject in project hive by apache.
the class TestGenericUDFCeil method testByte.
@Test
public void testByte() throws HiveException {
GenericUDFCeil udf = new GenericUDFCeil();
ByteWritable input = new ByteWritable((byte) 4);
ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableByteObjectInspector };
DeferredObject[] args = { new DeferredJavaObject(input) };
PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo());
LongWritable res = (LongWritable) udf.evaluate(args);
Assert.assertEquals(4L, res.get());
}
Aggregations