Search in sources :

Example 16 with VIntWritable

use of org.apache.hadoop.io.VIntWritable in project SQLWindowing by hbutani.

the class PartitionedByteBasedSortedMapTest method testGeti.

@Test
public void testGeti() throws Exception {
    int i = 0;
    for (i = table.length - 1; i >= 0; i--) {
        bm.put(new Text(table[i]), new VIntWritable(i));
    }
    Assert.assertEquals(table.length, bm.size());
    for (i = 0; i < table.length; i++) {
        bm.getKey(i, wObj);
        Assert.assertEquals(table[i], wObj.toString());
        bm.getValue(wObj, value);
        Assert.assertEquals(value.get(), i);
    }
}
Also used : VIntWritable(org.apache.hadoop.io.VIntWritable) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 17 with VIntWritable

use of org.apache.hadoop.io.VIntWritable in project SQLWindowing by hbutani.

the class PersistentByteBasedSortedMapTest method testEntryItr.

@Test
public void testEntryItr() throws Exception {
    int i = 0;
    for (i = table.length - 1; i >= 0; i--) {
        bm.put(new Text(table[i]), new VIntWritable(i));
    }
    File f = File.createTempFile("wdw", null);
    f.deleteOnExit();
    PersistentByteBasedSortedMap.store(bm, f);
    bm = null;
    PersistentByteBasedSortedMap pm = new PersistentByteBasedSortedMap(f, comparator);
    Assert.assertEquals(table.length, pm.size());
    Iterator<ByteBasedSortedMap.WritableEntry> it = pm.entryIterator(wEntry);
    i = 0;
    while (it.hasNext()) {
        ByteBasedSortedMap.WritableEntry e = it.next();
        Assert.assertEquals(table[i], e.getKey().toString());
        Assert.assertEquals(((VIntWritable) e.getValue()).get(), i);
        i++;
    }
}
Also used : VIntWritable(org.apache.hadoop.io.VIntWritable) Text(org.apache.hadoop.io.Text) File(java.io.File) Test(org.junit.Test) ByteBasedSortedMapTest(com.sap.hadoop.ds.sortedmap.ByteBasedSortedMapTest)

Example 18 with VIntWritable

use of org.apache.hadoop.io.VIntWritable in project SQLWindowing by hbutani.

the class PersistentByteBasedSortedMapTest method testGeti.

@Test
public void testGeti() throws Exception {
    int i = 0;
    for (i = table.length - 1; i >= 0; i--) {
        bm.put(new Text(table[i]), new VIntWritable(i));
    }
    File f = File.createTempFile("wdw", null);
    f.deleteOnExit();
    PersistentByteBasedSortedMap.store(bm, f);
    bm = null;
    PersistentByteBasedSortedMap pm = new PersistentByteBasedSortedMap(f, comparator);
    Assert.assertEquals(table.length, pm.size());
    for (i = 0; i < table.length; i++) {
        pm.getKey(i, wObj);
        Assert.assertEquals(table[i], wObj.toString());
        pm.getValue(wObj, value);
        Assert.assertEquals(value.get(), i);
    }
}
Also used : VIntWritable(org.apache.hadoop.io.VIntWritable) Text(org.apache.hadoop.io.Text) File(java.io.File) Test(org.junit.Test) ByteBasedSortedMapTest(com.sap.hadoop.ds.sortedmap.ByteBasedSortedMapTest)

Example 19 with VIntWritable

use of org.apache.hadoop.io.VIntWritable in project hive by apache.

the class ReaderWriter method readDatum.

public static Object readDatum(DataInput in) throws IOException {
    byte type = in.readByte();
    switch(type) {
        case DataType.STRING:
            byte[] buffer = new byte[in.readInt()];
            in.readFully(buffer);
            return new String(buffer, UTF8);
        case DataType.INTEGER:
            VIntWritable vint = new VIntWritable();
            vint.readFields(in);
            return vint.get();
        case DataType.LONG:
            VLongWritable vlong = new VLongWritable();
            vlong.readFields(in);
            return vlong.get();
        case DataType.FLOAT:
            return in.readFloat();
        case DataType.DOUBLE:
            return in.readDouble();
        case DataType.BOOLEAN:
            return in.readBoolean();
        case DataType.BYTE:
            return in.readByte();
        case DataType.SHORT:
            return in.readShort();
        case DataType.NULL:
            return null;
        case DataType.BINARY:
            int len = in.readInt();
            byte[] ba = new byte[len];
            in.readFully(ba);
            return ba;
        case DataType.MAP:
            int size = in.readInt();
            Map<Object, Object> m = new HashMap<Object, Object>(size);
            for (int i = 0; i < size; i++) {
                m.put(readDatum(in), readDatum(in));
            }
            return m;
        case DataType.LIST:
            int sz = in.readInt();
            List<Object> list = new ArrayList<Object>(sz);
            for (int i = 0; i < sz; i++) {
                list.add(readDatum(in));
            }
            return list;
        case DataType.CHAR:
            HiveCharWritable hcw = new HiveCharWritable();
            hcw.readFields(in);
            return hcw.getHiveChar();
        case DataType.VARCHAR:
            HiveVarcharWritable hvw = new HiveVarcharWritable();
            hvw.readFields(in);
            return hvw.getHiveVarchar();
        case DataType.DECIMAL:
            HiveDecimalWritable hdw = new HiveDecimalWritable();
            hdw.readFields(in);
            return hdw.getHiveDecimal();
        case DataType.DATE:
            DateWritable dw = new DateWritable();
            dw.readFields(in);
            return dw.get();
        case DataType.TIMESTAMP:
            TimestampWritable tw = new TimestampWritable();
            tw.readFields(in);
            return tw.getTimestamp();
        default:
            throw new IOException("Unexpected data type " + type + " found in stream.");
    }
}
Also used : HashMap(java.util.HashMap) VIntWritable(org.apache.hadoop.io.VIntWritable) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) ArrayList(java.util.ArrayList) HiveCharWritable(org.apache.hadoop.hive.serde2.io.HiveCharWritable) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) IOException(java.io.IOException) VLongWritable(org.apache.hadoop.io.VLongWritable)

Aggregations

VIntWritable (org.apache.hadoop.io.VIntWritable)19 Text (org.apache.hadoop.io.Text)16 Test (org.junit.Test)14 ByteBasedSortedMapTest (com.sap.hadoop.ds.sortedmap.ByteBasedSortedMapTest)4 File (java.io.File)4 Writable (org.apache.hadoop.io.Writable)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)2 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)2 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)2 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)2 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)2 VLongWritable (org.apache.hadoop.io.VLongWritable)2 Date (java.sql.Date)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1