Search in sources :

Example 1 with PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector in project hive by apache.

the class TestStreamingAvg method avgHiveDecimal.

public void avgHiveDecimal(Iterator<HiveDecimal> inVals, int inSz, int numPreceding, int numFollowing, Iterator<HiveDecimal> outVals) throws HiveException {
    GenericUDAFAverage fnR = new GenericUDAFAverage();
    TypeInfo[] inputTypes = { TypeInfoFactory.decimalTypeInfo };
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector };
    HiveDecimalWritable[] in = new HiveDecimalWritable[1];
    in[0] = new HiveDecimalWritable();
    TestStreamingSum._agg(fnR, inputTypes, inVals, TypeHandler.HiveDecimalHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) GenericUDAFAverage(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)

Example 2 with PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector in project hive by apache.

the class TestGenericUDFBRound method testDecimal.

@Test
public void testDecimal() throws HiveException {
    GenericUDFBRound udf = new GenericUDFBRound();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector;
    IntWritable scale = new IntWritable(0);
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, scale);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    runDecimal(2.5, scale, 2.0, udf);
    runDecimal(3.5, scale, 4.0, udf);
    runDecimal(2.49, scale, 2.0, udf);
    runDecimal(3.49, scale, 3.0, udf);
    runDecimal(2.51, scale, 3.0, udf);
    runDecimal(3.51, scale, 4.0, udf);
    runDecimal(2.4, scale, 2.0, udf);
    runDecimal(3.4, scale, 3.0, udf);
    runDecimal(2.6, scale, 3.0, udf);
    runDecimal(3.6, scale, 4.0, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 3 with PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector in project hive by apache.

the class TestStreamingSum method sumHiveDecimal.

public void sumHiveDecimal(Iterator<HiveDecimal> inVals, int inSz, int numPreceding, int numFollowing, Iterator<HiveDecimal> outVals) throws HiveException {
    GenericUDAFSum fnR = new GenericUDAFSum();
    TypeInfo[] inputTypes = { TypeInfoFactory.decimalTypeInfo };
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector };
    HiveDecimalWritable[] in = new HiveDecimalWritable[1];
    in[0] = new HiveDecimalWritable();
    _agg(fnR, inputTypes, inVals, TypeHandler.HiveDecimalHandler, in, inputOIs, inSz, numPreceding, numFollowing, outVals);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) GenericUDAFSum(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFSum)

Example 4 with PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector in project hive by apache.

the class TestGenericUDFRound method getExpectedResult.

@Override
public InspectableObject[] getExpectedResult() {
    DataBuilder db = new DataBuilder();
    db.setColumnNames("_col1", "_col2", "_col3", "_col4", "_col5", "_col6", "_col7", "_col8");
    db.setColumnTypes(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableByteObjectInspector, PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector);
    db.addRow(null, new IntWritable(170), new DoubleWritable(1.1), new FloatWritable(32f), new ByteWritable((byte) 0), new ShortWritable((short) 1234), new LongWritable(123500L), new HiveDecimalWritable(HiveDecimal.create("983.724")));
    db.addRow(new DoubleWritable(-200), null, null, new FloatWritable(0f), new ByteWritable((byte) 100), new ShortWritable((short) 551), new LongWritable(900L), new HiveDecimalWritable(HiveDecimal.create("983723.005")));
    db.addRow(new DoubleWritable(500), new IntWritable(22345), new DoubleWritable(-23.000), new FloatWritable(-3f), new ByteWritable((byte) 100), new ShortWritable((short) 2321), new LongWritable(9200L), new HiveDecimalWritable(HiveDecimal.create("-932032.7")));
    return db.createRows();
}
Also used : FloatWritable(org.apache.hadoop.io.FloatWritable) DataBuilder(org.apache.hadoop.hive.ql.testutil.DataBuilder) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) LongWritable(org.apache.hadoop.io.LongWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable)

Example 5 with PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector

use of org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector in project hive by apache.

the class TestValueBoundaryScanner method testHiveDecimalEquals.

@Test
public void testHiveDecimalEquals() {
    PTFExpressionDef argDef = new PTFExpressionDef();
    argDef.setOI(PrimitiveObjectInspectorFactory.writableHiveDecimalObjectInspector);
    HiveDecimalValueBoundaryScanner scanner = new HiveDecimalValueBoundaryScanner(null, null, new OrderExpressionDef(argDef), false);
    HiveDecimalWritable w1 = new HiveDecimalWritable(1);
    HiveDecimalWritable w2 = new HiveDecimalWritable(2);
    Assert.assertTrue(scanner.isEqual(w1, w1));
    Assert.assertFalse(scanner.isEqual(w1, w2));
    Assert.assertFalse(scanner.isEqual(w2, w1));
    Assert.assertFalse(scanner.isEqual(null, w2));
    Assert.assertFalse(scanner.isEqual(w1, null));
    Assert.assertTrue(scanner.isEqual(null, null));
}
Also used : HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) PTFExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef) OrderExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef) Test(org.junit.Test)

Aggregations

HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)4 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)4 Test (org.junit.Test)3 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)2 IntWritable (org.apache.hadoop.io.IntWritable)2 BigDecimal (java.math.BigDecimal)1 Timestamp (java.sql.Timestamp)1 OrderExpressionDef (org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef)1 PTFExpressionDef (org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef)1 DataBuilder (org.apache.hadoop.hive.ql.testutil.DataBuilder)1 GenericUDAFAverage (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage)1 GenericUDAFSum (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFSum)1 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)1 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)1 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)1 StandardStructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector)1 FloatWritable (org.apache.hadoop.io.FloatWritable)1 LongWritable (org.apache.hadoop.io.LongWritable)1 PartialRow (org.apache.kudu.client.PartialRow)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1