/// <summary>Get an entry from output generated by this class.</summary> /// <exception cref="System.IO.IOException"/> public static Writable GetEntry <K, V>(MapFile.Reader[] readers, Partitioner <K, V> partitioner, K key, V value) where K : WritableComparable where V : Writable { int part = partitioner.GetPartition(key, value, readers.Length); return(readers[part].Get(key, value)); }
/// <exception cref="System.IO.IOException"/> public virtual void Map(WritableComparable key, Writable value, OutputCollector <IntWritable , SortValidator.RecordStatsChecker.RecordStatsWritable> output, Reporter reporter ) { // Set up rawKey and rawValue on the first call to 'map' if (recordId == -1) { rawKey = CreateRaw(key.GetType()); rawValue = CreateRaw(value.GetType()); } ++recordId; if (this.key == sortOutput) { // Check if keys are 'sorted' if this // record is from sort's output if (prevKey == null) { prevKey = key; keyClass = prevKey.GetType(); } else { // Sanity check if (keyClass != key.GetType()) { throw new IOException("Type mismatch in key: expected " + keyClass.FullName + ", received " + key.GetType().FullName); } // Check if they were sorted correctly if (prevKey.CompareTo(key) > 0) { throw new IOException("The 'map-reduce' framework wrongly" + " classifed (" + prevKey + ") > (" + key + ") " + "for record# " + recordId); } prevKey = key; } // Check if the sorted output is 'partitioned' right int keyPartition = partitioner.GetPartition(key, value, noSortReducers); if (partition != keyPartition) { throw new IOException("Partitions do not match for record# " + recordId + " ! - '" + partition + "' v/s '" + keyPartition + "'"); } } // Construct the record-stats and output (this.key, record-stats) byte[] keyBytes = rawKey.GetRawBytes(key); int keyBytesLen = rawKey.GetRawBytesLength(key); byte[] valueBytes = rawValue.GetRawBytes(value); int valueBytesLen = rawValue.GetRawBytesLength(value); int keyValueChecksum = (WritableComparator.HashBytes(keyBytes, keyBytesLen) ^ WritableComparator .HashBytes(valueBytes, valueBytesLen)); output.Collect(this.key, new SortValidator.RecordStatsChecker.RecordStatsWritable ((keyBytesLen + valueBytesLen), 1, keyValueChecksum)); }
/// <summary>If a partition result was set manually, return it.</summary> /// <remarks> /// If a partition result was set manually, return it. Otherwise, we call /// the Java partitioner. /// </remarks> /// <param name="key">the key to partition</param> /// <param name="value">the value to partition</param> /// <param name="numPartitions">the number of reduces</param> public virtual int GetPartition(K key, V value, int numPartitions) { int result = cache.Get(); if (result == null) { return(part.GetPartition(key, value, numPartitions)); } else { return(result); } }
public int GetPartition(Vector3 worldPos) { return(partitioner.GetPartition(worldPos)); }