Search in sources :

Example 1 with TypeInfoFactory.intTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.intTypeInfo 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 2 with TypeInfoFactory.intTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.intTypeInfo 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)

Example 3 with TypeInfoFactory.intTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.intTypeInfo in project hive by apache.

the class TestGenericUDFSha2 method testSha0Bin.

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

Example 4 with TypeInfoFactory.intTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.intTypeInfo in project hive by apache.

the class TestGenericUDFSha2 method testSha256Str.

public void testSha256Str() throws HiveException {
    GenericUDFSha2 udf = new GenericUDFSha2();
    ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    IntWritable lenWr = new IntWritable(256);
    ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, lenWr);
    ObjectInspector[] arguments = { valueOI0, valueOI1 };
    udf.initialize(arguments);
    runAndVerifyStr("ABC", lenWr, "b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78", udf);
    runAndVerifyStr("", lenWr, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", udf);
    // null
    runAndVerifyStr(null, lenWr, null, udf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable)

Example 5 with TypeInfoFactory.intTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.intTypeInfo in project hive by apache.

the class TestGenericUDFInternalInterval method testDayIntervalConstant.

@Test
public void testDayIntervalConstant() throws Exception {
    try (GenericUDFInternalInterval udf = new GenericUDFInternalInterval()) {
        ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(HiveParser.TOK_INTERVAL_DAY_LITERAL)), PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(TypeInfoFactory.intTypeInfo, new IntWritable(3)) };
        PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
        Assert.assertEquals(TypeInfoFactory.intervalDayTimeTypeInfo, oi.getTypeInfo());
        ConstantObjectInspector coi = (ConstantObjectInspector) oi;
        HiveIntervalDayTimeWritable res = (HiveIntervalDayTimeWritable) coi.getWritableConstantValue();
        Assert.assertEquals(3, res.getHiveIntervalDayTime().getDays());
    }
}
Also used : PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) HiveIntervalDayTimeWritable(org.apache.hadoop.hive.serde2.io.HiveIntervalDayTimeWritable) ConstantObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)30 IntWritable (org.apache.hadoop.io.IntWritable)30 Test (org.junit.Test)25 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)14 Text (org.apache.hadoop.io.Text)10 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)9 ArrayList (java.util.ArrayList)6 ColumnMapper (org.apache.hadoop.hive.accumulo.columns.ColumnMapper)6 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)6 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)6 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)5 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)5 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Properties (java.util.Properties)4 Configuration (org.apache.hadoop.conf.Configuration)4 LazySimpleStructObjectInspector (org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector)4 ConstantObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ConstantObjectInspector)4 DataOutputStream (java.io.DataOutputStream)3 HiveAccumuloMapColumnMapping (org.apache.hadoop.hive.accumulo.columns.HiveAccumuloMapColumnMapping)3