Search in sources :

Example 36 with DoubleWritable

use of org.apache.hadoop.io.DoubleWritable in project hive by apache.

the class TestETypeConverter method testGetFloatConverterForDouble.

@Test
public void testGetFloatConverterForDouble() throws Exception {
    MyConverterParent converterParent = new MyConverterParent();
    PrimitiveType primitiveType = Types.optional(PrimitiveTypeName.FLOAT).named("value");
    PrimitiveConverter converter = ETypeConverter.getNewConverter(primitiveType, 1, converterParent, createHiveTypeInfo("double"));
    ((PrimitiveConverter) converter).addFloat(3276f);
    Writable writable = converterParent.getValue();
    DoubleWritable doubleWritable = (DoubleWritable) writable;
    assertEquals(3276d, doubleWritable.get(), 0);
}
Also used : PrimitiveConverter(org.apache.parquet.io.api.PrimitiveConverter) Writable(org.apache.hadoop.io.Writable) DoubleWritable(org.apache.hadoop.io.DoubleWritable) LongWritable(org.apache.hadoop.io.LongWritable) BytesWritable(org.apache.hadoop.io.BytesWritable) IntWritable(org.apache.hadoop.io.IntWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) FloatWritable(org.apache.hadoop.io.FloatWritable) PrimitiveType(org.apache.parquet.schema.PrimitiveType) DoubleWritable(org.apache.hadoop.io.DoubleWritable) Test(org.junit.Test)

Example 37 with DoubleWritable

use of org.apache.hadoop.io.DoubleWritable in project hive by apache.

the class TestGenericUDFMonthsBetween method runTestDt.

protected void runTestDt(String dt1, String dt2, Double expDiff, GenericUDFMonthsBetween udf) throws HiveException {
    DateWritableV2 dtWr1 = dt1 == null ? null : new DateWritableV2(Date.valueOf(dt1));
    DateWritableV2 dtWr2 = dt2 == null ? null : new DateWritableV2(Date.valueOf(dt2));
    DeferredJavaObject valueObj1 = new DeferredJavaObject(dtWr1);
    DeferredJavaObject valueObj2 = new DeferredJavaObject(dtWr2);
    DeferredObject[] args = new DeferredObject[] { valueObj1, valueObj2 };
    DoubleWritable output = (DoubleWritable) udf.evaluate(args);
    if (expDiff == null) {
        assertNull("months_between() test for NULL DATE failed", output);
    } else {
        assertNotNull("months_between() test for NOT NULL DATE failed", output);
        assertEquals("months_between() test for DATE failed", expDiff, output.get(), 0.00000001D);
    }
}
Also used : DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DateWritableV2(org.apache.hadoop.hive.serde2.io.DateWritableV2) DoubleWritable(org.apache.hadoop.io.DoubleWritable)

Example 38 with DoubleWritable

use of org.apache.hadoop.io.DoubleWritable in project hive by apache.

the class TestGenericUDFMonthsBetween method runTestStr.

protected void runTestStr(String date1, String date2, Double expDiff, GenericUDFMonthsBetween udf) throws HiveException {
    DeferredJavaObject valueObj1 = new DeferredJavaObject(date1 == null ? null : new Text(date1));
    DeferredJavaObject valueObj2 = new DeferredJavaObject(date2 == null ? null : new Text(date2));
    DeferredObject[] args = new DeferredObject[] { valueObj1, valueObj2 };
    DoubleWritable output = (DoubleWritable) udf.evaluate(args);
    if (expDiff == null) {
        assertNull("months_between() test for NULL STRING failed", output);
    } else {
        assertNotNull("months_between() test for NOT NULL STRING failed", output);
        assertEquals("months_between() test for STRING failed", expDiff, output.get(), 0.00000001D);
    }
}
Also used : DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) Text(org.apache.hadoop.io.Text) DoubleWritable(org.apache.hadoop.io.DoubleWritable)

Aggregations

DoubleWritable (org.apache.hadoop.io.DoubleWritable)38 IntWritable (org.apache.hadoop.io.IntWritable)20 Test (org.junit.Test)19 Path (org.apache.hadoop.fs.Path)12 BooleanWritable (org.apache.hadoop.io.BooleanWritable)12 LongWritable (org.apache.hadoop.io.LongWritable)12 BytesWritable (org.apache.hadoop.io.BytesWritable)11 FloatWritable (org.apache.hadoop.io.FloatWritable)11 FileSystem (org.apache.hadoop.fs.FileSystem)10 Writable (org.apache.hadoop.io.Writable)10 Configuration (org.apache.hadoop.conf.Configuration)9 Text (org.apache.hadoop.io.Text)8 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)7 ByteWritable (org.apache.hadoop.io.ByteWritable)7 NullWritable (org.apache.hadoop.io.NullWritable)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 SequenceFile (org.apache.hadoop.io.SequenceFile)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4