本文整理汇总了Java中org.apache.hadoop.hive.serde2.io.HiveDecimalWritable类的典型用法代码示例。如果您正苦于以下问题:Java HiveDecimalWritable类的具体用法?Java HiveDecimalWritable怎么用?Java HiveDecimalWritable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HiveDecimalWritable类属于org.apache.hadoop.hive.serde2.io包,在下文中一共展示了HiveDecimalWritable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrimitiveWritableObject
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Override
public HiveDecimalWritable getPrimitiveWritableObject(Object o) {
<#if mode == "Optional">
if (o == null) {
return null;
}
final NullableDecimal38SparseHolder h = (NullableDecimal38SparseHolder) o;
<#else>
final Decimal38SparseHolder h = (Decimal38SparseHolder) o;
</#if>
return new HiveDecimalWritable(
HiveDecimal.create(DecimalUtility.getBigDecimalFromSparse(h.buffer, h.start, h.nDecimalDigits, h.scale)));
}
示例2: getPrimitiveWritableObject
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Override
public HiveDecimalWritable getPrimitiveWritableObject(Object o) {
<#if mode == "Optional">
if (o == null) {
return null;
}
final NullableDecimalHolder h = (NullableDecimalHolder) o;
<#else>
final DecimalHolder h = (DecimalHolder) o;
</#if>
return new HiveDecimalWritable(
HiveDecimal.create(DecimalUtility.getBigDecimalFromArrowBuf(h.buffer, h.start, h.scale)));
}
示例3: toComparable
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
static Comparable<?> toComparable(PrimitiveCategory category, Object literal) {
String stringLiteral;
switch (category) {
case STRING:
return new Text((String) literal);
case BOOLEAN:
return new BooleanWritable((Boolean) literal);
case BYTE:
return new ByteWritable(((Long) literal).byteValue());
case SHORT:
return new ShortWritable(((Long) literal).shortValue());
case INT:
return new IntWritable(((Long) literal).intValue());
case LONG:
return new LongWritable((Long) literal);
case FLOAT:
return new FloatWritable(((Double) literal).floatValue());
case DOUBLE:
return new DoubleWritable((Double) literal);
case TIMESTAMP:
return new TimestampWritable((Timestamp) literal);
case DATE:
return (DateWritable) literal;
case CHAR:
stringLiteral = (String) literal;
return new HiveCharWritable(new HiveChar(stringLiteral, stringLiteral.length()));
case VARCHAR:
stringLiteral = (String) literal;
return new HiveVarcharWritable(new HiveVarchar(stringLiteral, stringLiteral.length()));
case DECIMAL:
return new HiveDecimalWritable(HiveDecimal.create((BigDecimal) literal));
default:
throw new IllegalArgumentException("Unsupported category: " + category);
}
}
示例4: toWritableObjectInternal
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Override
protected Object toWritableObjectInternal(Object value) throws UnexpectedTypeException {
if (value instanceof String) {
value = HiveDecimal.create((String) value);
} else if (value instanceof BigDecimal) {
value = HiveDecimal.create((BigDecimal) value);
}
return new HiveDecimalWritable((HiveDecimal) value);
}
示例5: decimalWritable
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Test
public void decimalWritable() throws UnexpectedTypeException {
Converter converter = getConverter(TypeInfoFactory.getDecimalTypeInfo(2, 1));
HiveDecimal hiveDecimal = HiveDecimal.create("2.1");
assertThat(converter.toWritableObject("2.1"), is((Object) new HiveDecimalWritable(hiveDecimal)));
assertThat(converter.toWritableObject(new BigDecimal("2.1")), is((Object) new HiveDecimalWritable(hiveDecimal)));
}
示例6: compareDecimalcolumn
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
static void compareDecimalcolumn(ColumnVector oneDecimalColumn, boolean[] isNull,
long currentBatchRow, Vec h2oFrame, Long startRowIndex) {
HiveDecimalWritable[] oneColumn= ((DecimalColumnVector) oneDecimalColumn).vector;
long frameRowIndex = startRowIndex;
for (int rowIndex = 0; rowIndex < currentBatchRow; rowIndex++) {
if (isNull[rowIndex])
assertEquals("Na is found: ", true, h2oFrame.isNA(frameRowIndex));
else
assertEquals("Decimal elements should equal: ", Double.parseDouble(oneColumn[rowIndex].toString()),
h2oFrame.at(frameRowIndex), EPSILON);
frameRowIndex++;
}
}
示例7: getPrimitiveWritableObject
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Override
public HiveDecimalWritable getPrimitiveWritableObject(Object o) {
if (o instanceof BigDecimal) {
return o == null ? null : new HiveDecimalWritable(HiveDecimal.create((BigDecimal)o));
} else { // BigInteger
return o == null ? null : new HiveDecimalWritable(HiveDecimal.create((BigInteger)o));
}
}
示例8: testDecimal
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Test
public void testDecimal() {
assertEquals("\"1\"", hiveTypeToJson(new MyHiveType(new HiveDecimalWritable(HiveDecimal.create(BigDecimal.ONE)),
decimalTypeInfo)));
}
示例9: readBigDecimal
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
private static BigDecimal readBigDecimal(HiveDecimalWritable hiveDecimalWritable) {
HiveDecimal hiveDecimal = hiveDecimalWritable.getHiveDecimal();
return hiveDecimal.bigDecimalValue();
}
示例10: castLiteral
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
Object castLiteral(Serializable literal) {
switch (literalType) {
case LONG:
if (literal instanceof Byte) {
return new Long((Byte) literal);
} else if (literal instanceof Short) {
return new Long((Short) literal);
} else if (literal instanceof Integer) {
return new Long((Integer) literal);
} else if (literal instanceof Long) {
return literal;
} else {
throw new IllegalArgumentException("A predicate on a LONG column requires an integer " +
"literal, i.e., Byte, Short, Integer, or Long.");
}
case FLOAT:
if (literal instanceof Float) {
return new Double((Float) literal);
} else if (literal instanceof Double) {
return literal;
} else if (literal instanceof BigDecimal) {
return ((BigDecimal) literal).doubleValue();
} else {
throw new IllegalArgumentException("A predicate on a FLOAT column requires a floating " +
"literal, i.e., Float or Double.");
}
case STRING:
if (literal instanceof String) {
return literal;
} else {
throw new IllegalArgumentException("A predicate on a STRING column requires a floating " +
"literal, i.e., Float or Double.");
}
case BOOLEAN:
if (literal instanceof Boolean) {
return literal;
} else {
throw new IllegalArgumentException("A predicate on a BOOLEAN column requires a Boolean literal.");
}
case DATE:
if (literal instanceof Date) {
return literal;
} else {
throw new IllegalArgumentException("A predicate on a DATE column requires a java.sql.Date literal.");
}
case TIMESTAMP:
if (literal instanceof Timestamp) {
return literal;
} else {
throw new IllegalArgumentException("A predicate on a TIMESTAMP column requires a java.sql.Timestamp literal.");
}
case DECIMAL:
if (literal instanceof BigDecimal) {
return new HiveDecimalWritable(HiveDecimal.create((BigDecimal) literal));
} else {
throw new IllegalArgumentException("A predicate on a DECIMAL column requires a BigDecimal literal.");
}
default:
throw new IllegalArgumentException("Unknown literal type " + literalType);
}
}
示例11: toWritableObjectInternal
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Override
protected Object toWritableObjectInternal(Object value) throws UnexpectedTypeException {
return new HiveDecimalWritable((HiveDecimal) value);
}
示例12: toJavaObjectInternal
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Override
protected Object toJavaObjectInternal(Object value) throws UnexpectedTypeException {
return ((HiveDecimalWritable) value).getHiveDecimal();
}
示例13: decimalJava
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Test
public void decimalJava() throws UnexpectedTypeException {
Converter converter = getConverter(TypeInfoFactory.getDecimalTypeInfo(2, 1));
HiveDecimal hiveDecimal = HiveDecimal.create("2.1");
assertThat(converter.toJavaObject(new HiveDecimalWritable(hiveDecimal)), is((Object) hiveDecimal));
}
示例14: decimalWritable
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@Test
public void decimalWritable() throws UnexpectedTypeException {
Converter converter = getConverter(TypeInfoFactory.getDecimalTypeInfo(2, 1));
HiveDecimal hiveDecimal = HiveDecimal.create("2.1");
assertThat(converter.toWritableObject(hiveDecimal), is((Object) new HiveDecimalWritable(hiveDecimal)));
}
示例15: decimalTypical
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void decimalTypical() {
assertThat(toComparable(DECIMAL, new BigDecimal("0.0")),
is((Comparable) new HiveDecimalWritable(HiveDecimal.create(new BigDecimal("0.0")))));
}