Search in sources :

Example 61 with DoubleWritable

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

the class TestLazyPrimitive method testLazyDouble.

/**
 * Test the LazyDouble class.
 */
@Test
public void testLazyDouble() throws Throwable {
    try {
        LazyDouble b = new LazyDouble(LazyPrimitiveObjectInspectorFactory.LAZY_DOUBLE_OBJECT_INSPECTOR);
        initLazyObject(b, new byte[] { '0' }, 0, 0);
        assertNull(b.getWritableObject());
        initLazyObject(b, new byte[] { '0' }, 0, 1);
        assertEquals(new DoubleWritable(0), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '0' }, 0, 2);
        assertEquals(new DoubleWritable(0), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '0' }, 0, 2);
        assertEquals(new DoubleWritable(-0.0), b.getWritableObject());
        initLazyObject(b, new byte[] { 'a', '1', 'b' }, 1, 1);
        assertEquals(new DoubleWritable(1), b.getWritableObject());
        initLazyObject(b, new byte[] { 'a', '-', '1' }, 1, 2);
        assertEquals(new DoubleWritable(-1), b.getWritableObject());
        initLazyObject(b, new byte[] { 'a', '+', '1' }, 1, 2);
        assertEquals(new DoubleWritable(1), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '1', '2', '8' }, 0, 4);
        assertEquals(new DoubleWritable(-128), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '1', '2', '7' }, 0, 4);
        assertEquals(new DoubleWritable(127), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '3', '2', '7', '6', '8' }, 0, 6);
        assertEquals(new DoubleWritable(-32768), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '3', '2', '7', '6', '7' }, 0, 6);
        assertEquals(new DoubleWritable(32767), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '8' }, 0, 11);
        assertEquals(new DoubleWritable(-2147483648), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '7' }, 0, 11);
        assertEquals(new DoubleWritable(2147483647), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5', '4', '7', '7', '5', '8', '0', '8' }, 0, 20);
        assertEquals(new DoubleWritable(-9223372036854775808L), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '9', '2', '2', '3', '3', '7', '2', '0', '3', '6', '8', '5', '4', '7', '7', '5', '8', '0', '7' }, 0, 20);
        assertEquals(new DoubleWritable(9223372036854775807L), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '3', '.', '7', '6', '8' }, 0, 6);
        assertEquals(new DoubleWritable(-3.768), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '3', '.', '7', '6', '7' }, 0, 6);
        assertEquals(new DoubleWritable(3.767), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '2', '.', '4', '7', '4', '8', '3', '6', 'e', '8' }, 0, 11);
        assertEquals(new DoubleWritable(-2.474836e8), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '2', '.', '4', '7', '4', '8', '3', 'E', '-', '7' }, 0, 11);
        assertEquals(new DoubleWritable(2.47483E-7), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '.', '4', '7', '4', '8', '3', '6', 'e', '8' }, 0, 10);
        assertEquals(new DoubleWritable(-.474836e8), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '.', '4', '7', '4', '8', '3', 'E', '-', '7' }, 0, 10);
        assertEquals(new DoubleWritable(.47483E-7), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '2', '1', '4', '7', '4', '8', '3', '6', '4', '.' }, 0, 11);
        assertEquals(new DoubleWritable(-214748364.), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '2', '1', '4', '7', '4', '8', '3', '6', '4', '.' }, 0, 11);
        assertEquals(new DoubleWritable(+214748364.), b.getWritableObject());
        initLazyObject(b, new byte[] { '.', '0' }, 0, 2);
        assertEquals(new DoubleWritable(.0), b.getWritableObject());
        initLazyObject(b, new byte[] { '0', '.' }, 0, 2);
        assertEquals(new DoubleWritable(0.), b.getWritableObject());
        initLazyObject(b, new byte[] { 'a', '1', 'b' }, 1, 2);
        assertNull(b.getWritableObject());
        assertNull(b.getWritableObject());
        initLazyObject(b, new byte[] { '.', '1', '2', '3' }, 0, 1);
        assertNull(b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '1', '2', '3' }, 0, 1);
        assertNull(b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '1', '2', '3' }, 0, 1);
        assertNull(b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '1', 'e', '3', '3', '3', '3', '3', '3' }, 0, 9);
        assertEquals(new DoubleWritable(Double.NEGATIVE_INFINITY), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '1', 'e', '3', '3', '3', '3', '3', '3' }, 0, 9);
        assertEquals(new DoubleWritable(Double.POSITIVE_INFINITY), b.getWritableObject());
        initLazyObject(b, new byte[] { '+', '1', 'e', '-', '3', '3', '3', '3', '3' }, 0, 8);
        assertEquals(new DoubleWritable(0), b.getWritableObject());
        initLazyObject(b, new byte[] { '-', '1', 'e', '-', '3', '3', '3', '3', '3' }, 0, 8);
        assertEquals(new DoubleWritable(-0.0), b.getWritableObject());
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Test(org.junit.Test)

Example 62 with DoubleWritable

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

the class TestLazySimpleSerDe method testLazySimpleSerDeExtraColumns.

/**
 * Test the LazySimpleSerDe class with extra columns.
 */
@Test
public void testLazySimpleSerDeExtraColumns() throws Throwable {
    try {
        // Create the SerDe
        LazySimpleSerDe serDe = new LazySimpleSerDe();
        Configuration conf = new Configuration();
        Properties tbl = createProperties();
        serDe.initialize(conf, tbl, null);
        // Data
        Text t = new Text("123\t456\t789\t1000\t5.3\thive and hadoop\t1.\ta\tb\t");
        String s = "123\t456\t789\t1000\t5.3\thive and hadoop\t1\ta";
        Object[] expectedFieldsData = { new ByteWritable((byte) 123), new ShortWritable((short) 456), new IntWritable(789), new LongWritable(1000), new DoubleWritable(5.3), new Text("hive and hadoop"), new IntWritable(1), new Text("a") };
        // Test
        deserializeAndSerialize(serDe, t, s, expectedFieldsData);
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Properties(java.util.Properties) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) LongWritable(org.apache.hadoop.io.LongWritable) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 63 with DoubleWritable

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

the class TestLazySimpleSerDe method testLazySimpleSerDeMissingColumns.

/**
 * Test the LazySimpleSerDe class with missing columns.
 */
@Test
public void testLazySimpleSerDeMissingColumns() throws Throwable {
    try {
        // Create the SerDe
        LazySimpleSerDe serDe = new LazySimpleSerDe();
        Configuration conf = new Configuration();
        Properties tbl = createProperties();
        serDe.initialize(conf, tbl, null);
        // Data
        Text t = new Text("123\t456\t789\t1000\t5.3\t");
        String s = "123\t456\t789\t1000\t5.3\t\tNULL\tNULL";
        Object[] expectedFieldsData = { new ByteWritable((byte) 123), new ShortWritable((short) 456), new IntWritable(789), new LongWritable(1000), new DoubleWritable(5.3), new Text(""), null, null };
        // Test
        deserializeAndSerialize(serDe, t, s, expectedFieldsData);
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Properties(java.util.Properties) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) LongWritable(org.apache.hadoop.io.LongWritable) ByteWritable(org.apache.hadoop.hive.serde2.io.ByteWritable) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 64 with DoubleWritable

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

the class TestGenericUDFPower method testFloatPowerFloat.

@Test
public void testFloatPowerFloat() throws HiveException {
    GenericUDFPower udf = new GenericUDFPower();
    FloatWritable f1 = new FloatWritable(4.5f);
    FloatWritable f2 = new FloatWritable(-1.5f);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(f1), new DeferredJavaObject(f2) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
    DoubleWritable res = (DoubleWritable) udf.evaluate(args);
    Assert.assertEquals(0.10475656017578482, res.get(), EPSILON);
}
Also used : FloatWritable(org.apache.hadoop.io.FloatWritable) 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) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) Test(org.junit.Test)

Example 65 with DoubleWritable

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

the class TestGenericUDFPower method testShortPowerFloat.

@Test
public void testShortPowerFloat() throws HiveException {
    GenericUDFPower udf = new GenericUDFPower();
    ShortWritable base = new ShortWritable((short) 23);
    FloatWritable power = new FloatWritable(-1.5f);
    ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableShortObjectInspector, PrimitiveObjectInspectorFactory.writableFloatObjectInspector };
    DeferredObject[] args = { new DeferredJavaObject(base), new DeferredJavaObject(power) };
    PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs);
    Assert.assertEquals(oi.getTypeInfo(), TypeInfoFactory.doubleTypeInfo);
    DoubleWritable res = (DoubleWritable) udf.evaluate(args);
    Assert.assertEquals(0.009065844089438033, res.get(), EPSILON);
}
Also used : FloatWritable(org.apache.hadoop.io.FloatWritable) 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) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) 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