Search in sources :

Example 16 with ByteArrayRef

use of org.apache.hadoop.hive.serde2.lazy.ByteArrayRef in project presto by prestodb.

the class ColumnarBinaryHiveRecordCursor method parseObjectColumn.

private void parseObjectColumn(int column, byte[] bytes, int start, int length) {
    checkState(VALID_HIVE_STRUCTURAL_CATEGORIES.contains(hiveTypes[column].getCategory()), "%s is not a valid STRUCTURAL type", hiveTypes[column]);
    if (length == 0) {
        nulls[column] = true;
    } else {
        nulls[column] = false;
        LazyBinaryObject<? extends ObjectInspector> lazyObject = LazyBinaryFactory.createLazyBinaryObject(fieldInspectors[column]);
        ByteArrayRef byteArrayRef = new ByteArrayRef();
        byteArrayRef.setData(bytes);
        lazyObject.init(byteArrayRef, start, length);
        objects[column] = getBlockObject(types[column], lazyObject.getObject(), fieldInspectors[column]);
    }
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)

Example 17 with ByteArrayRef

use of org.apache.hadoop.hive.serde2.lazy.ByteArrayRef in project presto by prestodb.

the class ColumnarTextHiveRecordCursor method parseObjectColumn.

private void parseObjectColumn(int column, byte[] bytes, int start, int length) {
    boolean wasNull;
    if (length == "\\N".length() && bytes[start] == '\\' && bytes[start + 1] == 'N') {
        wasNull = true;
    } else {
        LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(fieldInspectors[column]);
        ByteArrayRef byteArrayRef = new ByteArrayRef();
        byteArrayRef.setData(bytes);
        lazyObject.init(byteArrayRef, start, length);
        objects[column] = getBlockObject(types[column], lazyObject.getObject(), fieldInspectors[column]);
        wasNull = false;
    }
    nulls[column] = wasNull;
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)

Example 18 with ByteArrayRef

use of org.apache.hadoop.hive.serde2.lazy.ByteArrayRef in project hive by apache.

the class TestAvroLazyObjectInspector method testEmptyData.

@Test
public void testEmptyData() {
    List<String> fieldNames = new ArrayList<String>();
    fieldNames.add("myField");
    List<ObjectInspector> ois = new ArrayList<ObjectInspector>();
    ois.add(LazyPrimitiveObjectInspectorFactory.getLazyStringObjectInspector(false, new Byte((byte) 0)));
    AvroLazyObjectInspector aloi = new AvroLazyObjectInspector(fieldNames, ois, null, (byte) 0, new Text(), false, false, (byte) 0);
    LazyStruct lazyStruct = new LazyStruct(LazyObjectInspectorFactory.getLazySimpleStructObjectInspector(fieldNames, ois, (byte) 0, new Text(), false, false, (byte) 0));
    ByteArrayRef byteArrayRef = new ByteArrayRef();
    // set data to empty explicitly
    byteArrayRef.setData(new byte[0]);
    lazyStruct.init(byteArrayRef, 0, 0);
    assertNull(aloi.getStructFieldData(lazyStruct, new TestStructField()));
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) LazyStruct(org.apache.hadoop.hive.serde2.lazy.LazyStruct) Test(org.junit.Test)

Example 19 with ByteArrayRef

use of org.apache.hadoop.hive.serde2.lazy.ByteArrayRef in project hive by apache.

the class AvroLazyObjectInspector method toLazyPrimitiveObject.

/**
   * Convert the given object to a lazy object using the given {@link ObjectInspector}
   *
   * @param obj Object to be converted to a {@link LazyObject}
   * @param oi ObjectInspector used for the conversion
   * @return the created {@link LazyObject lazy object}
   * */
private LazyObject<? extends ObjectInspector> toLazyPrimitiveObject(Object obj, ObjectInspector oi) {
    if (obj == null) {
        return null;
    }
    LazyObject<? extends ObjectInspector> lazyObject = LazyFactory.createLazyObject(oi);
    ByteArrayRef ref = new ByteArrayRef();
    String objAsString = obj.toString().trim();
    ref.setData(objAsString.getBytes());
    // initialize the lazy object
    lazyObject.init(ref, 0, ref.getData().length);
    return lazyObject;
}
Also used : ByteArrayRef(org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)

Example 20 with ByteArrayRef

use of org.apache.hadoop.hive.serde2.lazy.ByteArrayRef in project hive by apache.

the class LazyDioBoolean method init.

/* (non-Javadoc)
   * This provides a LazyBoolean like class which can be initialized from data stored in a
   * binary format.
   *
   * @see org.apache.hadoop.hive.serde2.lazy.LazyObject#init
   *        (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef, int, int)
   */
@Override
public void init(ByteArrayRef bytes, int start, int length) {
    boolean value = false;
    try {
        in = new ByteStream.Input(bytes.getData(), start, length);
        din = new DataInputStream(in);
        value = din.readBoolean();
        data.set(value);
        isNull = false;
    } catch (IOException e) {
        isNull = true;
    } finally {
        try {
            din.close();
        } catch (IOException e) {
        // swallow exception
        }
        try {
            in.close();
        } catch (IOException e) {
        // swallow exception
        }
    }
}
Also used : ByteStream(org.apache.hadoop.hive.serde2.ByteStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Aggregations

ByteArrayRef (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)27 LazySimpleStructObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector)12 Text (org.apache.hadoop.io.Text)11 Test (org.junit.Test)11 Mutation (org.apache.accumulo.core.data.Mutation)10 LazyStruct (org.apache.hadoop.hive.serde2.lazy.LazyStruct)9 DataInputStream (java.io.DataInputStream)8 Properties (java.util.Properties)8 Configuration (org.apache.hadoop.conf.Configuration)8 ByteStream (org.apache.hadoop.hive.serde2.ByteStream)8 LazySerDeParameters (org.apache.hadoop.hive.serde2.lazy.LazySerDeParameters)8 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)8 IOException (java.io.IOException)7 Connector (org.apache.accumulo.core.client.Connector)6 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)6 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)6 Key (org.apache.accumulo.core.data.Key)6 Value (org.apache.accumulo.core.data.Value)6 Authorizations (org.apache.accumulo.core.security.Authorizations)6 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)6