use of org.apache.hadoop.io.VIntWritable in project SQLWindowing by hbutani.
the class PersistentByteBasedSortedMapTest method setup.
@Before
public void setup() throws Exception {
comparator = WritableComparator.get(Text.class);
bm = new ByteBasedSortedMap(comparator);
cls = sd.getSerializedClass();
wObj = cls.newInstance();
value = new VIntWritable();
wEntry = new ByteBasedSortedMap.WritableEntry(wObj, value);
bldr = new StringBuilder();
}
use of org.apache.hadoop.io.VIntWritable in project SQLWindowing by hbutani.
the class PersistentByteBasedSortedMapTest method testKeyItr.
@Test
public void testKeyItr() 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<Writable> it = pm.keyIterator(wObj);
i = 0;
while (it.hasNext()) {
Writable we = it.next();
Assert.assertEquals(table[i], we.toString());
pm.getValue(we, value);
Assert.assertEquals(value.get(), i);
i++;
}
}
use of org.apache.hadoop.io.VIntWritable in project SQLWindowing by hbutani.
the class PersistentByteBasedSortedMapTest method testRandomPut.
@Test
public void testRandomPut() throws Exception {
int i = 0;
for (i = 0; i < table.length; i++) {
int j = (i + 13) % table.length;
bm.put(new Text(table[j]), new VIntWritable(j));
}
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);
}
}
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 DateWritable((Date) val).write(out);
return;
case DataType.TIMESTAMP:
new TimestampWritable((java.sql.Timestamp) val).write(out);
return;
default:
throw new IOException("Unexpected data type " + type + " found in stream.");
}
}
use of org.apache.hadoop.io.VIntWritable in project SQLWindowing by hbutani.
the class ByteBasedSortedMapTest method testRandomPut.
@Test
public void testRandomPut() throws Exception {
int i = 0;
for (i = 0; i < table.length; i++) {
int j = (i + 13) % table.length;
bm.put(new Text(table[j]), new VIntWritable(j));
}
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);
}
}
Aggregations