Search in sources :

Example 61 with HiveDecimal

use of org.apache.hadoop.hive.common.type.HiveDecimal in project hive by apache.

the class TestDecimalUtil method testCeiling.

@Test
public void testCeiling() {
    DecimalColumnVector dcv = new DecimalColumnVector(4, 20, 13);
    HiveDecimal d1 = HiveDecimal.create("19.56778");
    HiveDecimal expected1 = HiveDecimal.create("20");
    DecimalUtil.ceiling(0, d1, dcv);
    Assert.assertEquals(0, expected1.compareTo(dcv.vector[0].getHiveDecimal()));
    // As of HIVE-8745, these decimal values should be trimmed of trailing zeros.
    HiveDecimal d2 = HiveDecimal.create("23.00000");
    Assert.assertEquals(0, d2.scale());
    HiveDecimal expected2 = HiveDecimal.create("23");
    DecimalUtil.ceiling(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d3 = HiveDecimal.create("-25.34567");
    HiveDecimal expected3 = HiveDecimal.create("-25");
    DecimalUtil.ceiling(0, d3, dcv);
    Assert.assertEquals(0, expected3.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d4 = HiveDecimal.create("-17.00000");
    Assert.assertEquals(0, d4.scale());
    HiveDecimal expected4 = HiveDecimal.create("-17");
    DecimalUtil.ceiling(0, d4, dcv);
    Assert.assertEquals(0, expected4.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d5 = HiveDecimal.create("-0.30000");
    Assert.assertEquals(1, d5.scale());
    HiveDecimal expected5 = HiveDecimal.create("0");
    DecimalUtil.ceiling(0, d5, dcv);
    Assert.assertEquals(0, expected5.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d6 = HiveDecimal.create("0.30000");
    Assert.assertEquals(1, d6.scale());
    HiveDecimal expected6 = HiveDecimal.create("1");
    DecimalUtil.ceiling(0, d6, dcv);
    Assert.assertEquals(0, expected6.compareTo(dcv.vector[0].getHiveDecimal()));
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 62 with HiveDecimal

use of org.apache.hadoop.hive.common.type.HiveDecimal in project hive by apache.

the class TestDecimalUtil method testRound.

@Test
public void testRound() {
    DecimalColumnVector dcv = new DecimalColumnVector(4, 20, 0);
    HiveDecimal d1 = HiveDecimal.create("19.56778");
    HiveDecimal expected1 = HiveDecimal.create("20");
    DecimalUtil.round(0, d1, dcv);
    Assert.assertEquals(0, expected1.compareTo(dcv.vector[0].getHiveDecimal()));
    // As of HIVE-8745, these decimal values should be trimmed of trailing zeros.
    HiveDecimal d2 = HiveDecimal.create("23.00000");
    Assert.assertEquals(0, d2.scale());
    HiveDecimal expected2 = HiveDecimal.create("23");
    DecimalUtil.round(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d3 = HiveDecimal.create("-25.34567");
    HiveDecimal expected3 = HiveDecimal.create("-25");
    DecimalUtil.round(0, d3, dcv);
    Assert.assertEquals(0, expected3.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d4 = HiveDecimal.create("-17.00000");
    Assert.assertEquals(0, d4.scale());
    HiveDecimal expected4 = HiveDecimal.create("-17");
    DecimalUtil.round(0, d4, dcv);
    Assert.assertEquals(0, expected4.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d5 = HiveDecimal.create("19.36778");
    HiveDecimal expected5 = HiveDecimal.create("19");
    DecimalUtil.round(0, d5, dcv);
    Assert.assertEquals(0, expected5.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d6 = HiveDecimal.create("-25.54567");
    HiveDecimal expected6 = HiveDecimal.create("-26");
    DecimalUtil.round(0, d6, dcv);
    Assert.assertEquals(0, expected6.compareTo(dcv.vector[0].getHiveDecimal()));
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 63 with HiveDecimal

use of org.apache.hadoop.hive.common.type.HiveDecimal in project hive by apache.

the class TestDecimalUtil method testNegate.

@Test
public void testNegate() {
    DecimalColumnVector dcv = new DecimalColumnVector(4, 20, 13);
    HiveDecimal d1 = HiveDecimal.create("19.56778");
    HiveDecimal expected1 = HiveDecimal.create("-19.56778");
    DecimalUtil.negate(0, d1, dcv);
    Assert.assertEquals(0, expected1.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d2 = HiveDecimal.create("-25.34567");
    HiveDecimal expected2 = HiveDecimal.create("25.34567");
    DecimalUtil.negate(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0].getHiveDecimal()));
    // As of HIVE-8745, these decimal values should be trimmed of trailing zeros.
    HiveDecimal d3 = HiveDecimal.create("0.00000");
    Assert.assertEquals(0, d3.scale());
    HiveDecimal expected3 = HiveDecimal.create("0");
    DecimalUtil.negate(0, d3, dcv);
    Assert.assertEquals(0, expected3.compareTo(dcv.vector[0].getHiveDecimal()));
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 64 with HiveDecimal

use of org.apache.hadoop.hive.common.type.HiveDecimal in project hive by apache.

the class TestDecimalUtil method testFloor.

@Test
public void testFloor() {
    DecimalColumnVector dcv = new DecimalColumnVector(4, 20, 13);
    HiveDecimal d1 = HiveDecimal.create("19.56778");
    HiveDecimal expected1 = HiveDecimal.create("19");
    DecimalUtil.floor(0, d1, dcv);
    Assert.assertEquals(0, expected1.compareTo(dcv.vector[0].getHiveDecimal()));
    // As of HIVE-8745, these decimal values should be trimmed of trailing zeros.
    HiveDecimal d2 = HiveDecimal.create("23.00000");
    Assert.assertEquals(0, d2.scale());
    HiveDecimal expected2 = HiveDecimal.create("23");
    DecimalUtil.floor(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d3 = HiveDecimal.create("-25.34567");
    HiveDecimal expected3 = HiveDecimal.create("-26");
    DecimalUtil.floor(0, d3, dcv);
    Assert.assertEquals(0, expected3.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d4 = HiveDecimal.create("-17.00000");
    Assert.assertEquals(0, d4.scale());
    HiveDecimal expected4 = HiveDecimal.create("-17");
    DecimalUtil.floor(0, d4, dcv);
    Assert.assertEquals(0, expected4.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d5 = HiveDecimal.create("-0.30000");
    Assert.assertEquals(1, d5.scale());
    HiveDecimal expected5 = HiveDecimal.create("-1");
    DecimalUtil.floor(0, d5, dcv);
    Assert.assertEquals(0, expected5.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d6 = HiveDecimal.create("0.30000");
    Assert.assertEquals(1, d6.scale());
    HiveDecimal expected6 = HiveDecimal.create("0");
    DecimalUtil.floor(0, d6, dcv);
    Assert.assertEquals(0, expected6.compareTo(dcv.vector[0].getHiveDecimal()));
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 65 with HiveDecimal

use of org.apache.hadoop.hive.common.type.HiveDecimal in project hive by apache.

the class TestDecimalUtil method testAbs.

@Test
public void testAbs() {
    DecimalColumnVector dcv = new DecimalColumnVector(4, 20, 13);
    HiveDecimal d1 = HiveDecimal.create("19.56778");
    DecimalUtil.abs(0, d1, dcv);
    Assert.assertEquals(0, d1.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d2 = HiveDecimal.create("-25.34567");
    HiveDecimal expected2 = HiveDecimal.create("25.34567");
    DecimalUtil.abs(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0].getHiveDecimal()));
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Aggregations

HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)94 Test (org.junit.Test)28 Timestamp (java.sql.Timestamp)24 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)23 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)22 Text (org.apache.hadoop.io.Text)22 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)21 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)21 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)20 Date (java.sql.Date)19 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)18 BytesWritable (org.apache.hadoop.io.BytesWritable)17 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)16 HiveIntervalYearMonth (org.apache.hadoop.hive.common.type.HiveIntervalYearMonth)15 DateWritable (org.apache.hadoop.hive.serde2.io.DateWritable)15 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)15 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)14 IntWritable (org.apache.hadoop.io.IntWritable)14 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)13 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)13