gpt4 book ai didi

Hadoop 自定义分区程序问题

转载 作者:可可西里 更新时间:2023-11-01 16:18:52 26 4
gpt4 key购买 nike

我遇到了一个问题,自定义中间键没有出现在我期望的分区中,这是基于自定义分区程序的“getPartition”方法的输出。我可以在我的映射器日志文件中看到分区器生成了预期的分区号,但有时具有公共(public)分区号的键不会在同一个缩减器中结束。

具有共同“getPartition”输出的键如何在不同的 reducer 中结束?

在所有“getPartition”调用之后,我在映射器日志文件中注意到对自定义中间键“hashCode”和“compareTo”方法进行了多次调用。映射器只是在分区排序中进行,还是这可能是问题的一部分?

我附上了自定义中间键和分区程序的代码。注意:我确切知道 1/2 的键将“useBothGUIDFlag”设置为 true,1/2 的键将此设置为 false(这就是为什么我将这些键划分为分区空间的两半)。我也知道键似乎没有跨越到分区的另一半​​(即,“useBothGUIDFlag”键不会在“!useBothGUIDFlag”分区中结束,反之亦然),而是它们在它们的一半内混合分区。

public class IntermediaryKey implements WritableComparable<IntermediaryKey> {

public String guid1;
public String guid2;
public boolean useBothGUIDFlag;

@Override
public int compareTo(IntermediaryKey other) {
if(useBothGUIDFlag)
{
if(other.useBothGUIDFlag)
{
return this.hashCode() - other.hashCode();
}else{
return 1;
}
}else{
if(!other.useBothGUIDFlag)
{
return guid2.compareTo(other.guid2);
}else{
return -1;
}
}
}

@Override
public int hashCode()
{
if(useBothGUIDFlag)
{
if(guid1.compareTo(guid2) > 0)
{
return (guid2+guid1).hashCode();
}else{
return (guid1+guid2).hashCode();
}
}else{
return guid2.hashCode();
}
}

@Override
public boolean equals(Object otherKey)
{
if(otherKey instanceof IntermediaryKey)
{
return this.compareTo((IntermediaryKey)otherKey) == 0;
}
return false;
}
}

public static class KeyPartitioner extends Partitioner<IntermediaryKey, PathValue>
{
@Override
public int getPartition(IntermediaryKey key, PathValue value, int numReduceTasks) {
int bothGUIDReducers = numReduceTasks/2;
if(bothGUIDReducers == 0)
{
return 0;
}

int keyHashCode = Math.abs(key.hashCode());
if(key.useBothGUIDFlag)
{
return keyHashCode % bothGUIDReducers;
}else{
return (bothGUIDReducers + (keyHashCode % (numReduceTasks-bothGUIDReducers)));
}
}
}

最佳答案

问题最终出现在自定义 key (IntermediaryKey) 的序列化/反序列化中。 “useBothGUIDFlag”变量被读入与它应该读入的相反。

在 reducer 中获取“mapred.task.partition”属性值有助于注意到发生了这种交换。具有相反“useBothGUIDFlag”值的键似乎会转到正确的 reducer 。

关于Hadoop 自定义分区程序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13076331/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com