Skip to content

Commit

Permalink
handle python longs properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaas Bosteels authored and Klaas Bosteels committed Jan 15, 2009
1 parent e60bfed commit f16275c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/java/org/apache/hadoop/dumbo/CodeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.dumbo;

import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -68,6 +69,10 @@ public static String floatToCode(float f) {
public static String doubleToCode(double d) {
return numberToCode(d);
}

public static String bigIntToCode(BigInteger i) {
return numberToCode(i);
}

private static String numberToCode(Number n) {
return n.toString();
Expand All @@ -78,11 +83,11 @@ public static int codeToInt(String code) {
}

public static long codeToLong(String code) {
int lastIndex = code.length() - 1;
if (code.charAt(lastIndex) == 'L')
return Long.parseLong(code.substring(0, code.length()-1));
else
return Long.parseLong(code);
return Long.parseLong(code);
}

public static BigInteger codeToBigInteger(String code) {
return new BigInteger(code.substring(0, code.length()-1));
}

public static float codeToFloat(String code) {
Expand Down
4 changes: 2 additions & 2 deletions src/java/org/apache/hadoop/dumbo/CodeWritable.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void write(DataOutput out) throws IOException {
writeString(out, CodeUtils.codeToString(code));
} else if (type == CodeType.BOOLEAN) {
out.writeBoolean(CodeUtils.codeToBoolean(code));
} else if ((type == CodeType.INTEGER) || (type == CodeType.LONG)) {
} else if (type == CodeType.INTEGER) {
WritableUtils.writeVLong(out, CodeUtils.codeToLong(code));
} else if (type == CodeType.FLOAT) {
out.writeFloat(CodeUtils.codeToFloat(code));
Expand All @@ -82,7 +82,7 @@ public void readFields(DataInput in) throws IOException {
code = CodeUtils.stringToCode(readString(in));
} else if (type == CodeType.BOOLEAN.ordinal()) {
code = CodeUtils.booleanToCode(in.readBoolean());
} else if ((type == CodeType.INTEGER.ordinal()) || (type == CodeType.LONG.ordinal())) {
} else if (type == CodeType.INTEGER.ordinal()) {
code = CodeUtils.longToCode(WritableUtils.readVLong(in));
} else if (type == CodeType.FLOAT.ordinal()) {
code = new Float(in.readFloat()).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testBoolean() throws Exception {

public void testNumber() throws Exception {
testCode("1234");
testCode("1234L","1234");
testCode("1234L", false);
testCode("123.45");
}

Expand Down

0 comments on commit f16275c

Please sign in to comment.