use of java.math.BigDecimal in project hadoop by apache.
the class TestTextSplitter method testStringConvertEmpty.
@Test
public void testStringConvertEmpty() {
TextSplitter splitter = new TextSplitter();
BigDecimal emptyBigDec = splitter.stringToBigDecimal("");
assertEquals(BigDecimal.ZERO, emptyBigDec);
}
use of java.math.BigDecimal in project hadoop by apache.
the class TextSplitter method stringToBigDecimal.
/**
* Return a BigDecimal representation of string 'str' suitable for use
* in a numerically-sorting order.
*/
BigDecimal stringToBigDecimal(String str) {
BigDecimal result = BigDecimal.ZERO;
// start with 1/65536 to compute the first digit.
BigDecimal curPlace = ONE_PLACE;
int len = Math.min(str.length(), MAX_CHARS);
for (int i = 0; i < len; i++) {
int codePoint = str.codePointAt(i);
result = result.add(tryDivide(new BigDecimal(codePoint), curPlace));
// advance to the next less significant place. e.g., 1/(65536^2) for the second char.
curPlace = curPlace.multiply(ONE_PLACE);
}
return result;
}
use of java.math.BigDecimal in project hadoop by apache.
the class TextSplitter method split.
List<String> split(int numSplits, String minString, String maxString, String commonPrefix) throws SQLException {
BigDecimal minVal = stringToBigDecimal(minString);
BigDecimal maxVal = stringToBigDecimal(maxString);
List<BigDecimal> splitPoints = split(new BigDecimal(numSplits), minVal, maxVal);
List<String> splitStrings = new ArrayList<String>();
// Convert the BigDecimal splitPoints into their string representations.
for (BigDecimal bd : splitPoints) {
splitStrings.add(commonPrefix + bigDecimalToString(bd));
}
// in the array.
if (splitStrings.size() == 0 || !splitStrings.get(0).equals(commonPrefix + minString)) {
splitStrings.add(0, commonPrefix + minString);
}
if (splitStrings.size() == 1 || !splitStrings.get(splitStrings.size() - 1).equals(commonPrefix + maxString)) {
splitStrings.add(commonPrefix + maxString);
}
return splitStrings;
}
use of java.math.BigDecimal in project hbase by apache.
the class PerformanceEvaluation method calculateMbps.
/**
* Compute a throughput rate in MB/s.
* @param rows Number of records consumed.
* @param timeMs Time taken in milliseconds.
* @return String value with label, ie '123.76 MB/s'
*/
private static String calculateMbps(int rows, long timeMs, final int valueSize, int columns) {
BigDecimal rowSize = BigDecimal.valueOf(ROW_LENGTH + ((valueSize + FAMILY_NAME.length + COLUMN_ZERO.length) * columns));
BigDecimal mbps = BigDecimal.valueOf(rows).multiply(rowSize, CXT).divide(BigDecimal.valueOf(timeMs), CXT).multiply(MS_PER_SEC, CXT).divide(BYTES_PER_MB, CXT);
return FMT.format(mbps) + " MB/s";
}
use of java.math.BigDecimal in project hbase by apache.
the class TestOrderedBytes method testEncodedValueCheck.
/**
* Test encoded value check
*/
@Test
public void testEncodedValueCheck() {
BigDecimal longMax = BigDecimal.valueOf(Long.MAX_VALUE);
double negInf = Double.NEGATIVE_INFINITY;
BigDecimal negLarge = longMax.multiply(longMax).negate();
BigDecimal negMed = new BigDecimal("-10.0");
BigDecimal negSmall = new BigDecimal("-0.0010");
long zero = 0l;
BigDecimal posSmall = negSmall.negate();
BigDecimal posMed = negMed.negate();
BigDecimal posLarge = negLarge.negate();
double posInf = Double.POSITIVE_INFINITY;
double nan = Double.NaN;
byte int8 = 100;
short int16 = 100;
int int32 = 100;
long int64 = 100l;
float float32 = 100.0f;
double float64 = 100.0d;
String text = "hello world.";
byte[] blobVar = Bytes.toBytes("foo");
int cnt = 0;
PositionedByteRange buff = new SimplePositionedMutableByteRange(1024);
for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
int o;
o = OrderedBytes.encodeNull(buff, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, negInf, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, negLarge, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, negMed, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, negSmall, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, zero, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, posSmall, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, posMed, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, posLarge, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, posInf, ord);
cnt++;
o = OrderedBytes.encodeNumeric(buff, nan, ord);
cnt++;
o = OrderedBytes.encodeInt8(buff, int8, ord);
cnt++;
o = OrderedBytes.encodeInt16(buff, int16, ord);
cnt++;
o = OrderedBytes.encodeInt32(buff, int32, ord);
cnt++;
o = OrderedBytes.encodeInt64(buff, int64, ord);
cnt++;
o = OrderedBytes.encodeFloat32(buff, float32, ord);
cnt++;
o = OrderedBytes.encodeFloat64(buff, float64, ord);
cnt++;
o = OrderedBytes.encodeString(buff, text, ord);
cnt++;
o = OrderedBytes.encodeBlobVar(buff, blobVar, ord);
cnt++;
}
buff.setPosition(0);
assertEquals(OrderedBytes.length(buff), cnt);
for (int i = 0; i < cnt; i++) {
assertEquals(OrderedBytes.isEncodedValue(buff), true);
OrderedBytes.skip(buff);
}
}
Aggregations