private Writable allocateWritable(Type type) { switch (type) { case BYTE: return new ByteWritable(); case BOOL: return new BooleanWritable(); case INT: return new IntWritable(); case SHORT: return new ShortWritable(); case LONG: return new LongWritable(); case FLOAT: return new FloatWritable(); case DOUBLE: return new DoubleWritable(); case STRING: return new Text(); default: assert false; // not supported } return null; }
public LazyFloat(LazyFloat copy) { super(copy); data = new FloatWritable(copy.data.get()); }
public FloatWritable readFloat(FloatWritable fw) throws IOException { if (fw == null) { fw = new FloatWritable(); } fw.set(in.readFloat()); return fw; }
switch (poi.getPrimitiveCategory()) { case INT: return Bytes.toBytes(((IntWritable) writable).get()); case BOOLEAN: return Bytes.toBytes(((BooleanWritable) writable).get()); case LONG: return Bytes.toBytes(((LongWritable) writable).get()); case FLOAT: return Bytes.toBytes(((FloatWritable) writable).get()); case DOUBLE: return Bytes.toBytes(((DoubleWritable) writable).get()); case SHORT: return Bytes.toBytes(((ShortWritable) writable).get()); case STRING: return Bytes.toBytes(((Text) writable).toString()); case BYTE: return Bytes.toBytes(((ByteWritable) writable).get());
writable = new BooleanWritable(); ((BooleanWritable) writable).set(deserializeRead.currentBoolean); writable = new ByteWritable(); ((ByteWritable) writable).set(deserializeRead.currentByte); writable = new ShortWritable(); ((ShortWritable) writable).set(deserializeRead.currentShort); writable = new IntWritable(); ((IntWritable) writable).set(deserializeRead.currentInt); writable = new LongWritable(); ((LongWritable) writable).set(deserializeRead.currentLong); writable = new FloatWritable(); ((FloatWritable) writable).set(deserializeRead.currentFloat); writable = new Text();
byteWritable.set((byte) -(((ByteWritable)input).get())); return byteWritable; case SHORT: shortWritable.set((short) -(((ShortWritable)input).get())); return shortWritable; case INT: intWritable.set(-(((IntWritable)input).get())); return intWritable; case LONG: longWritable.set(-(((LongWritable)input).get())); return longWritable; case FLOAT: floatWritable.set(-(((FloatWritable)input).get())); return floatWritable; case DOUBLE:
/** * Convert from string to a float. This is called for CAST(... AS FLOAT) * * @param i * The string value to convert * @return FloatWritable */ public FloatWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { floatWritable.set(Float.parseFloat(i.toString())); return floatWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // But we decided to return NULL instead, which is more conservative. return null; } } }
@Test public void testDruidObjectSerializerwithNullTimestamp() throws Exception { // Create, initialize, and test the SerDe DruidSerDe serDe = new DruidSerDe(); Configuration conf = new Configuration(); Properties tbl; // Mixed source (all types) tbl = createPropertiesSource(COLUMN_NAMES, COLUMN_TYPES); SerDeUtils.initializeSerDe(serDe, conf, tbl, null); Object[] row = new Object[]{ null, new Text("dim1_val"), new HiveCharWritable(new HiveChar("dim2_v", 6)), new HiveVarcharWritable(new HiveVarchar("dim3_val", 8)), new DoubleWritable(10669.3D), new FloatWritable(10669.45F), new LongWritable(1113939), new IntWritable(1112123), new ShortWritable((short) 12), new ByteWritable((byte) 0), null // granularity }; expectedEx.expect(NullPointerException.class); expectedEx.expectMessage("Timestamp column cannot have null value"); // should fail as timestamp is null serializeObject(tbl, serDe, row, DRUID_WRITABLE); }
return null; case BOOLEAN: ((BooleanWritable)returnObj).set((Boolean)result); return returnObj; case BYTE: ((ByteWritable)returnObj).set((Byte)result); return returnObj; case SHORT: ((ShortWritable)returnObj).set((Short)result); return returnObj; case INT: ((IntWritable)returnObj).set((Integer)result); return returnObj; case LONG: ((LongWritable)returnObj).set((Long)result); return returnObj; case FLOAT: ((FloatWritable)returnObj).set((Float)result); return returnObj; case DOUBLE: return returnObj; case STRING: ((Text)returnObj).set((String)result); return returnObj; case TIMESTAMP:
@Test public void testFloat() throws HiveException { GenericUDFCeil udf = new GenericUDFCeil(); FloatWritable input = new FloatWritable(323.4747f); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableFloatObjectInspector, }; DeferredObject[] args = { new DeferredJavaObject(input) }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.longTypeInfo, oi.getTypeInfo()); LongWritable res = (LongWritable) udf.evaluate(args); Assert.assertEquals(324L, res.get()); }
@Override public Object getWritableConstantValue() { if (value==null) { return null; } return new FloatWritable(value); } }
@Override public float get(Object o) { return ((FloatWritable) o).get(); }