Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#writableBinaryObjectInspector()
The following examples show how to use
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#writableBinaryObjectInspector() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EthereumGetSendAddressUDF.java From hadoopcryptoledger with Apache License 2.0 | 6 votes |
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments==null) { throw new UDFArgumentLengthException("ethereumGetSendAddress only takes two arguments: Struct<EthereumTransction>, INT chainId "); } if (arguments.length != 2) { throw new UDFArgumentLengthException("ethereumGetSendAddress only takes two arguments: Struct<EthereumTransction>, INT chainId "); } if (!(arguments[0] instanceof StructObjectInspector)) { throw new UDFArgumentException("first argument must be a Struct containing a EthereumTransction"); } if (!(arguments[1] instanceof IntObjectInspector)) { throw new UDFArgumentException("second argument must be an int with the chainId"); } this.ethereumUDFUtil=new EthereumUDFUtil((StructObjectInspector) arguments[0]); return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; }
Example 2
Source File: BitcoinTransactionHashUDF.java From hadoopcryptoledger with Apache License 2.0 | 6 votes |
/** * * Initialize HiveUDF and create object inspectors. It requires that the argument length is = 1 and that the ObjectInspector of arguments[0] is of type StructObjectInspector * * @param arguments array of length 1 containing one StructObjectInspector * * @return ObjectInspector that is able to parse the result of the evaluate method of the UDF (BinaryWritable) * * @throws org.apache.hadoop.hive.ql.exec.UDFArgumentException in case the first argument is not of StructObjectInspector * @throws org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in case the number of arguments is != 1 * */ @Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments==null) { throw new UDFArgumentLengthException("bitcoinTransactionHash only takes one argument: Struct<BitcoinTransaction> "); } if (arguments.length != 1) { throw new UDFArgumentLengthException("bitcoinTransactionHash only takes one argument: Struct<BitcoinTransaction> "); } if (!(arguments[0] instanceof StructObjectInspector)) { throw new UDFArgumentException("first argument must be a Struct containing a BitcoinTransaction"); } this.soi = (StructObjectInspector)arguments[0]; // these are only used for bitcointransaction structs exported to other formats, such as ORC this.wboi = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; this.wioi = PrimitiveObjectInspectorFactory.writableIntObjectInspector; this.wloi = PrimitiveObjectInspectorFactory.writableLongObjectInspector; this.hdoi = PrimitiveObjectInspectorFactory.javaHiveDecimalObjectInspector; // the UDF returns the hash value of a BitcoinTransaction as byte array return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; }
Example 3
Source File: BitcoinTransactionHashSegwitUDF.java From hadoopcryptoledger with Apache License 2.0 | 6 votes |
/** * * Initialize HiveUDF and create object inspectors. It requires that the argument length is = 1 and that the ObjectInspector of arguments[0] is of type StructObjectInspector * * @param arguments array of length 1 containing one StructObjectInspector * * @return ObjectInspector that is able to parse the result of the evaluate method of the UDF (BinaryWritable) * * @throws org.apache.hadoop.hive.ql.exec.UDFArgumentException in case the first argument is not of StructObjectInspector * @throws org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in case the number of arguments is != 1 * */ @Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments==null) { throw new UDFArgumentLengthException("bitcoinTransactionHash only takes one argument: Struct<BitcoinTransaction> "); } if (arguments.length != 1) { throw new UDFArgumentLengthException("bitcoinTransactionHash only takes one argument: Struct<BitcoinTransaction> "); } if (!(arguments[0] instanceof StructObjectInspector)) { throw new UDFArgumentException("first argument must be a Struct containing a BitcoinTransaction"); } this.soi = (StructObjectInspector)arguments[0]; // these are only used for bitcointransaction structs exported to other formats, such as ORC this.wboi = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; this.wioi = PrimitiveObjectInspectorFactory.writableIntObjectInspector; this.wloi = PrimitiveObjectInspectorFactory.writableLongObjectInspector; this.wbyoi = PrimitiveObjectInspectorFactory.writableByteObjectInspector; this.hdoi = PrimitiveObjectInspectorFactory.javaHiveDecimalObjectInspector; // the UDF returns the hash value of a BitcoinTransaction as byte array return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; }
Example 4
Source File: NamecoinUDFTest.java From hadoopcryptoledger with Apache License 2.0 | 6 votes |
@Test public void extractNamecoinFieldFirstUpdate() throws HiveException { String firstUpdateScript ="520A642F666C6173687570641460C7B068EDEA60281DAF424C38D8DAB87C96CF993D7B226970223A223134352E3234392E3130362E323238222C226D6170223A7B222A223A7B226970223A223134352E3234392E3130362E323238227D7D7D6D6D76A91451B4FC93AAB8CBDBD0AC9BC8EAF824643FC1E29B88AC"; byte[] firstUpdateScriptBytes = BitcoinUtil.convertHexStringToByteArray(firstUpdateScript); NamecoinExtractFieldUDF nefu = new NamecoinExtractFieldUDF(); ObjectInspector[] arguments = new ObjectInspector[1]; arguments[0] = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;; nefu.initialize(arguments); GenericUDF.DeferredObject[] doa = new GenericUDF.DeferredObject[1]; doa[0]=new GenericUDF.DeferredJavaObject(new BytesWritable(firstUpdateScriptBytes)); List<Text> resultList = (List<Text>) nefu.evaluate(doa); Text[] result=resultList.toArray(new Text[resultList.size()]); assertNotNull( result,"Valid result obtained"); // test for domain name assertEquals("d/flashupd",result[0].toString(),"Domain name of first update detected correctly"); // test for domain value assertEquals("{\"ip\":\"145.249.106.228\",\"map\":{\"*\":{\"ip\":\"145.249.106.228\"}}}",result[1].toString(),"Domain value of first update detected correctly"); }
Example 5
Source File: NamecoinUDFTest.java From hadoopcryptoledger with Apache License 2.0 | 6 votes |
@Test public void extractNamecoinFieldUpdate() throws HiveException { String updateScript = "5309642F70616E656C6B612D7B226970223A22382E382E382E38222C226D6170223A7B222A223A7B226970223A22382E382E382E38227D7D7D6D7576A9148D804B079AC79AD0CA108A4E5B679DB591FF069B88AC"; byte[] updateScriptBytes = BitcoinUtil.convertHexStringToByteArray(updateScript); NamecoinExtractFieldUDF nefu = new NamecoinExtractFieldUDF(); ObjectInspector[] arguments = new ObjectInspector[1]; arguments[0] = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;; nefu.initialize(arguments); GenericUDF.DeferredObject[] doa = new GenericUDF.DeferredObject[1]; doa[0]=new GenericUDF.DeferredJavaObject(new BytesWritable(updateScriptBytes)); List<Text> resultList = (List<Text>) nefu.evaluate(doa); Text[] result=resultList.toArray(new Text[resultList.size()]); assertNotNull( result,"Valid result obtained"); // test for domain name assertEquals("d/panelka",result[0].toString(),"Domain name of first update detected correctly"); // test for domain value assertEquals("{\"ip\":\"8.8.8.8\",\"map\":{\"*\":{\"ip\":\"8.8.8.8\"}}}",result[1].toString(),"Domain value of first update detected correctly"); }
Example 6
Source File: DeflateUDF.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Override public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { if (argOIs.length != 1 && argOIs.length != 2) { throw new UDFArgumentException("_FUNC_ takes 1 or 2 arguments"); } this.stringOI = HiveUtils.asStringOI(argOIs[0]); int level = Deflater.DEFAULT_COMPRESSION; if (argOIs.length == 2) { level = HiveUtils.getConstInt(argOIs[1]); if ((level < 0 || level > 9) && level != Deflater.DEFAULT_COMPRESSION) { throw new UDFArgumentException("Invalid compression level: " + level); } } this.compressionLevel = level; return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; }
Example 7
Source File: EthereumGetTransactionHashUDF.java From hadoopcryptoledger with Apache License 2.0 | 5 votes |
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments==null) { throw new UDFArgumentLengthException("ethereumGetTransactionHash only takes one argument: Struct<EthereumTransction> "); } if (arguments.length != 1) { throw new UDFArgumentLengthException("ethereumGetTransactionHash only takes one argument: Struct<EthereumTransction> "); } if (!(arguments[0] instanceof StructObjectInspector)) { throw new UDFArgumentException("first argument must be a Struct containing a EthereumTransction"); } this.ethereumUDFUtil=new EthereumUDFUtil((StructObjectInspector) arguments[0]); return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; }
Example 8
Source File: Unbase91UDF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { if (argOIs.length != 1) { throw new UDFArgumentException("_FUNC_ takes exactly 1 argument"); } this.stringOI = HiveUtils.asStringOI(argOIs[0]); return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; }
Example 9
Source File: OrcLazyObjectInspectorUtils.java From hive-dwrf with Apache License 2.0 | 5 votes |
public static ObjectInspector createWritableObjectInspector(int columnId, List<OrcProto.Type> types){ OrcProto.Type type = types.get(columnId); switch (type.getKind()) { case FLOAT: return PrimitiveObjectInspectorFactory.writableFloatObjectInspector; case DOUBLE: return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; case BOOLEAN: return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; case BYTE: return PrimitiveObjectInspectorFactory.writableByteObjectInspector; case SHORT: return PrimitiveObjectInspectorFactory.writableShortObjectInspector; case INT: return PrimitiveObjectInspectorFactory.writableIntObjectInspector; case LONG: return PrimitiveObjectInspectorFactory.writableLongObjectInspector; case BINARY: return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; case STRING: return PrimitiveObjectInspectorFactory.writableStringObjectInspector; case TIMESTAMP: return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector; case STRUCT: return new OrcStruct.OrcStructInspector(columnId, types); case UNION: return new OrcUnion.OrcUnionObjectInspector(columnId, types); case MAP: return new OrcStruct.OrcMapObjectInspector(columnId, types); case LIST: return new OrcStruct.OrcListObjectInspector(columnId, types); default: throw new UnsupportedOperationException("Unknown type " + type.getKind()); } }
Example 10
Source File: MDSObjectInspectorFactory.java From multiple-dimension-spread with Apache License 2.0 | 4 votes |
public static ObjectInspector craeteObjectInspectorFromTypeInfo( final TypeInfo typeInfo ){ switch ( typeInfo.getCategory() ){ case STRUCT: return new MDSStructObjectInspector( (StructTypeInfo)typeInfo ); case MAP: return new MDSMapObjectInspector( (MapTypeInfo)typeInfo ); case LIST: return new MDSListObjectInspector( (ListTypeInfo)typeInfo ); case UNION: UnionTypeInfo unionTypeInfo = (UnionTypeInfo)typeInfo; List<ObjectInspector> unionList = new ArrayList<ObjectInspector>(); for( TypeInfo childTypeInfo : unionTypeInfo.getAllUnionObjectTypeInfos() ){ unionList.add( craeteObjectInspectorFromTypeInfo( childTypeInfo ) ); } return ObjectInspectorFactory.getStandardUnionObjectInspector( unionList ); case PRIMITIVE: PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo)typeInfo; switch( primitiveTypeInfo.getPrimitiveCategory() ){ case STRING: return PrimitiveObjectInspectorFactory.writableStringObjectInspector; case BINARY: return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; case BOOLEAN: return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; case BYTE: return PrimitiveObjectInspectorFactory.writableByteObjectInspector; case DOUBLE: return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; case FLOAT: return PrimitiveObjectInspectorFactory.writableFloatObjectInspector; case INT: return PrimitiveObjectInspectorFactory.writableIntObjectInspector; case LONG: return PrimitiveObjectInspectorFactory.writableLongObjectInspector; case SHORT: return PrimitiveObjectInspectorFactory.writableShortObjectInspector; case DATE: case DECIMAL: case TIMESTAMP: case VOID: default: throw new UnsupportedOperationException( "Unknown primitive category " + primitiveTypeInfo.getPrimitiveCategory() ); } default: throw new UnsupportedOperationException( "Unknown category " + typeInfo.getCategory() ); } }
Example 11
Source File: OrcLazyObjectInspectorUtils.java From hive-dwrf with Apache License 2.0 | 4 votes |
public static ObjectInspector createWritableObjectInspector(TypeInfo info) { switch (info.getCategory()) { case PRIMITIVE: switch (((PrimitiveTypeInfo) info).getPrimitiveCategory()) { case FLOAT: return PrimitiveObjectInspectorFactory.writableFloatObjectInspector; case DOUBLE: return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; case BOOLEAN: return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; case BYTE: return PrimitiveObjectInspectorFactory.writableByteObjectInspector; case SHORT: return PrimitiveObjectInspectorFactory.writableShortObjectInspector; case INT: return PrimitiveObjectInspectorFactory.writableIntObjectInspector; case LONG: return PrimitiveObjectInspectorFactory.writableLongObjectInspector; case BINARY: return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; case STRING: return PrimitiveObjectInspectorFactory.writableStringObjectInspector; case TIMESTAMP: return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector; default: throw new IllegalArgumentException("Unknown primitive type " + ((PrimitiveTypeInfo) info).getPrimitiveCategory()); } case STRUCT: return new OrcStruct.OrcStructInspector((StructTypeInfo) info); case UNION: return new OrcUnion.OrcUnionObjectInspector((UnionTypeInfo) info); case MAP: return new OrcStruct.OrcMapObjectInspector((MapTypeInfo) info); case LIST: return new OrcStruct.OrcListObjectInspector((ListTypeInfo) info); default: throw new IllegalArgumentException("Unknown type " + info.getCategory()); } }