Search in sources :

Example 1 with VIntWritable

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

the class ReaderWriter method writeDatum.

public static void writeDatum(DataOutput out, Object val) throws IOException {
    // write the data type
    byte type = DataType.findType(val);
    out.write(type);
    switch(type) {
        case DataType.LIST:
            List<?> list = (List<?>) val;
            int sz = list.size();
            out.writeInt(sz);
            for (int i = 0; i < sz; i++) {
                writeDatum(out, list.get(i));
            }
            return;
        case DataType.MAP:
            Map<?, ?> m = (Map<?, ?>) val;
            out.writeInt(m.size());
            Iterator<?> i = m.entrySet().iterator();
            while (i.hasNext()) {
                Entry<?, ?> entry = (Entry<?, ?>) i.next();
                writeDatum(out, entry.getKey());
                writeDatum(out, entry.getValue());
            }
            return;
        case DataType.INTEGER:
            new VIntWritable((Integer) val).write(out);
            return;
        case DataType.LONG:
            new VLongWritable((Long) val).write(out);
            return;
        case DataType.FLOAT:
            out.writeFloat((Float) val);
            return;
        case DataType.DOUBLE:
            out.writeDouble((Double) val);
            return;
        case DataType.BOOLEAN:
            out.writeBoolean((Boolean) val);
            return;
        case DataType.BYTE:
            out.writeByte((Byte) val);
            return;
        case DataType.SHORT:
            out.writeShort((Short) val);
            return;
        case DataType.STRING:
            String s = (String) val;
            byte[] utfBytes = s.getBytes(ReaderWriter.UTF8);
            out.writeInt(utfBytes.length);
            out.write(utfBytes);
            return;
        case DataType.BINARY:
            byte[] ba = (byte[]) val;
            out.writeInt(ba.length);
            out.write(ba);
            return;
        case DataType.NULL:
            // for NULL we just write out the type
            return;
        case DataType.CHAR:
            new HiveCharWritable((HiveChar) val).write(out);
            return;
        case DataType.VARCHAR:
            new HiveVarcharWritable((HiveVarchar) val).write(out);
            return;
        case DataType.DECIMAL:
            new HiveDecimalWritable((HiveDecimal) val).write(out);
            return;
        case DataType.DATE:
            new DateWritableV2((Date) val).write(out);
            return;
        case DataType.TIMESTAMP:
            new TimestampWritableV2((Timestamp) val).write(out);
            return;
        default:
            throw new IOException("Unexpected data type " + type + " found in stream.");
    }
}
Also used : VIntWritable(org.apache.hadoop.io.VIntWritable) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) Timestamp(org.apache.hadoop.hive.common.type.Timestamp) Entry(java.util.Map.Entry) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) ArrayList(java.util.ArrayList) List(java.util.List) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) HiveCharWritable(org.apache.hadoop.hive.serde2.io.HiveCharWritable) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) IOException(java.io.IOException) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) Date(org.apache.hadoop.hive.common.type.Date) VLongWritable(org.apache.hadoop.io.VLongWritable) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with VIntWritable

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

the class ByteBasedSortedMapTest method setup.

@Before
public void setup() throws Exception {
    bm = new ByteBasedSortedMap(WritableComparator.get(Text.class));
    cls = sd.getSerializedClass();
    wObj = cls.newInstance();
    value = new VIntWritable();
    wEntry = new ByteBasedSortedMap.WritableEntry(wObj, value);
    bldr = new StringBuilder();
}
Also used : VIntWritable(org.apache.hadoop.io.VIntWritable) Before(org.junit.Before)

Example 3 with VIntWritable

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

the class ByteBasedSortedMapTest 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));
    }
    Assert.assertEquals(table.length, bm.size());
    Iterator<ByteBasedSortedMap.WritableEntry> it = bm.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) Test(org.junit.Test)

Example 4 with VIntWritable

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

the class PartitionedByteBasedSortedMapTest method setup.

@Before
public void setup() throws Exception {
    comparator = WritableComparator.get(Text.class);
    bm = new PartitionedByteBasedSortedMap(100, comparator);
    cls = sd.getSerializedClass();
    wObj = cls.newInstance();
    value = new VIntWritable();
    wEntry = new ByteBasedSortedMap.WritableEntry(wObj, value);
    bldr = new StringBuilder();
}
Also used : VIntWritable(org.apache.hadoop.io.VIntWritable) Text(org.apache.hadoop.io.Text) Before(org.junit.Before)

Example 5 with VIntWritable

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

the class PartitionedByteBasedSortedMapTest 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));
    }
    Assert.assertEquals(table.length, bm.size());
    Iterator<ByteBasedSortedMap.WritableEntry> it = bm.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) Test(org.junit.Test)

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 LinkedHashMap (java.util.LinkedHashMap)2 DateWritableV2 (org.apache.hadoop.hive.serde2.io.DateWritableV2)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 TimestampWritableV2 (org.apache.hadoop.hive.serde2.io.TimestampWritableV2)2 VLongWritable (org.apache.hadoop.io.VLongWritable)2 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Date (org.apache.hadoop.hive.common.type.Date)1