Search in sources :

Example 1 with PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector

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

the class GenericUDTFGetSplits method initialize.

@Override
public StructObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    LOG.debug("initializing GenericUDFGetSplits");
    validateInput(arguments);
    List<String> names = Arrays.asList("split");
    List<ObjectInspector> fieldOIs = Arrays.<ObjectInspector>asList(PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector);
    StructObjectInspector outputOI = ObjectInspectorFactory.getStandardStructObjectInspector(names, fieldOIs);
    LOG.debug("done initializing GenericUDFGetSplits");
    return outputOI;
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) IntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Example 2 with PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector

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

the class GenericUDTFGetSQLSchema method initialize.

@Override
public StructObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    LOG.debug("initializing GenericUDTFGetSQLSchema");
    if (SessionState.get() == null || SessionState.get().getConf() == null) {
        throw new IllegalStateException("Cannot run GET_SQL_SCHEMA outside HS2");
    }
    LOG.debug("Initialized conf, jc and metastore connection");
    if (arguments.length != 1) {
        throw new UDFArgumentLengthException("The function GET_SQL_SCHEMA accepts 1 argument.");
    } else if (!(arguments[0] instanceof StringObjectInspector)) {
        LOG.error("Got " + arguments[0].getTypeName() + " instead of string.");
        throw new UDFArgumentTypeException(0, "\"" + "string\" is expected at function GET_SQL_SCHEMA, " + "but \"" + arguments[0].getTypeName() + "\" is found");
    }
    stringOI = (StringObjectInspector) arguments[0];
    List<String> names = Arrays.asList("col_name", "col_type");
    List<ObjectInspector> fieldOIs = Arrays.asList(PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector, PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector);
    StructObjectInspector outputOI = ObjectInspectorFactory.getStandardStructObjectInspector(names, fieldOIs);
    LOG.debug("done initializing GenericUDTFGetSQLSchema");
    return outputOI;
}
Also used : StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) UDFArgumentLengthException(org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException) UDFArgumentTypeException(org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Example 3 with PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector

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

the class GenericUDTFGetSplits2 method initialize.

@Override
public StructObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    LOG.debug("initializing GenericUDFGetSplits2");
    validateInput(arguments);
    List<String> names = Arrays.asList("type", "split");
    List<ObjectInspector> fieldOIs = Arrays.asList(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector);
    StructObjectInspector outputOI = ObjectInspectorFactory.getStandardStructObjectInspector(names, fieldOIs);
    LOG.debug("done initializing GenericUDFGetSplits2");
    return outputOI;
}
Also used : StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)

Example 4 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 5 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)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)5 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)3 StringObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector)2 Test (org.junit.Test)2 UDFArgumentLengthException (org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException)1 UDFArgumentTypeException (org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException)1 AllTypes (org.apache.hadoop.hive.ql.io.protobuf.SampleProtos.AllTypes)1 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)1 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)1 IntObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector)1 JavaBinaryObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaBinaryObjectInspector)1 BytesWritable (org.apache.hadoop.io.BytesWritable)1