LazyBinaryHiveChar(LazyBinaryHiveChar copy) { super(copy); maxLength = copy.maxLength; data = new HiveCharWritable(copy.data); }
@Override public Object getWritableConstantValue() { if (value==null) { return null; } return new HiveCharWritable(value); } }
public LazyHiveChar(LazyHiveChar copy) { super(copy); this.maxLength = copy.maxLength; data = new HiveCharWritable(copy.data); }
public HiveCharTransformerAdapter(HiveCharObjectInspector columnType, AbstractTransformer transformer) { this(columnType, transformer, new HiveCharWritable()); }
public HiveCharTransformerAdapter(HiveCharObjectInspector columnType, AbstractTransformer transformer) { this(columnType, transformer, new HiveCharWritable()); }
public LazyHiveChar(LazyHiveCharObjectInspector oi) { super(oi); maxLength = ((CharTypeInfo)oi.getTypeInfo()).getLength(); data = new HiveCharWritable(); }
private HiveCharWritable getWritableWithParams(HiveCharWritable val) { HiveCharWritable newValue = new HiveCharWritable(); newValue.set(val, getMaxLength()); return newValue; }
LazyBinaryHiveChar(WritableHiveCharObjectInspector oi) { super(oi); maxLength = ((CharTypeInfo)oi.getTypeInfo()).getLength(); data = new HiveCharWritable(); }
@Override public Object create(HiveChar value) { HiveCharWritable ret; ret = new HiveCharWritable(); ret.set(value, getMaxLength()); return ret; }
private HiveCharWritable getWritableWithParams(HiveChar val) { HiveCharWritable hcw = new HiveCharWritable(); hcw.set(val, getMaxLength()); return hcw; }
public StringHelper(PrimitiveCategory type) throws UDFArgumentException { this.type = type; switch (type) { case STRING: returnValue = new Text(); break; case CHAR: returnValue = new HiveCharWritable(); break; case VARCHAR: returnValue = new HiveVarcharWritable(); break; default: throw new UDFArgumentException("Unexpected non-string type " + type); } }
public Object copyObject(Object o) { if (o == null) { return null; } if (o instanceof Text) { String str = ((Text)o).toString(); HiveCharWritable hcw = new HiveCharWritable(); hcw.set(str, ((CharTypeInfo)typeInfo).getLength()); return hcw; } HiveCharWritable writable = (HiveCharWritable) o; if (doesWritableMatchTypeParams((HiveCharWritable) o)) { return new HiveCharWritable(writable); } return getWritableWithParams(writable); }
public StringHelper(PrimitiveCategory type) throws UDFArgumentException { this.type = type; switch (type) { case STRING: returnValue = new Text(); break; case CHAR: returnValue = new HiveCharWritable(); break; case VARCHAR: returnValue = new HiveVarcharWritable(); break; default: throw new UDFArgumentException("Unexpected non-string type " + type); } }
private static HiveCharWritable charW(String value, int length) { return new HiveCharWritable(new HiveChar(value, length)); }
@Test public void testChar() throws HiveException { GenericUDFOPPositive udf = new GenericUDFOPPositive(); HiveChar vc = new HiveChar("32300.004747", 12); HiveCharWritable input = new HiveCharWritable(vc); CharTypeInfo inputTypeInfo = TypeInfoFactory.getCharTypeInfo(12); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo), }; DeferredObject[] args = { new DeferredJavaObject(input) }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo()); DoubleWritable res = (DoubleWritable) udf.evaluate(args); Assert.assertEquals(new Double(32300.004747), new Double(res.get())); }
@Test public void testChar() throws HiveException { GenericUDFOPNegative udf = new GenericUDFOPNegative(); HiveChar vc = new HiveChar("32300.004747", 12); HiveCharWritable input = new HiveCharWritable(vc); CharTypeInfo inputTypeInfo = TypeInfoFactory.getCharTypeInfo(12); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo), }; DeferredObject[] args = { new DeferredJavaObject(input) }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.doubleTypeInfo, oi.getTypeInfo()); DoubleWritable res = (DoubleWritable) udf.evaluate(args); Assert.assertEquals(new Double(-32300.004747), new Double(res.get())); }
@Test public void testChar() throws HiveException { GenericUDFCeil udf = new GenericUDFCeil(); HiveChar vc = new HiveChar("-32300.004747", 12); HiveCharWritable input = new HiveCharWritable(vc); CharTypeInfo inputTypeInfo = TypeInfoFactory.getCharTypeInfo(12); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo), }; 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(-32300L, res.get()); }
@Test public void testChar() throws HiveException { GenericUDFFloor udf = new GenericUDFFloor(); HiveChar vc = new HiveChar("32300.004747", 12); HiveCharWritable input = new HiveCharWritable(vc); CharTypeInfo inputTypeInfo = TypeInfoFactory.getCharTypeInfo(12); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo), }; 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(32300L, res.get()); }
@Test public void testCharFormat() throws HiveException { GenericUDFPrintf udf = new GenericUDFPrintf(); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getCharTypeInfo(10)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getVarcharTypeInfo(7)) }; HiveCharWritable formatChar = new HiveCharWritable(); formatChar.set("arg1=%s"); HiveVarcharWritable argVarchar = new HiveVarcharWritable(); argVarchar.set("world"); DeferredObject[] args = { new DeferredJavaObject(formatChar), new DeferredJavaObject(argVarchar) }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(PrimitiveObjectInspectorFactory.writableStringObjectInspector, oi); Text res = (Text) udf.evaluate(args); Assert.assertEquals("arg1=world", res.toString()); }
@Test public void testVarcharFormat() throws HiveException { GenericUDFPrintf udf = new GenericUDFPrintf(); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getVarcharTypeInfo(7)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getCharTypeInfo(5)) }; HiveCharWritable argChar = new HiveCharWritable(); argChar.set("hello"); HiveVarcharWritable formatVarchar = new HiveVarcharWritable(); formatVarchar.set("arg1=%s"); DeferredObject[] args = { new DeferredJavaObject(formatVarchar), new DeferredJavaObject(argChar) }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(PrimitiveObjectInspectorFactory.writableStringObjectInspector, oi); Text res = (Text) udf.evaluate(args); Assert.assertEquals("arg1=hello", res.toString()); }