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;
}
}
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;
}
}
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;
}
}
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);
}
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);
}
Aggregations