Search in sources :

Example 46 with DoubleWritable

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

the class TestUDFMath method testAcos.

@Test
public void testAcos() throws HiveException {
    UDFAcos udf = new UDFAcos();
    input = createDecimal("0.716");
    DoubleWritable res = udf.evaluate(input);
    Assert.assertEquals(0.7727408115633954, res.get(), 0.000001);
}
Also used : DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Test(org.junit.Test)

Example 47 with DoubleWritable

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

the class TestUDFMath method testLog.

@Test
public void testLog() throws HiveException {
    UDFLog udf = new UDFLog();
    input = createDecimal("7.38905609893065");
    DoubleWritable res = udf.evaluate(input);
    Assert.assertEquals(2.0, res.get(), 0.000001);
    res = udf.evaluate(createDecimal("3.0"), createDecimal("9.0"));
    Assert.assertEquals(2.0, res.get(), 0.000001);
}
Also used : DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Test(org.junit.Test)

Example 48 with DoubleWritable

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

the class WritableHiveCharObjectInspector method getPrimitiveWritableObject.

@Override
public HiveCharWritable getPrimitiveWritableObject(Object o) {
    // then output new writable with correct params.
    if (o == null) {
        return null;
    }
    if ((o instanceof Text) || (o instanceof TimestampWritableV2) || (o instanceof HiveDecimalWritable) || (o instanceof DoubleWritable) || (o instanceof FloatWritable) || (o instanceof LongWritable) || (o instanceof IntWritable) || (o instanceof BooleanWritable)) {
        String str = o.toString();
        HiveCharWritable hcw = new HiveCharWritable();
        hcw.set(str, ((CharTypeInfo) typeInfo).getLength());
        return hcw;
    }
    HiveCharWritable writable = ((HiveCharWritable) o);
    if (doesWritableMatchTypeParams((HiveCharWritable) o)) {
        return writable;
    }
    return getWritableWithParams(writable);
}
Also used : FloatWritable(org.apache.hadoop.io.FloatWritable) BooleanWritable(org.apache.hadoop.io.BooleanWritable) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) HiveCharWritable(org.apache.hadoop.hive.serde2.io.HiveCharWritable) Text(org.apache.hadoop.io.Text) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) LongWritable(org.apache.hadoop.io.LongWritable) TimestampWritableV2(org.apache.hadoop.hive.serde2.io.TimestampWritableV2) IntWritable(org.apache.hadoop.io.IntWritable)

Example 49 with DoubleWritable

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

the class TestGenericUDAFPercentileDisc method checkPercentile.

private void checkPercentile(Long[] items, double percentile, double expected) throws Exception {
    PercentileContLongEvaluator eval = new GenericUDAFPercentileDisc.PercentileDiscLongEvaluator();
    PercentileAgg agg = new PercentileContLongEvaluator().new PercentileAgg();
    agg.percentiles = new ArrayList<DoubleWritable>();
    agg.percentiles.add(new DoubleWritable(percentile));
    agg.isAscending = true;
    for (int i = 0; i < items.length; i++) {
        eval.increment(agg, new LongWritable(items[i]), 1);
    }
    DoubleWritable result = (DoubleWritable) eval.terminate(agg);
    Assert.assertEquals(expected, result.get(), 0.01);
    eval.close();
}
Also used : PercentileContLongEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContLongEvaluator) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) LongWritable(org.apache.hadoop.io.LongWritable) PercentileAgg(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg)

Example 50 with DoubleWritable

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

the class TestGenericUDFNullif method testConversionInSameGroup.

@Test
public void testConversionInSameGroup() throws HiveException {
    GenericUDFNullif udf = new GenericUDFNullif();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(new DoubleWritable(4.0)), new DeferredJavaObject(new ByteWritable((byte) 4)) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
}
Also used : StandardListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) DeferredJavaObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject) DeferredObject(org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject) DoubleWritable(org.apache.hadoop.io.DoubleWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) Test(org.junit.Test)

Aggregations

DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)132 Test (org.junit.Test)85 IntWritable (org.apache.hadoop.io.IntWritable)71 LongWritable (org.apache.hadoop.io.LongWritable)70 Text (org.apache.hadoop.io.Text)57 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)52 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)51 FloatWritable (org.apache.hadoop.io.FloatWritable)51 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)49 BooleanWritable (org.apache.hadoop.io.BooleanWritable)46 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)42 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)42 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)42 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)40 BytesWritable (org.apache.hadoop.io.BytesWritable)36 ArrayList (java.util.ArrayList)29 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)27 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)21 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)21 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)19