Example usage for org.apache.hadoop.io BooleanWritable get

List of usage examples for org.apache.hadoop.io BooleanWritable get

Introduction

In this page you can find the example usage for org.apache.hadoop.io BooleanWritable get.

Prototype

public boolean get() 

Source Link

Document

Returns the value of the BooleanWritable

Usage

From source file:com.axiomine.largecollections.kryo.serializers.BooleanWritableSerializer.java

License:Apache License

public void write(Kryo kryo, Output output, BooleanWritable object) {
    byte[] ba = SerDeUtils.serializeWritable(object);
    output.writeBoolean(object.get());
}

From source file:com.cloudera.impala.hive.executor.TestUdf.java

License:Apache License

public BooleanWritable evaluate(BooleanWritable a) {
    if (a == null)
        return null;
    return new BooleanWritable(a.get());
}

From source file:com.cloudera.impala.hive.executor.UdfExecutor.java

License:Apache License

private void storeUdfResult(Object obj) throws ImpalaRuntimeException {
    if (obj == null) {
        UnsafeUtil.UNSAFE.putByte(outputNullPtr_, (byte) 1);
        return;/*ww  w . j ava2s  .  c o m*/
    }

    UnsafeUtil.UNSAFE.putByte(outputNullPtr_, (byte) 0);

    switch (retType_.getPrimitiveType()) {
    case BOOLEAN: {
        BooleanWritable val = (BooleanWritable) obj;
        UnsafeUtil.UNSAFE.putByte(outputBufferPtr_, val.get() ? (byte) 1 : 0);
        return;
    }
    case TINYINT: {
        ByteWritable val = (ByteWritable) obj;
        UnsafeUtil.UNSAFE.putByte(outputBufferPtr_, val.get());
        return;
    }
    case SMALLINT: {
        ShortWritable val = (ShortWritable) obj;
        UnsafeUtil.UNSAFE.putShort(outputBufferPtr_, val.get());
        return;
    }
    case INT: {
        IntWritable val = (IntWritable) obj;
        UnsafeUtil.UNSAFE.putInt(outputBufferPtr_, val.get());
        return;
    }
    case BIGINT: {
        LongWritable val = (LongWritable) obj;
        UnsafeUtil.UNSAFE.putLong(outputBufferPtr_, val.get());
        return;
    }
    case FLOAT: {
        FloatWritable val = (FloatWritable) obj;
        UnsafeUtil.UNSAFE.putFloat(outputBufferPtr_, val.get());
        return;
    }
    case DOUBLE: {
        DoubleWritable val = (DoubleWritable) obj;
        UnsafeUtil.UNSAFE.putDouble(outputBufferPtr_, val.get());
        return;
    }
    case STRING: {
        byte[] bytes = null;
        if (obj instanceof byte[]) {
            bytes = (byte[]) obj;
        } else if (obj instanceof BytesWritable) {
            bytes = ((BytesWritable) obj).copyBytes();
        } else if (obj instanceof Text) {
            bytes = ((Text) obj).copyBytes();
        } else if (obj instanceof String) {
            bytes = ((String) obj).getBytes();
        } else {
            throw new ImpalaRuntimeException("Unexpected return type: " + obj.getClass());
        }

        if (bytes.length > outBufferCapacity_) {
            outBufferStringPtr_ = UnsafeUtil.UNSAFE.reallocateMemory(outBufferStringPtr_, bytes.length);
            outBufferCapacity_ = bytes.length;
            UnsafeUtil.UNSAFE.putLong(outputBufferPtr_, outBufferStringPtr_);
        }
        UnsafeUtil.Copy(outBufferStringPtr_, bytes, 0, bytes.length);
        UnsafeUtil.UNSAFE.putInt(outputBufferPtr_ + ImpalaStringWritable.STRING_VALUE_LEN_OFFSET, bytes.length);
        return;
    }
    case TIMESTAMP:
    default:
        throw new ImpalaRuntimeException("Unsupported argument type: " + retType_);
    }
}

From source file:com.datasalt.utils.commons.TestExpiringSemaphore.java

License:Apache License

@Test
public void testParallelism() throws InterruptedException {
    final ExpiringSemaphore semaphore = new ExpiringSemaphore(1, 2000);
    final BooleanWritable flag = new BooleanWritable();

    Thread[] threads = new Thread[10];

    for (int i = 0; i < 10; i++) {
        threads[i] = new Thread() {
            @Override// www . j  ava2s  .  com
            public void run() {
                try {
                    for (int i = 0; i < 200; i++) {
                        semaphore.acquire();
                        if (flag.get()) {
                            throw new RuntimeException("Semaphore is not behaving as expected");
                        }
                        flag.set(true);
                        flag.set(false);
                        semaphore.release();
                    }
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
    }

    for (int i = 0; i < 10; i++) {
        threads[i].start();
    }

    for (int i = 0; i < 10; i++) {
        threads[i].join();
    }
}

From source file:com.facebook.hive.orc.lazy.OrcLazyBooleanObjectInspector.java

License:Open Source License

@Override
public Object getPrimitiveJavaObject(Object o) {
    BooleanWritable writable = getPrimitiveWritableObject(o);
    return writable == null ? null : Boolean.valueOf(writable.get());
}

From source file:com.facebook.hive.orc.TestOrcFile.java

License:Apache License

private void compareRowsWithoutNextIsNull(OrcStruct row, RandomRowInputs inputs, int rowNumber,
        NumberOfNulls numNulls, boolean usingPrimitives) throws Exception {

    ReallyBigRow expected = null;//from   w ww.j a v  a 2  s  .com
    switch (numNulls) {
    case MANY:
    case SOME:
        expected = createRandomRowWithNulls(inputs.intValues, inputs.doubleValues, inputs.stringValues,
                inputs.byteValues, inputs.words, rowNumber, numNulls);
        break;
    case NONE:
        expected = createRandomRow(inputs.intValues, inputs.doubleValues, inputs.stringValues,
                inputs.byteValues, inputs.words, rowNumber);
        break;
    }

    OrcLazyBoolean lazyBoolean1 = (OrcLazyBoolean) row.getFieldValue(0);
    BooleanWritable boolean1 = (BooleanWritable) lazyBoolean1.materialize();
    if (boolean1 == null) {
        assertNull(expected.boolean1);
    } else {
        assertEquals(expected.boolean1.booleanValue(), boolean1.get());
    }

    ByteWritable byte1 = (ByteWritable) ((OrcLazyByte) row.getFieldValue(1)).materialize();
    if (byte1 == null) {
        assertNull(expected.byte1);
    } else {
        assertEquals(expected.byte1.byteValue(), byte1.get());
    }

    OrcLazyShort lazyShort1 = (OrcLazyShort) row.getFieldValue(2);
    ShortWritable short1 = (ShortWritable) lazyShort1.materialize();
    if (short1 == null) {
        assertNull(expected.short1);
    } else {
        assertEquals(expected.short1.shortValue(), short1.get());
    }

    OrcLazyInt lazyInt1 = (OrcLazyInt) row.getFieldValue(3);
    IntWritable int1 = (IntWritable) lazyInt1.materialize();
    if (int1 == null) {
        assertNull(expected.int1);
    } else {
        assertEquals(expected.int1.intValue(), int1.get());
    }

    OrcLazyLong lazyLong1 = (OrcLazyLong) row.getFieldValue(4);
    LongWritable long1 = (LongWritable) lazyLong1.materialize();
    if (long1 == null) {
        assertNull(expected.long1);
    } else {
        assertEquals(expected.long1.longValue(), long1.get());
    }

    OrcLazyShort lazyShort2 = (OrcLazyShort) row.getFieldValue(5);
    ShortWritable short2 = (ShortWritable) lazyShort2.materialize();
    if (short2 == null) {
        assertNull(expected.short2);
    } else {
        assertEquals(expected.short2.shortValue(), short2.get());
    }

    OrcLazyInt lazyInt2 = (OrcLazyInt) row.getFieldValue(6);
    IntWritable int2 = (IntWritable) lazyInt2.materialize();
    if (int2 == null) {
        assertNull(expected.int2);
    } else {
        assertEquals(expected.int2.intValue(), int2.get());
    }

    OrcLazyLong lazyLong2 = (OrcLazyLong) row.getFieldValue(7);
    LongWritable long2 = (LongWritable) lazyLong2.materialize();
    if (long2 == null) {
        assertNull(expected.long2);
    } else {
        assertEquals(expected.long2.longValue(), long2.get());
    }

    OrcLazyShort lazyShort3 = (OrcLazyShort) row.getFieldValue(8);
    ShortWritable short3 = (ShortWritable) lazyShort3.materialize();
    if (short3 == null) {
        assertNull(expected.short3);
    } else {
        assertEquals(expected.short3.shortValue(), short3.get());
    }

    OrcLazyInt lazyInt3 = (OrcLazyInt) row.getFieldValue(9);
    IntWritable int3 = (IntWritable) lazyInt3.materialize();
    if (int3 == null) {
        assertNull(expected.int3);
    } else {
        assertEquals(expected.int3.intValue(), int3.get());
    }

    OrcLazyLong lazyLong3 = (OrcLazyLong) row.getFieldValue(10);
    LongWritable long3 = (LongWritable) lazyLong3.materialize();
    if (long3 == null) {
        assertNull(expected.long3);
    } else {
        assertEquals(expected.long3.longValue(), long3.get());
    }

    OrcLazyFloat lazyFloat1 = (OrcLazyFloat) row.getFieldValue(11);
    FloatWritable float1 = (FloatWritable) lazyFloat1.materialize();
    if (float1 == null) {
        assertNull(expected.float1);
    } else {
        assertEquals(expected.float1.floatValue(), float1.get(), 0.0001);
    }

    OrcLazyDouble lazyDouble1 = (OrcLazyDouble) row.getFieldValue(12);
    DoubleWritable double1 = (DoubleWritable) lazyDouble1.materialize();
    if (double1 == null) {
        assertNull(expected.double1);
    } else {
        assertEquals(expected.double1.doubleValue(), double1.get(), 0.0001);
    }

    BytesWritable bytes1 = (BytesWritable) ((OrcLazyBinary) row.getFieldValue(13)).materialize();
    if (bytes1 == null) {
        assertNull(expected.bytes1);
    } else {
        assertEquals(expected.bytes1, bytes1);
    }

    Text string1 = (Text) ((OrcLazyString) row.getFieldValue(14)).materialize();
    if (string1 == null) {
        assertNull(expected.string1);
    } else {
        assertEquals(expected.string1, string1);
    }

    Text string2 = (Text) ((OrcLazyString) row.getFieldValue(15)).materialize();
    if (string2 == null) {
        assertNull(expected.string2);
    } else {
        assertEquals(expected.string2, string2);
    }

    Text string3 = (Text) ((OrcLazyString) row.getFieldValue(16)).materialize();
    if (string3 == null) {
        assertNull(expected.string3);
    } else {
        assertEquals(expected.string3, string3);
    }

    OrcStruct middle = (OrcStruct) ((OrcLazyStruct) row.getFieldValue(17)).materialize();
    if (middle == null) {
        assertNull(expected.middle);
    } else {
        final List<InnerStruct> expectedList = expected.middle.list;
        final List<OrcStruct> actualList = (List) middle.getFieldValue(0);
        compareListOfStructs(expectedList, actualList);
        final List<String> actualFieldNames = middle.getFieldNames();
        final List<String> expectedFieldNames = ImmutableList.of("list");
        compareLists(expectedFieldNames, actualFieldNames);
    }

    List list = (List) ((OrcLazyList) row.getFieldValue(18)).materialize();
    if (list == null) {
        assertNull(expected.list);
    } else {
        compareListOfStructs(expected.list, list);
    }

    Map map = (Map) ((OrcLazyMap) row.getFieldValue(19)).materialize();
    if (map == null) {
        assertNull(expected.map);
    } else {
        compareMap(expected.map, map);
    }

    if (usingPrimitives) {
        compareRowsUsingPrimitives(expected, lazyBoolean1, lazyShort1, lazyInt1, lazyLong1, lazyShort2,
                lazyInt2, lazyLong2, lazyShort3, lazyInt3, lazyLong3, lazyFloat1, lazyDouble1);
    }
}

From source file:com.facebook.presto.hive.DwrfHiveRecordCursor.java

License:Apache License

private void parseBooleanColumn(int column) {
    // don't include column number in message because it causes boxing which is expensive here
    checkArgument(!isPartitionColumn[column], "Column is a partition key");

    loaded[column] = true;//from w w  w . ja  va  2 s.c o m

    Object object = getMaterializedValue(column);

    if (object == null) {
        nulls[column] = true;
    } else {
        nulls[column] = false;
        BooleanWritable booleanWritable = checkWritable(object, BooleanWritable.class);
        booleans[column] = booleanWritable.get();
    }
}

From source file:com.jfolson.hive.serde.RTypedBytesWritableOutput.java

License:Apache License

public void writeRawBoolean(BooleanWritable bw) throws IOException {
    out.writeRawBool(bw.get());
}

From source file:com.jfolson.hive.serde.RTypedBytesWritableOutput.java

License:Apache License

public void writeBoolean(BooleanWritable bw) throws IOException {
    out.writeBool(bw.get());
}

From source file:com.moz.fiji.hive.io.FijiCellWritable.java

License:Apache License

/**
 * Reads and converts data according to the specified schema.
 *
 * @param in DataInput to deserialize this object from.
 * @param schema Schema to be used for deserializing this data.
 * @return the data read and converted according to the schema.
 * @throws IOException if there was an error reading.
 *//*from  w w  w  .  j  av  a  2  s .c  o  m*/
private static Object readData(DataInput in, Schema schema) throws IOException {
    switch (schema.getType()) {
    case INT:
        Integer intData = WritableUtils.readVInt(in);
        return intData;
    case LONG:
        Long longData = WritableUtils.readVLong(in);
        return longData;
    case DOUBLE:
        DoubleWritable doubleWritable = (DoubleWritable) WritableFactories.newInstance(DoubleWritable.class);
        doubleWritable.readFields(in);
        return doubleWritable.get();
    case ENUM:
    case STRING:
        String stringData = WritableUtils.readString(in);
        return stringData;
    case FLOAT:
        FloatWritable floatWritable = (FloatWritable) WritableFactories.newInstance(FloatWritable.class);
        floatWritable.readFields(in);
        return floatWritable.get();
    case ARRAY:
        List<Object> listData = Lists.newArrayList();
        Integer numElements = WritableUtils.readVInt(in);
        for (int c = 0; c < numElements; c++) {
            Object listElement = readData(in, schema.getElementType());
            listData.add(listElement);
        }
        return listData;
    case RECORD:
        GenericRecord recordData = new GenericData.Record(schema);
        Integer numFields = WritableUtils.readVInt(in);
        for (int c = 0; c < numFields; c++) {
            String fieldName = WritableUtils.readString(in);
            Object fieldData = readData(in, schema.getField(fieldName).schema());
            recordData.put(fieldName, fieldData);
        }
        return recordData;
    case MAP:
        Map<String, Object> mapData = Maps.newHashMap();
        Integer numEntries = WritableUtils.readVInt(in);
        for (int c = 0; c < numEntries; c++) {
            String key = WritableUtils.readString(in);
            Object value = readData(in, schema.getValueType());
            mapData.put(key, value);
        }
        return mapData;
    case UNION:
        Integer tag = WritableUtils.readVInt(in);
        Schema unionSubSchema = schema.getTypes().get(tag);
        Object unionData = readData(in, unionSubSchema);
        return unionData;
    case BYTES:
        byte[] bytesData = WritableUtils.readCompressedByteArray(in);
        return bytesData;
    case BOOLEAN:
        BooleanWritable booleanWritable = (BooleanWritable) WritableFactories
                .newInstance(BooleanWritable.class);
        booleanWritable.readFields(in);
        return booleanWritable.get();
    case NULL:
        return null;
    default:
        throw new UnsupportedOperationException("Unsupported type: " + schema.getType());
    }
}