Search in sources :

Example 6 with PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector in project hive by apache.

the class TestGenericUDFDecode method verifyDecode.

public void verifyDecode(String string, String charsetName) throws UnsupportedEncodingException, HiveException {
    GenericUDFDecode udf = new GenericUDFDecode();
    byte[] bytes = string.getBytes(charsetName);
    ObjectInspector valueOI = PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector;
    ObjectInspector charsetOI = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    ObjectInspector[] initArguments = { valueOI, charsetOI };
    udf.initialize(initArguments);
    DeferredObject valueObj = new DeferredJavaObject(bytes);
    DeferredObject charsetObj = new DeferredJavaObject(charsetName);
    DeferredObject[] arguments = { valueObj, charsetObj };
    String output = (String) udf.evaluate(arguments);
    assertEquals("Decoding failed for CharSet: " + charsetName, string, output);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)

Example 7 with PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector in project hive by apache.

the class TestLazyBinarySerDe method testJavaBinaryObjectInspector.

/**
 * Test to see if byte[] with correct contents is generated by
 * JavaBinaryObjectInspector from input BytesWritable
 * @throws Throwable
 */
@Test
public void testJavaBinaryObjectInspector() throws Throwable {
    BytesWritable bW = getInputBytesWritable();
    // create JavaBinaryObjectInspector
    JavaBinaryObjectInspector binInspector = PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector;
    // convert BytesWritable to byte][
    byte[] outBARef = binInspector.set(null, bW);
    assertTrue("compare input and output BAs", Arrays.equals(inpBArray, outBARef));
}
Also used : JavaBinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaBinaryObjectInspector) BytesWritable(org.apache.hadoop.io.BytesWritable) Test(org.junit.Test)

Example 8 with PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector in project blockchain-spark by datawaves-xyz.

the class DecodeContractEventHiveUDFTest method testDecodeContractEvent.

@Test
public void testDecodeContractEvent() throws HiveException {
    ContractEvent e = new ContractEvent("Transfer");
    e.inputs = ImmutableList.of(new EventField("from", "address", true), new EventField("to", "address", true), new EventField("value", "uint256"));
    DecodeContractEventHiveImpl impl = new DecodeContractEventHiveImpl();
    // Mock input object inspector
    BinaryObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector;
    ListObjectInspector valueOI2 = ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
    ObjectInspector valueOI3 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    ObjectInspector valueOI4 = PrimitiveObjectInspectorFactory.javaStringObjectInspector;
    ObjectInspector[] arguments = { valueOI1, valueOI2, valueOI3, valueOI4 };
    StandardStructObjectInspector resultOI = (StandardStructObjectInspector) impl.initialize(arguments);
    // Mock input data
    DeferredObject valueDf1 = new DeferredJavaObject(Converter.decodeHexStartsWith0x("0x000000000000000000000000000000000000000000003b23f6365b3fabec0000"));
    DeferredObject valueDf2 = new DeferredJavaObject(ImmutableList.of("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x000000000000000000000000b3f923eabaf178fc1bd8e13902fc5c61d3ddef5b", "0x00000000000000000000000028c6c06298d514db089934071355e5743bf21d60"));
    DeferredObject valueDf3 = new DeferredJavaObject(gson.toJson(e));
    DeferredObject valueDf4 = new DeferredJavaObject("Transfer");
    DeferredObject[] args = { valueDf1, valueDf2, valueDf3, valueDf4 };
    List<Object> result = (List<Object>) impl.evaluate(args);
    // Parse output data by output inspector and check it
    StandardStructObjectInspector inputOI = (StandardStructObjectInspector) resultOI.getStructFieldRef("input").getFieldObjectInspector();
    List<Object> inputData = (List<Object>) resultOI.getStructFieldData(result, resultOI.getStructFieldRef("input"));
    List<Object> resultData = inputOI.getStructFieldsDataAsList(inputData);
    assertEquals("0xb3f923eabaf178fc1bd8e13902fc5c61d3ddef5b", resultData.get(0).toString());
    assertEquals("0x28c6c06298d514db089934071355e5743bf21d60", resultData.get(1).toString());
    assertEquals(0, ((HiveDecimalWritable) resultData.get(2)).getHiveDecimal().bigDecimalValue().compareTo(new BigDecimal("279283000000000000000000")));
}
Also used : ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) BinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.BinaryObjectInspector) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) BinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.BinaryObjectInspector) BigDecimal(java.math.BigDecimal) ContractEvent(io.iftech.sparkudf.Mocks.ContractEvent) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) EventField(io.iftech.sparkudf.Mocks.EventField) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)7 Test (org.junit.Test)4 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)3 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)3 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)3 ImmutableList (com.google.common.collect.ImmutableList)2 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 StandardStructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector)2 BinaryObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BinaryObjectInspector)2 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)2 Address (com.esaulpaugh.headlong.abi.Address)1 Function (com.esaulpaugh.headlong.abi.Function)1 ContractEvent (io.iftech.sparkudf.Mocks.ContractEvent)1 ContractFunction (io.iftech.sparkudf.Mocks.ContractFunction)1 EventField (io.iftech.sparkudf.Mocks.EventField)1 FunctionField (io.iftech.sparkudf.Mocks.FunctionField)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)1