@Override protected void func(BytesColumnVector outV, DecimalColumnVector inV, int i) { HiveDecimalWritable decWritable = inV.vector[i]; final int byteIndex = decWritable.toFormatBytes(inV.scale, scratchBuffer); assign(outV, i, scratchBuffer, byteIndex, HiveDecimal.SCRATCH_BUFFER_LEN_TO_BYTES - byteIndex); } }
@Test public void testCastDecimalToString() throws HiveException { VectorizedRowBatch b = getBatchDecimalString(); VectorExpression expr = new CastDecimalToString(0, 1); expr.setInputTypeInfos(new TypeInfo[] {TypeInfoFactory.decimalTypeInfo}); expr.transientInit(); expr.evaluate(b); BytesColumnVector r = (BytesColumnVector) b.cols[1]; // As of HIVE-8745, these decimal values should be trimmed of trailing zeros. byte[] v = toBytes("1.10"); assertTrue(((Integer) v.length).toString() + " " + r.length[0], v.length == r.length[0]); Assert.assertEquals(0, StringExpr.compare(v, 0, v.length, r.vector[0], r.start[0], r.length[0])); v = toBytes("-2.20"); Assert.assertEquals(0, StringExpr.compare(v, 0, v.length, r.vector[1], r.start[1], r.length[1])); v = toBytes("9999999999999999.00"); Assert.assertEquals(0, StringExpr.compare(v, 0, v.length, r.vector[2], r.start[2], r.length[2])); }
@Override protected void func(BytesColumnVector outV, DecimalColumnVector inV, int i) { HiveDecimalWritable decWritable = inV.vector[i]; final int byteIndex = decWritable.toBytes(scratchBuffer); assign(outV, i, scratchBuffer, byteIndex, HiveDecimal.SCRATCH_BUFFER_LEN_TO_BYTES - byteIndex); } }
@Override protected void func(BytesColumnVector outV, DecimalColumnVector inV, int i) { String s = inV.vector[i].getHiveDecimal().toString(); byte[] b = null; try { b = s.getBytes("UTF-8"); } catch (Exception e) { // This should never happen. If it does, there is a bug. throw new RuntimeException("Internal error: unable to convert decimal to string", e); } assign(outV, i, b, b.length); } }