List of usage examples for org.apache.hadoop.io SortedMapWritable size
@Override public int size()
From source file:com.jfolson.hive.serde.RTypedBytesWritableOutput.java
License:Apache License
public void writeSortedMap(SortedMapWritable smw) throws IOException { out.writeMapHeader(smw.size()); for (Map.Entry<WritableComparable, Writable> entry : smw.entrySet()) { write(entry.getKey());/*from w ww . java 2s . c o m*/ write(entry.getValue()); } }
From source file:org.huahinframework.core.lib.partition.SimpleSortComparator.java
License:Apache License
/** * {@inheritDoc}//from w w w .j ava 2s . co m */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public int compare(WritableComparable a, WritableComparable b) { if (a instanceof Key && b instanceof Key) { Comparable oneIdentifier = Key.class.cast(a).identifier(); Comparable otherIdentifier = Key.class.cast(b).identifier(); int identifier = oneIdentifier.compareTo(otherIdentifier); if (identifier != 0) { return identifier; } SortedMapWritable oneSort = Key.class.cast(a).sort(); SortedMapWritable otherSort = Key.class.cast(b).sort(); if (oneSort.size() != otherSort.size()) { return -1; } for (Entry<WritableComparable, Writable> entry : oneSort.entrySet()) { IntWritable priority = ((IntWritable) entry.getKey()); KeyDetail oneKeyDetail = (KeyDetail) entry.getValue(); KeyDetail otherKeyDetail = (KeyDetail) otherSort.get(priority); WritableComparable oneKey = oneKeyDetail.getKey(); WritableComparable otherKey = otherKeyDetail.getKey(); if (ObjectUtil.typeCompareTo(oneKeyDetail.getKey(), otherKeyDetail.getKey()) != 0) { return -1; } int cmpare = oneKey.compareTo(otherKey); if (cmpare != 0) { if (oneKeyDetail.getSort() == Record.SORT_LOWER) { return cmpare; } else { return -cmpare; } } } return 0; } return super.compare(a, b); }