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);
}
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));
}
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")));
}
Aggregations