public static CharTypeInfo getCharTypeInfo(ASTNode node) throws SemanticException { if (node.getChildCount() != 1) { throw new SemanticException("Bad params for type char"); } String lengthStr = node.getChild(0).getText(); return TypeInfoFactory.getCharTypeInfo(Integer.parseInt(lengthStr)); }
public static CharTypeInfo getCharTypeInfo(ASTNode node) throws SemanticException { if (node.getChildCount() != 1) { throw new SemanticException("Bad params for type char"); } String lengthStr = node.getChild(0).getText(); return TypeInfoFactory.getCharTypeInfo(Integer.parseInt(lengthStr)); }
CharType charType = (CharType) type; int charLength = charType.getLength(); return getPrimitiveWritableObjectInspector(getCharTypeInfo(charLength));
int charLength = charType.getLength(); if (charLength <= HiveChar.MAX_CHAR_LENGTH) { return getCharTypeInfo(charLength);
return new JavaHiveCharObjectInspector(getCharTypeInfo(charLength));
throw new AvroSerdeException("Failed to obtain maxLength value from file schema: " + schema, ex); return TypeInfoFactory.getCharTypeInfo(maxLength);
TypeInfoFactory.getCharTypeInfo(type.getMaximumLength())); case VARCHAR: if (!type.hasMaximumLength()) {
TypeInfoUtils.getCharacterLengthForType(a), TypeInfoUtils.getCharacterLengthForType(b)); return TypeInfoFactory.getCharTypeInfo(maxLength); case VARCHAR: maxLength = getCommonLength(
@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())); }
TypeInfoUtils.getCharacterLengthForType(a), TypeInfoUtils.getCharacterLengthForType(b)); return TypeInfoFactory.getCharTypeInfo(maxLength); case VARCHAR: maxLength = getCommonLength(
@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()); }
typeInfo = TypeInfoFactory.getCharTypeInfo( GenericUDFUtils.StringHelper.getFixedStringSizeForType(argumentOI)); outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo);
@Test public void testCharVarcharArgs() throws HiveException { GenericUDFPrintf udf = new GenericUDFPrintf(); ObjectInspector[] inputOIs = { PrimitiveObjectInspectorFactory.writableStringObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getCharTypeInfo(5)), PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(TypeInfoFactory.getVarcharTypeInfo(7)) }; HiveCharWritable argChar = new HiveCharWritable(); argChar.set("hello"); HiveVarcharWritable argVarchar = new HiveVarcharWritable(); argVarchar.set("world"); DeferredObject[] args = { new DeferredJavaObject(new Text("1st: %s, 2nd: %s")), new DeferredJavaObject(argChar), new DeferredJavaObject(argVarchar) }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(PrimitiveObjectInspectorFactory.writableStringObjectInspector, oi); Text res = (Text) udf.evaluate(args); Assert.assertEquals("1st: hello, 2nd: world", res.toString()); }
@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()); }
typeInfo = TypeInfoFactory.getCharTypeInfo( GenericUDFUtils.StringHelper.getFixedStringSizeForType(argumentOI)); outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(
typeInfo = TypeInfoFactory.getCharTypeInfo( GenericUDFUtils.StringHelper.getFixedStringSizeForType(argumentOI)); outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo);
typeInfo = TypeInfoFactory.getCharTypeInfo( GenericUDFUtils.StringHelper.getFixedStringSizeForType(argumentOI)); outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(
@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()); }