public VectorUDFMapIndexDecimalScalar(int mapColumnNum, HiveDecimal key, int outputColumnNum) { super(mapColumnNum, outputColumnNum); this.key = key; doubleKey = key.doubleValue(); }
@Override public void addToEstimator(HiveDecimal decimal) { addDouble(decimal.doubleValue()); }
public void updateValueNoCheck(HiveDecimalWritable value, short scale) { double dval = value.getHiveDecimal().doubleValue(); this.sum += dval; this.count += 1; double t = this.count*dval - this.sum; this.variance += (t*t) / ((double)this.count*(this.count-1)); }
public void updateValueNoCheck(HiveDecimalWritable value, short scale) { double dval = value.getHiveDecimal().doubleValue(); this.sum += dval; this.count += 1; double t = this.count*dval - this.sum; this.variance += (t*t) / ((double)this.count*(this.count-1)); }
private static Object coercePrimitiveObject(final PrimitiveObjectInspector inspector, final Object object) { if (object instanceof HiveDecimalWritable) { // inspector on HiveDecimal rounds off to integer for some reason. return ((HiveDecimalWritable) object).getHiveDecimal().doubleValue(); } else if (object instanceof DateWritable) { return object.toString(); } else { return inspector.getPrimitiveJavaObject(object); } }
public void updateValueNoCheck(HiveDecimalWritable value, short scale) { double dval = value.getHiveDecimal().doubleValue(); this.sum += dval; this.count += 1; double t = this.count*dval - this.sum; this.variance += (t*t) / ((double)this.count*(this.count-1)); }
public void updateValueNoCheck(HiveDecimalWritable value, short scale) { double dval = value.getHiveDecimal().doubleValue(); this.sum += dval; this.count += 1; double t = this.count*dval - this.sum; this.variance += (t*t) / ((double)this.count*(this.count-1)); }
public void updateValueWithCheckAndInit(HiveDecimalWritable value, short scale) { if (this.isNull) { this.init(); } double dval = value.getHiveDecimal().doubleValue(); this.sum += dval; this.count += 1; if(this.count > 1) { double t = this.count*dval - this.sum; this.variance += (t*t) / ((double)this.count*(this.count-1)); } }
public void updateValueWithCheckAndInit(HiveDecimalWritable value, short scale) { if (this.isNull) { this.init(); } double dval = value.getHiveDecimal().doubleValue(); this.sum += dval; this.count += 1; if(this.count > 1) { double t = this.count*dval - this.sum; this.variance += (t*t) / ((double)this.count*(this.count-1)); } }
public void updateValueWithCheckAndInit(HiveDecimalWritable value, short scale) { if (this.isNull) { this.init(); } double dval = value.getHiveDecimal().doubleValue(); this.sum += dval; this.count += 1; if(this.count > 1) { double t = this.count*dval - this.sum; this.variance += (t*t) / ((double)this.count*(this.count-1)); } }
public void updateValueWithCheckAndInit(HiveDecimalWritable value, short scale) { if (this.isNull) { this.init(); } double dval = value.getHiveDecimal().doubleValue(); this.sum += dval; this.count += 1; if(this.count > 1) { double t = this.count*dval - this.sum; this.variance += (t*t) / ((double)this.count*(this.count-1)); } }
private Double castConstantToDouble(Object scalar, TypeInfo type) throws HiveException { if (null == scalar) { return null; } PrimitiveTypeInfo ptinfo = (PrimitiveTypeInfo) type; PrimitiveCategory primitiveCategory = ptinfo.getPrimitiveCategory(); switch (primitiveCategory) { case FLOAT: case DOUBLE: case BYTE: case SHORT: case INT: case LONG: return ((Number) scalar).doubleValue(); case STRING: return Double.valueOf((String) scalar); case CHAR: return Double.valueOf(((HiveChar) scalar).getStrippedValue()); case VARCHAR: return Double.valueOf(((HiveVarchar) scalar).getValue()); case DECIMAL: HiveDecimal decimalVal = (HiveDecimal) scalar; return decimalVal.doubleValue(); default: throw new HiveException("Unsupported primitive category " + primitiveCategory + " for cast to DOUBLE"); } }
if (lit instanceof HiveDecimal) { dbl = ((HiveDecimal) lit).doubleValue(); } else { dbl = ((Number) lit);
private Double castConstantToDouble(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).doubleValue(); case DECIMAL: HiveDecimal decimalVal = (HiveDecimal) scalar; return decimalVal.doubleValue(); default: throw new HiveException("Unsupported type "+typename+" for cast to Double"); } }
obj = ((HiveDecimal)obj).doubleValue(); } else if (obj instanceof BigDecimal) { obj = ((BigDecimal)obj).doubleValue();
private void runDecimal(double v, IntWritable scale, Double expV, GenericUDF udf) throws HiveException { HiveDecimal hd = HiveDecimal.create(BigDecimal.valueOf(v)); DeferredObject valueObj0 = new DeferredJavaObject(new HiveDecimalWritable(hd)); DeferredObject valueObj1 = new DeferredJavaObject(scale); DeferredObject[] args = { valueObj0, valueObj1 }; HiveDecimalWritable output = (HiveDecimalWritable) udf.evaluate(args); Assert.assertEquals("bround() test ", expV.doubleValue(), output.getHiveDecimal().doubleValue(), 0.00001); } }
case DECIMAL: result = ((HiveDecimalObjectInspector) oi) .getPrimitiveJavaObject(o).doubleValue(); break; case DATE: // unsupported conversion
public static DecimalColumnVector generateDecimalColumnVector(DecimalTypeInfo typeInfo, boolean nulls, boolean repeating, int size, Random rand) { DecimalColumnVector dcv = new DecimalColumnVector(size, typeInfo.precision(), typeInfo.scale()); dcv.noNulls = !nulls; dcv.isRepeating = repeating; HiveDecimalWritable repeatingValue = new HiveDecimalWritable(); do{ repeatingValue.set(HiveDecimal.create(((Double) rand.nextDouble()).toString()).setScale((short)typeInfo.scale(), HiveDecimal.ROUND_HALF_UP)); }while(repeatingValue.getHiveDecimal().doubleValue() == 0); int nullFrequency = generateNullFrequency(rand); for(int i = 0; i < size; i++) { if(nulls && (repeating || i % nullFrequency == 0)) { dcv.isNull[i] = true; dcv.vector[i] = null; }else { dcv.isNull[i] = false; if (repeating) { dcv.vector[i].set(repeatingValue); } else { dcv.vector[i].set(HiveDecimal.create(((Double) rand.nextDouble()).toString()).setScale((short) typeInfo.scale(), HiveDecimal.ROUND_HALF_UP)); } if(dcv.vector[i].getHiveDecimal().doubleValue() == 0) { i--; } } } return dcv; }
assertTrue(sameFirstKBytes(alphaBytes, bcv.vector[0], alphaBytes.length)); assertTrue(25.8 == dv.vector[0].getHiveDecimal().doubleValue()); assertTrue(25.8 == dv.vector[0].getHiveDecimal().doubleValue());
.doubleValue()); .doubleValue());