Search in sources :

Example 81 with IntWritable

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

the class TestGenericUDFPower method testVarcharPowerInt.

@Test
public void testVarcharPowerInt() throws HiveException {
    GenericUDFPower udf = new GenericUDFPower();
    HiveVarcharWritable left = new HiveVarcharWritable();
    left.set("3.14");
    IntWritable right = new IntWritable(2);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(left), new DeferredJavaObject(right) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
    DoubleWritable res = (DoubleWritable) udf.evaluate(args);
    Assert.assertEquals(new Double(3.14 * 3.14), new Double(res.get()));
}
Also used : 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) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 82 with IntWritable

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

the class TestGenericUDFOPMod method testModByZero3.

@Test
public void testModByZero3() throws HiveException {
    GenericUDFOPMod udf = new GenericUDFOPMod();
    // Int
    IntWritable i1 = new IntWritable(4);
    IntWritable i2 = new IntWritable(0);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableIntObjectInspector, PrimitiveObjectInspectorFactory.writableIntObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(i1), new DeferredJavaObject(i2) };
    udf.initialize(inputOIs);
    IntWritable i3 = (IntWritable) udf.evaluate(args);
    Assert.assertNull(i3);
}
Also used : 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) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 83 with IntWritable

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

the class TestGenericUDFRound method testDecimalRoundingMetaData1.

@Test
public void testDecimalRoundingMetaData1() throws UDFArgumentException {
    GenericUDFRound udf = new GenericUDFRound();
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getDecimalTypeInfo(7, 3)), PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(-2)) };
    PrimitiveObjectInspector outputOI = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    DecimalTypeInfo outputTypeInfo = (DecimalTypeInfo) outputOI.getTypeInfo();
    Assert.assertEquals(TypeInfoFactory.getDecimalTypeInfo(5, 0), outputTypeInfo);
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test) BaseScalarUdfTest(org.apache.hadoop.hive.ql.testutil.BaseScalarUdfTest)

Example 84 with IntWritable

use of org.apache.hadoop.io.IntWritable 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 85 with IntWritable

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

the class TestGenericUDFSha2 method testShaNullBin.

public void testShaNullBin() throws HiveException {
    GenericUDFSha2 udf = new GenericUDFSha2();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
    IntWritable lenWr = null;
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, lenWr);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    runAndVerifyBin(new byte[] { 65, 66, 67 }, lenWr, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable)

Aggregations

IntWritable (org.apache.hadoop.io.IntWritable)338 Test (org.junit.Test)120 Text (org.apache.hadoop.io.Text)115 LongWritable (org.apache.hadoop.io.LongWritable)79 Path (org.apache.hadoop.fs.Path)66 FloatWritable (org.apache.hadoop.io.FloatWritable)58 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)56 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)56 BooleanWritable (org.apache.hadoop.io.BooleanWritable)51 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)50 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)47 BytesWritable (org.apache.hadoop.io.BytesWritable)45 SequenceFile (org.apache.hadoop.io.SequenceFile)41 ArrayList (java.util.ArrayList)40 Writable (org.apache.hadoop.io.Writable)39 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)37 Configuration (org.apache.hadoop.conf.Configuration)35 IOException (java.io.IOException)30 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)29 Random (java.util.Random)28