Hadoop에 WritableComparable 클래스를 구현하는 클래스가 있습니다. 이 클래스는 short와 very long이라는 두 개의 문자열 변수를 가지고 있습니다. 나는이 변수들을 쓰려면 writeChars
을 사용하고 그것들을 읽으려면 readLine
을 사용한다. 그러나 나는 어떤 종류의 오류가있는 것처럼 보인다. Hadoop에서 이러한 긴 문자열을 직렬화하는 가장 좋은 방법은 무엇입니까?Hadoop에서 긴 문자열 직렬화
0
A
답변
0
여러분은 byteswritable을 사용하여 더욱 효율적으로 사용할 수 있다고 생각합니다. callId와 같이 BytesWritable 유형을 가진 아래의 맞춤 키를 확인하십시오.
당신은으로 호출 할 수 있습니다
CustomMRKey customKey을 = 새 - :
가에서 사용하려면
public class CustomMRKey implements WritableComparable<CustomMRKey> {
private BytesWritable callId;
private IntWritable mapperType;
/**
* @default constructor
*/
public CustomMRKey() {
set(new BytesWritable(), new IntWritable());
}
/**
* Constructor
*
* @param callId
* @param mapperType
*/
public CustomMRKey(BytesWritable callId, IntWritable mapperType) {
set(callId, mapperType);
}
/**
* sets the call id and mapper type
*
* @param callId
* @param mapperType
*/
public void set(BytesWritable callId, IntWritable mapperType) {
this.callId = callId;
this.mapperType = mapperType;
}
/**
* This method returns the callId
*
* @return callId
*/
public BytesWritable getCallId() {
return callId;
}
/**
* This method sets the callId given a callId
*
* @param callId
*/
public void setCallId(BytesWritable callId) {
this.callId = callId;
}
/**
* This method returns the mapper type
*
*
* @return
*/
public IntWritable getMapperType() {
return mapperType;
}
/**
* This method is set to store the mapper type
*
* @param mapperType
*/
public void setMapperType(IntWritable mapperType) {
this.mapperType = mapperType;
}
@Override
public void readFields(DataInput in) throws IOException {
callId.readFields(in);
mapperType.readFields(in);
}
@Override
public void write(DataOutput out) throws IOException {
callId.write(out);
mapperType.write(out);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof CustomMRCdrKey) {
CustomMRCdrKey key = (CustomMRCdrKey) obj;
return callId.equals(key.callId)
&& mapperType.equals(key.mapperType);
}
return false;
}
@Override
public int compareTo(CustomMRCdrKey key) {
int cmp = callId.compareTo(key.getCallId());
if (cmp != 0) {
return cmp;
}
return mapperType.compareTo(key.getMapperType());
}
은} 매퍼 코드는 다음과 같은 당신이 뭔가를 사용 BytesWritable 형태의 키를 생성 할 수 있다고 말한다 CustomMRKey (새 BytesWritable(), 새 IntWritable()); customKey.setCallId (makeKey (value, this.resultKey)); customKey.setMapperType (this.mapTypeIndicator);
다음makeKey 방법은 무엇인가 다음과 같다 : -이 도움이 될 수
public BytesWritable makeKey(Text value, BytesWritable key) throws IOException {
try {
ByteArrayOutputStream byteKey = new ByteArrayOutputStream(Constants.MR_DEFAULT_KEY_SIZE);
for (String field : keyFields) {
byte[] bytes = value.getString(field).getBytes();
byteKey.write(bytes,0,bytes.length);
}
if(key==null){
return new BytesWritable(byteKey.toByteArray());
}else{
key.set(byteKey.toByteArray(), 0, byteKey.size());
return key;
}
} catch (Exception ex) {
throw new IOException("Could not generate key", ex);
}
}
희망.
관련 문제
- 1. 긴 xml을 사용하는 XML 직렬화
- 2. hadoop에서
- 3. 긴 문자열 줄이기
- 4. VS 편집기의 긴 문자열
- 5. 속보 긴 SED 문자열
- 6. PlayFramework 설정 - 긴 문자열
- 7. 긴 문자열 작업
- 8. 분할 긴 문자열 WP7
- 9. 긴 텍스트 문자열 저장
- 10. 가장 긴 문자열
- 11. 긴 중복 문자열
- 12. 긴 문자열 깨기
- 13. 스칼라 긴 문자열 오류
- 14. HTML5 WebSocket을하고 긴 문자열
- 15. 면도기에 긴 문자열 정의
- 16. fslex의 Lua 긴 문자열
- 17. 긴 표현 문자열 처리
- 18. json_encode는 긴 문자열
- 19. 긴 문자열 오류 Atoi
- 20. Talend에서 긴 문자열 변환
- 21. JSON의 긴 문자열 값
- 22. C# 문자열 배열 직렬화 역 직렬화 문제
- 23. JSON 문자열 직렬화 (Newtonsoft.JSON)
- 24. 직렬화 문자열 속성은
- 25. json 문자열 비 직렬화
- 26. 문자열 직렬화 - 가능합니까?
- 27. Node.js 버퍼 문자열 직렬화
- 28. json에 문자열 역 직렬화
- 29. 역 직렬화 문자열 JSON
- 30. 백 슬래시로 문자열 직렬화
''readline''이 각 끝나는 시점을 인식 할 수 있도록 각 문자열 변수의 끝 부분에 줄 종결자를 추가해야합니까? –