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

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

Introduction

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

Prototype

public BooleanWritable(boolean value) 

Source Link

Usage

From source file:cascading.hive.ORCFile.java

License:Apache License

private void tuple2Struct(Tuple tuple, OrcStruct struct) {
    Object value = null;//  www  .  j  ava2s . c  o  m
    for (int i = 0; i < types.length; i++) {
        switch (typeMapping.get(types[i].toLowerCase())) {
        case INT:
            value = tuple.getObject(i) == null ? null : new IntWritable(tuple.getInteger(i));
            break;
        case BOOLEAN:
            value = tuple.getObject(i) == null ? null : new BooleanWritable(tuple.getBoolean(i));
            break;
        case TINYINT:
            value = tuple.getObject(i) == null ? null : new ByteWritable(Byte.valueOf(tuple.getString(i)));
            break;
        case SMALLINT:
            value = tuple.getObject(i) == null ? null : new ShortWritable(tuple.getShort(i));
            break;
        case BIGINT:
            value = tuple.getObject(i) == null ? null : new LongWritable(tuple.getLong(i));
            break;
        case FLOAT:
            value = tuple.getObject(i) == null ? null : new FloatWritable(tuple.getFloat(i));
            break;
        case DOUBLE:
            value = tuple.getObject(i) == null ? null : new DoubleWritable(tuple.getDouble(i));
            break;
        case BIGDECIMAL:
            value = tuple.getObject(i) == null ? null
                    : new HiveDecimalWritable(HiveDecimal.create((new BigDecimal(tuple.getString(i)))));
            break;
        case STRING:
        default:
            value = tuple.getObject(i) == null ? null : new Text(tuple.getString(i));
        }
        struct.setFieldValue(i, value);
    }
}

From source file:cascading.tuple.hadoop.HadoopSerializationPlatformTest.java

License:Open Source License

@Test
public void testInputOutputSerialization() throws IOException {
    long time = System.currentTimeMillis();

    Configuration jobConf = new Configuration();

    jobConf.set("io.serializations",
            TestSerialization.class.getName() + "," + WritableSerialization.class.getName()); // disable/replace WritableSerialization class
    jobConf.set("cascading.serialization.tokens",
            "1000=" + BooleanWritable.class.getName() + ",10001=" + Text.class.getName()); // not using Text, just testing parsing

    TupleSerialization tupleSerialization = new TupleSerialization(jobConf);

    File file = new File(getOutputPath("serialization"));

    file.mkdirs();/*from  w  w w.  java 2 s . c  o  m*/
    file = new File(file, "/test.bytes");

    TupleOutputStream output = new HadoopTupleOutputStream(new FileOutputStream(file, false),
            tupleSerialization.getElementWriter());

    for (int i = 0; i < 501; i++) // 501 is arbitrary
    {
        String aString = "string number " + i;
        double random = Math.random();

        output.writeTuple(new Tuple(i, aString, random, new TestText(aString),
                new Tuple("inner tuple", new BytesWritable("some string".getBytes())),
                new BytesWritable(Integer.toString(i).getBytes("UTF-8")), new BooleanWritable(false)));
    }

    output.close();

    assertEquals("wrong size", 89967L, file.length()); // just makes sure the file size doesnt change from expected

    TupleInputStream input = new HadoopTupleInputStream(new FileInputStream(file),
            tupleSerialization.getElementReader());

    int k = -1;
    for (int i = 0; i < 501; i++) {
        Tuple tuple = input.readTuple();
        int value = tuple.getInteger(0);
        assertTrue("wrong diff", value - k == 1);
        assertTrue("wrong type", tuple.getObject(3) instanceof TestText);
        assertTrue("wrong type", tuple.getObject(4) instanceof Tuple);
        assertTrue("wrong type", tuple.getObject(5) instanceof BytesWritable);

        byte[] bytes = ((BytesWritable) tuple.getObject(5)).getBytes();
        String string = new String(bytes, 0, bytes.length > 1 ? bytes.length - 1 : bytes.length, "UTF-8");
        assertEquals("wrong value", Integer.parseInt(string), i);
        assertTrue("wrong type", tuple.getObject(6) instanceof BooleanWritable);
        k = value;
    }

    input.close();

    System.out.println("time = " + (System.currentTimeMillis() - time));
}

From source file:cascading.tuple.hadoop.HadoopSerializationTest.java

License:Open Source License

public void testInputOutputSerialization() throws IOException {
    long time = System.currentTimeMillis();

    JobConf jobConf = new JobConf();

    jobConf.set("io.serializations",
            TestSerialization.class.getName() + "," + WritableSerialization.class.getName()); // disable/replace WritableSerialization class
    jobConf.set("cascading.serialization.tokens",
            "1000=" + BooleanWritable.class.getName() + ",10001=" + Text.class.getName()); // not using Text, just testing parsing

    TupleSerialization tupleSerialization = new TupleSerialization(jobConf);

    File file = new File(outputPath);

    file.mkdirs();// www. j a  va2 s  .c o  m
    file = new File(file, "/test.bytes");

    TupleOutputStream output = new TupleOutputStream(new FileOutputStream(file, false),
            tupleSerialization.getElementWriter());

    for (int i = 0; i < 501; i++) // 501 is arbitrary
    {
        String aString = "string number " + i;
        double random = Math.random();

        output.writeTuple(new Tuple(i, aString, random, new TestText(aString),
                new Tuple("inner tuple", new BytesWritable("some string".getBytes())),
                new BytesWritable(Integer.toString(i).getBytes("UTF-8")), new BooleanWritable(false)));
    }

    output.close();

    assertEquals("wrong size", 89967L, file.length()); // just makes sure the file size doesnt change from expected

    TupleInputStream input = new TupleInputStream(new FileInputStream(file),
            tupleSerialization.getElementReader());

    int k = -1;
    for (int i = 0; i < 501; i++) {
        Tuple tuple = input.readTuple();
        int value = tuple.getInteger(0);
        assertTrue("wrong diff", value - k == 1);
        assertTrue("wrong type", tuple.get(3) instanceof TestText);
        assertTrue("wrong type", tuple.get(4) instanceof Tuple);
        assertTrue("wrong type", tuple.get(5) instanceof BytesWritable);

        byte[] bytes = ((BytesWritable) tuple.get(5)).getBytes();
        String string = new String(bytes, 0, bytes.length > 1 ? bytes.length - 1 : bytes.length, "UTF-8");
        assertEquals("wrong value", Integer.parseInt(string), i);
        assertTrue("wrong type", tuple.get(6) instanceof BooleanWritable);
        k = value;
    }

    input.close();

    System.out.println("time = " + (System.currentTimeMillis() - time));
}

From source file:co.nubetech.hiho.dedup.TestHashUtility.java

License:Apache License

@Test
public void testMD5HashForBooleanWritableKey() throws IOException {
    BooleanWritable key = new BooleanWritable(true);
    MD5Hash md5HashKey1 = HashUtility.getMD5Hash(key);
    MD5Hash md5HashKey2 = HashUtility.getMD5Hash(key);
    assertEquals(md5HashKey1, md5HashKey2);
}

From source file:co.nubetech.hiho.merge.HihoValue.java

License:Apache License

public void setIsOld(Boolean isOld) {
    this.isOld = new BooleanWritable(isOld);
}

From source file:com.asakusafw.directio.hive.serde.BooleanOptionInspector.java

License:Apache License

@Override
public Object getPrimitiveWritableObject(Object o) {
    BooleanOption object = (BooleanOption) o;
    if (object == null || object.isNull()) {
        return null;
    }//from  www. ja  v  a  2s .com
    return new BooleanWritable(object.get());
}

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

License:Apache License

public BooleanWritable read(Kryo kryo, Input input, Class<BooleanWritable> type) {
    return new BooleanWritable(input.readBoolean());
}

From source file:com.cloudera.crunch.type.writable.WritablesTest.java

License:Open Source License

@Test
public void testBoolean() throws Exception {
    boolean j = false;
    BooleanWritable w = new BooleanWritable(j);
    testInputOutputFn(Writables.booleans(), j, w);
}

From source file:com.cloudera.FuzzyEqualsUdf.java

License:Apache License

public BooleanWritable evaluate(DoubleWritable x, DoubleWritable y) {
    double EPSILON = 0.000001f;
    if (x == null || y == null)
        return null;
    return new BooleanWritable(Math.abs(x.get() - y.get()) < EPSILON);
}

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());
}