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:org.apache.hawq.pxf.plugins.hdfs.utilities.RecordkeyAdapterTest.java

License:Apache License

/**
 * Test convertKeyValue for boolean type and then string type - negative
 * test/*from   w w  w  . j  a  v a 2 s .c o m*/
 */
@Test
public void convertKeyValueBadSecondValue() {
    boolean key = true;
    initRecordkeyAdapter();
    runConvertKeyValue(key, new BooleanWritable(key));
    String badKey = "bad";
    try {
        recordkeyAdapter.convertKeyValue(badKey);
        fail("conversion of string to boolean should fail");
    } catch (ClassCastException e) {
        assertEquals(e.getMessage(), "java.lang.String cannot be cast to java.lang.Boolean");
    }
}

From source file:org.apache.hive.benchmark.storage.ColumnarStorageBench.java

License:Apache License

private Writable getPrimitiveWritable(final PrimitiveTypeInfo typeInfo) {
    Random rand = new Random();

    switch (typeInfo.getPrimitiveCategory()) {
    case INT:/* w  w w .  j  a va 2  s .  c om*/
        return new IntWritable(rand.nextInt());
    case DOUBLE:
        return new DoubleWritable(rand.nextDouble());
    case BOOLEAN:
        return new BooleanWritable(rand.nextBoolean());
    case CHAR:
    case VARCHAR:
    case STRING:
        byte b[] = new byte[30];
        rand.nextBytes(b);
        return new BytesWritable(b);
    default:
        throw new IllegalArgumentException("Invalid primitive type: " + typeInfo.getTypeName());
    }
}

From source file:org.apache.metron.common.cli.ConfigurationManagerIntegrationTest.java

License:Apache License

@Test
public void testPush() throws Exception {
    pushConfigs();//from   www.  j  av a 2 s . co  m
    final Set<String> sensorsInZookeeper = new HashSet<>();
    final BooleanWritable foundGlobal = new BooleanWritable(false);
    ConfigurationsUtils.visitConfigs(client, new ConfigurationsUtils.ConfigurationVisitor() {
        @Override
        public void visit(ConfigurationType configurationType, String name, String data) {
            Assert.assertTrue(data.length() > 0);
            validateConfig(name, configurationType, data);
            if (configurationType == ConfigurationType.GLOBAL) {
                validateConfig(name, configurationType, data);
                foundGlobal.set(true);
            } else {
                sensorsInZookeeper.add(name);
            }
        }
    });
    Assert.assertEquals(true, foundGlobal.get());
    Assert.assertEquals(sensorsInZookeeper, sensors);
}

From source file:org.apache.orc.mapred.TestOrcOutputFormat.java

License:Apache License

@Test
public void testAllTypes() throws Exception {
    conf.set("mapreduce.task.attempt.id", "attempt_20160101_0001_m_000001_0");
    conf.setOutputCommitter(NullOutputCommitter.class);
    final String typeStr = "struct<b1:binary,b2:boolean,b3:tinyint,"
            + "c:char(10),d1:date,d2:decimal(20,5),d3:double,fff:float,int:int,"
            + "l:array<bigint>,map:map<smallint,string>,"
            + "str:struct<u:uniontype<timestamp,varchar(100)>>,ts:timestamp>";
    OrcConf.MAPRED_OUTPUT_SCHEMA.setString(conf, typeStr);
    FileOutputFormat.setOutputPath(conf, workDir);
    TypeDescription type = TypeDescription.fromString(typeStr);

    // build a row object
    OrcStruct row = (OrcStruct) OrcStruct.createValue(type);
    ((BytesWritable) row.getFieldValue(0)).set(new byte[] { 1, 2, 3, 4 }, 0, 4);
    ((BooleanWritable) row.getFieldValue(1)).set(true);
    ((ByteWritable) row.getFieldValue(2)).set((byte) 23);
    ((Text) row.getFieldValue(3)).set("aaabbbcccddd");
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    ((DateWritable) row.getFieldValue(4)).set(DateWritable.millisToDays(format.parse("2016-04-01").getTime()));
    ((HiveDecimalWritable) row.getFieldValue(5)).set(new HiveDecimalWritable("1.23"));
    ((DoubleWritable) row.getFieldValue(6)).set(1.5);
    ((FloatWritable) row.getFieldValue(7)).set(4.5f);
    ((IntWritable) row.getFieldValue(8)).set(31415);
    OrcList<LongWritable> longList = (OrcList<LongWritable>) row.getFieldValue(9);
    longList.add(new LongWritable(123));
    longList.add(new LongWritable(456));
    OrcMap<ShortWritable, Text> map = (OrcMap<ShortWritable, Text>) row.getFieldValue(10);
    map.put(new ShortWritable((short) 1000), new Text("aaaa"));
    map.put(new ShortWritable((short) 123), new Text("bbbb"));
    OrcStruct struct = (OrcStruct) row.getFieldValue(11);
    OrcUnion union = (OrcUnion) struct.getFieldValue(0);
    union.set((byte) 1, new Text("abcde"));
    ((OrcTimestamp) row.getFieldValue(12)).set("1996-12-11 15:00:00");
    NullWritable nada = NullWritable.get();
    RecordWriter<NullWritable, OrcStruct> writer = new OrcOutputFormat<OrcStruct>().getRecordWriter(fs, conf,
            "all.orc", Reporter.NULL);
    for (int r = 0; r < 10; ++r) {
        row.setFieldValue(8, new IntWritable(r * 10));
        writer.write(nada, row);//from w w  w .  ja v  a  2  s.c  o m
    }
    union.set((byte) 0, new OrcTimestamp("2011-12-25 12:34:56"));
    for (int r = 0; r < 10; ++r) {
        row.setFieldValue(8, new IntWritable(r * 10 + 100));
        writer.write(nada, row);
    }
    OrcStruct row2 = new OrcStruct(type);
    writer.write(nada, row2);
    row.setFieldValue(8, new IntWritable(210));
    writer.write(nada, row);
    writer.close(Reporter.NULL);

    FileSplit split = new FileSplit(new Path(workDir, "all.orc"), 0, 100000, new String[0]);
    RecordReader<NullWritable, OrcStruct> reader = new OrcInputFormat<OrcStruct>().getRecordReader(split, conf,
            Reporter.NULL);
    nada = reader.createKey();
    row = reader.createValue();
    for (int r = 0; r < 22; ++r) {
        assertEquals(true, reader.next(nada, row));
        if (r == 20) {
            for (int c = 0; c < 12; ++c) {
                assertEquals(null, row.getFieldValue(c));
            }
        } else {
            assertEquals(new BytesWritable(new byte[] { 1, 2, 3, 4 }), row.getFieldValue(0));
            assertEquals(new BooleanWritable(true), row.getFieldValue(1));
            assertEquals(new ByteWritable((byte) 23), row.getFieldValue(2));
            assertEquals(new Text("aaabbbcccd"), row.getFieldValue(3));
            assertEquals(new DateWritable(DateWritable.millisToDays(format.parse("2016-04-01").getTime())),
                    row.getFieldValue(4));
            assertEquals(new HiveDecimalWritable("1.23"), row.getFieldValue(5));
            assertEquals(new DoubleWritable(1.5), row.getFieldValue(6));
            assertEquals(new FloatWritable(4.5f), row.getFieldValue(7));
            assertEquals(new IntWritable(r * 10), row.getFieldValue(8));
            assertEquals(longList, row.getFieldValue(9));
            assertEquals(map, row.getFieldValue(10));
            if (r < 10) {
                union.set((byte) 1, new Text("abcde"));
            } else {
                union.set((byte) 0, new OrcTimestamp("2011-12-25 12:34:56"));
            }
            assertEquals("row " + r, struct, row.getFieldValue(11));
            assertEquals("row " + r, new OrcTimestamp("1996-12-11 15:00:00"), row.getFieldValue(12));
        }
    }
    assertEquals(false, reader.next(nada, row));
}

From source file:org.apache.phoenix.hive.objectinspector.PhoenixBooleanObjectInspector.java

License:Apache License

@Override
public BooleanWritable getPrimitiveWritableObject(Object o) {
    return new BooleanWritable(get(o));
}

From source file:org.apache.phoenix.hive.util.HiveTypeUtil.java

License:Apache License

/**
 * This method returns the most appropriate Writable associated with the incoming sql type name.
 * @param hiveType,Object//  w  w w .ja  v  a 2 s. c o m
 * @return Wrtiable
 */
// TODO awkward logic revisit
public static Writable SQLType2Writable(String hiveType, Object o) throws SerDeException {
    String lctype = hiveType.toLowerCase();
    if ("string".equals(lctype))
        return new Text(o.toString());
    if ("varchar".equals(lctype))
        return new HiveVarcharWritable(new HiveVarchar(o.toString(), o.toString().length()));
    if ("char".equals(lctype))
        return new HiveCharWritable(new HiveChar(o.toString(), o.toString().length()));
    if ("float".equals(lctype))
        return new FloatWritable(((Float) o).floatValue());
    if ("double".equals(lctype))
        return new DoubleWritable(((Double) o).doubleValue());
    if ("boolean".equals(lctype))
        return new BooleanWritable(((Boolean) o).booleanValue());
    if ("tinyint".equals(lctype))
        return new ShortWritable(((Integer) o).shortValue());
    if ("smallint".equals(lctype))
        return new ShortWritable(((Integer) o).shortValue());
    if ("int".equals(lctype))
        return new IntWritable(((Integer) o).intValue());
    if ("bigint".equals(lctype))
        return new LongWritable(((Long) o).longValue());
    if ("timestamp".equals(lctype))
        return new TimestampWritable((Timestamp) o);
    if ("binary".equals(lctype))
        return new Text(o.toString());
    if ("date".equals(lctype))
        return new DateWritable(new Date((long) o));
    if ("array".equals(lctype))
        ;
    throw new SerDeException("Phoenix unrecognized column type: " + hiveType);
}

From source file:org.apache.pig.impl.io.NullableBooleanWritable.java

License:Apache License

/**
 * @param value
 */
public NullableBooleanWritable(boolean value) {
    mValue = new BooleanWritable(value);
}

From source file:org.archive.bacon.io.SequenceFileStorage.java

License:Apache License

/**
 * Convert the Pig tupleValue to the corresponding Hadoop object.
 *///from ww  w. j  a  v  a 2s  .co  m
public Writable getWritable(Object tupleValue, Writable nullWritable) throws IOException {
    switch (DataType.findType(tupleValue)) {
    case DataType.BOOLEAN:
        return new BooleanWritable((boolean) tupleValue);

    case DataType.BYTE:
        return new ByteWritable((byte) tupleValue);

    case DataType.CHARARRAY:
        return new Text((String) tupleValue);

    case DataType.INTEGER:
        return new IntWritable((int) tupleValue);

    case DataType.LONG:
        return new LongWritable((long) tupleValue);

    case DataType.DOUBLE:
        return new DoubleWritable((double) tupleValue);

    case DataType.FLOAT:
        return new FloatWritable((float) tupleValue);

    case DataType.BYTEARRAY:
        return new BytesWritable((byte[]) tupleValue);

    // If we get a 'null' from Pig, just pass through the
    // already-instantiated Hadoop nullWritable.
    case DataType.NULL:
        return nullWritable;

    // Don't know what to do with these complex data types.
    case DataType.BAG:
    case DataType.ERROR:
    case DataType.MAP:
    case DataType.TUPLE:
    case DataType.UNKNOWN:
    default:
        throw new IOException("Cannot write values of type: " + DataType.findTypeName(tupleValue));
    }
}

From source file:org.archive.hadoop.pig.SequenceFileStorage.java

License:Apache License

/**
 * Convert the Pig tupleValue to the corresponding Hadoop object.
 *///from  w  w  w  .  j  av  a  2s.c o  m
public Writable getWritable(Object tupleValue, Writable nullWritable) throws IOException {
    switch (DataType.findType(tupleValue)) {
    case DataType.BOOLEAN:
        return new BooleanWritable((Boolean) tupleValue);

    case DataType.BYTE:
        return new ByteWritable((Byte) tupleValue);

    case DataType.CHARARRAY:
        return new Text((String) tupleValue);

    case DataType.INTEGER:
        return new IntWritable((Integer) tupleValue);

    case DataType.LONG:
        return new LongWritable((Long) tupleValue);

    case DataType.DOUBLE:
        return new DoubleWritable((Double) tupleValue);

    case DataType.FLOAT:
        return new FloatWritable((Float) tupleValue);

    case DataType.BYTEARRAY:
        return new BytesWritable((byte[]) tupleValue);

    // If we get a 'null' from Pig, just pass through the
    // already-instantiated Hadoop nullWritable.
    case DataType.NULL:
        return nullWritable;

    // Don't know what to do with these complex data types.
    case DataType.BAG:
    case DataType.ERROR:
    case DataType.MAP:
    case DataType.TUPLE:
    case DataType.UNKNOWN:
    default:
        throw new IOException("Cannot write values of type: " + DataType.findTypeName(tupleValue));
    }
}

From source file:org.elasticsearch.hadoop.mr.WritableValueReader.java

License:Apache License

@Override
protected Object processBoolean(Boolean value) {
    return new BooleanWritable(value);
}