@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException(getFuncName() + " requires 1 argument, got " + arguments.length); } checkIfPrimitive(arguments, 0, "1st"); checkIfStringGroup(arguments, 0, "1st"); getStringConverter(arguments, 0, "1st"); ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector; return outputOI; }
@Override public String getDisplayString(String[] children) { return getStandardDisplayString(getFuncName(), children); }
protected void checkIfPrimitive(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { ObjectInspector.Category oiCat = arguments[i].getCategory(); if (oiCat != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes primitive types as " + argOrder + " argument, got " + oiCat); } }
public void testSoundexWrongType0() throws HiveException { @SuppressWarnings("resource") GenericUDFSoundex udf = new GenericUDFSoundex(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableIntObjectInspector; ObjectInspector[] arguments = { valueOI0 }; try { udf.initialize(arguments); assertTrue("soundex test. UDFArgumentTypeException is expected", false); } catch (UDFArgumentTypeException e) { assertEquals("soundex test", "soundex only takes STRING_GROUP types as 1st argument, got INT", e.getMessage()); } }
protected void checkIfPrimitive(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { ObjectInspector.Category oiCat = arguments[i].getCategory(); if (oiCat != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes primitive types as " + argOrder + " argument, got " + oiCat); } }
public void testSoundexWrongLength() throws HiveException { @SuppressWarnings("resource") GenericUDFSoundex udf = new GenericUDFSoundex(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector; ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector; ObjectInspector[] arguments = { valueOI0, valueOI1 }; try { udf.initialize(arguments); assertTrue("soundex test. UDFArgumentLengthException is expected", false); } catch (UDFArgumentLengthException e) { assertEquals("soundex test", "soundex requires 1 argument, got 2", e.getMessage()); } }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException(getFuncName() + " requires 1 argument, got " + arguments.length); } checkIfPrimitive(arguments, 0, "1st"); checkIfStringGroup(arguments, 0, "1st"); getStringConverter(arguments, 0, "1st"); ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector; return outputOI; }
@Override public String getDisplayString(String[] children) { return getStandardDisplayString(getFuncName(), children); }
protected void checkIfStringGroup(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { inputTypes[i] = ((PrimitiveObjectInspector) arguments[i]).getPrimitiveCategory(); if (PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputTypes[i]) != PrimitiveGrouping.STRING_GROUP && PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputTypes[i]) != PrimitiveGrouping.VOID_GROUP) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP types as " + argOrder + " argument, got " + inputTypes[i]); } }
public void testSoundex() throws HiveException { GenericUDFSoundex udf = new GenericUDFSoundex(); ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableStringObjectInspector; ObjectInspector[] arguments = { valueOI0 }; udf.initialize(arguments); runAndVerify("Miller", "M460", udf); runAndVerify("miler", "M460", udf); runAndVerify("myller", "M460", udf); runAndVerify("muller", "M460", udf); runAndVerify("m", "M000", udf); runAndVerify("mu", "M000", udf); runAndVerify("mil", "M400", udf); runAndVerify("Peterson", "P362", udf); runAndVerify("Pittersen", "P362", udf); runAndVerify("", "", udf); runAndVerify(null, null, udf); runAndVerify("\u3500\u3501\u3502\u3503", null, udf); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException(getFuncName() + " requires 1 argument, got " + arguments.length); } checkIfPrimitive(arguments, 0, "1st"); checkIfStringGroup(arguments, 0, "1st"); getStringConverter(arguments, 0, "1st"); ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector; return outputOI; }
@Override public String getDisplayString(String[] children) { return getStandardDisplayString(getFuncName(), children); }
protected void checkIfStringGroup(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { inputTypes[i] = ((PrimitiveObjectInspector) arguments[i]).getPrimitiveCategory(); if (PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputTypes[i]) != PrimitiveGrouping.STRING_GROUP && PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputTypes[i]) != PrimitiveGrouping.VOID_GROUP) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP types as " + argOrder + " argument, got " + inputTypes[i]); } }
protected void checkIfPrimitive(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { ObjectInspector.Category oiCat = arguments[i].getCategory(); if (oiCat != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes primitive types as " + argOrder + " argument, got " + oiCat); } }
protected void checkIfStringGroup(ObjectInspector[] arguments, int i, String argOrder) throws UDFArgumentTypeException { inputTypes[i] = ((PrimitiveObjectInspector) arguments[i]).getPrimitiveCategory(); if (PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputTypes[i]) != PrimitiveGrouping.STRING_GROUP && PrimitiveObjectInspectorUtils.getPrimitiveGrouping(inputTypes[i]) != PrimitiveGrouping.VOID_GROUP) { throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP types as " + argOrder + " argument, got " + inputTypes[i]); } }