throw new ArithmeticException("Overflow"); return dec.longValue();
throw new ArithmeticException("Overflow"); return dec.longValue();
return decimalVal.longValue(); default: throw new HiveException("Unsupported primitive category " + primitiveCategory + " for cast to LONG");
return hd.longValue();
return decimalVal.longValue(); default: throw new HiveException("Unsupported type "+typename+" for cast to Long");
throw new NumberFormatException(); result = dec.longValue();
@Test public void testToLong() { Decimal128 d = new Decimal128("1.25", (short) 2); assertEquals(1, d.longValue()); d.update("4294967295", (short) 0); // 2^32-1 assertEquals(4294967295L, d.longValue()); d.update("4294967296", (short) 0); // 2^32 -- needs 2 32 bit words assertEquals(4294967296L, d.longValue()); d.update("-4294967295", (short) 0); // -(2^32-1) assertEquals(-4294967295L, d.longValue()); d.update("-4294967296", (short) 0); // -(2^32) assertEquals(-4294967296L, d.longValue()); d.update("4294967295.01", (short) 2); // 2^32-1 + .01 assertEquals(4294967295L, d.longValue()); d.update("4294967296.01", (short) 2); // 2^32 + .01 assertEquals(4294967296L, d.longValue()); // Compare long value with HiveDecimal#longValue d.update(37.678, (short)5); HiveDecimal hd = HiveDecimal.create(BigDecimal.valueOf(37.678)); assertEquals(hd.longValue(), d.longValue()); }
@Override protected void func(LongColumnVector outV, DecimalColumnVector inV, int i) { outV.vector[i] = inV.vector[i].getHiveDecimal().longValue(); } }
public LongWritable evaluate(HiveDecimalWritable i) { if (i == null) { return null; } else { longWritable.set(i.getHiveDecimal().longValue()); return longWritable; } }
@Override protected void func(LongColumnVector outV, DecimalColumnVector inV, int i) { HiveDecimal result = inV.vector[i].getHiveDecimal().multiply(tenE9); if (result == null) { outV.noNulls = false; outV.isNull[i] = true; } else { outV.vector[i] = result.longValue(); } } }
private Long castConstantToLong(Object scalar, TypeInfo type) throws HiveException { if (null == scalar) { return null; } PrimitiveTypeInfo ptinfo = (PrimitiveTypeInfo) type; String typename = type.getTypeName(); switch (ptinfo.getPrimitiveCategory()) { case FLOAT: case DOUBLE: case BYTE: case SHORT: case INT: case LONG: return ((Number) scalar).longValue(); case DECIMAL: HiveDecimal decimalVal = (HiveDecimal) scalar; return decimalVal.longValue(); default: throw new HiveException("Unsupported type "+typename+" for cast to Long"); } }
@Override public void setConvertVectorElement(int elementNum) throws IOException { HiveDecimal decimalValue = decimalColVector.vector[elementNum].getHiveDecimal(); if (decimalValue.compareTo(DECIMAL_MAX_LONG) > 0 || decimalValue.compareTo(DECIMAL_MIN_LONG) < 0) { longColVector.isNull[elementNum] = true; longColVector.noNulls = false; } else { downCastAnyInteger(longColVector, elementNum, decimalValue.longValue(), readerType); } }
return ((HiveDecimal) obj).longValue(); } else if (obj instanceof String) { return Long.valueOf(obj.toString());
return ((HiveDecimal) obj).longValue(); } else if (obj instanceof String) { return Long.valueOf(obj.toString());
return hd.longValue();
throw new NumberFormatException(); result = dec.longValue();
case DECIMAL: result = ((HiveDecimalObjectInspector) oi) .getPrimitiveJavaObject(o).longValue(); break; case DATE: // unsupported conversion
case DECIMAL: result = ((HiveDecimalObjectInspector) oi) .getPrimitiveJavaObject(o).longValue(); break; case DATE: // unsupported conversion
case DECIMAL: result = ((HiveDecimalObjectInspector) oi) .getPrimitiveJavaObject(o).longValue(); break; case DATE: // unsupported conversion