Java Code Examples for org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo#getParameterObjectInspectors()
The following examples show how to use
org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo#getParameterObjectInspectors() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnionItemsSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length != 1) { throw new UDFArgumentException("One argument expected"); } if (inspectors[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Primitive argument expected, but " + inspectors[0].getTypeName() + " was recieved"); } final PrimitiveObjectInspector inspector = (PrimitiveObjectInspector) inspectors[0]; if (inspector.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BINARY) { throw new UDFArgumentTypeException(0, "Binary argument expected, but " + inspector.getPrimitiveCategory().name() + " was received"); } return createEvaluator(); }
Example 2
Source File: IntersectSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 1) { throw new UDFArgumentException("Please specify at least 1 argument"); } if (inspectors.length > 2) { throw new UDFArgumentTypeException(inspectors.length - 1, "Please specify no more than 2 arguments"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); if (inspectors.length > 1) { ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1); } return new IntersectSketchUDAFEvaluator(); }
Example 3
Source File: SignalNoiseRatioUDAF.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Override public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] OIs = info.getParameterObjectInspectors(); if (OIs.length != 2) { throw new UDFArgumentLengthException("Specify two arguments: " + OIs.length); } if (!HiveUtils.isNumberListOI(OIs[0])) { throw new UDFArgumentTypeException(0, "Only array<number> type argument is acceptable but " + OIs[0].getTypeName() + " was passed as `features`"); } if (!HiveUtils.isListOI(OIs[1]) || !HiveUtils.isIntegerOI( ((ListObjectInspector) OIs[1]).getListElementObjectInspector())) { throw new UDFArgumentTypeException(1, "Only array<int> type argument is acceptable but " + OIs[1].getTypeName() + " was passed as `labels`"); } return new SignalNoiseRatioUDAFEvaluator(); }
Example 4
Source File: DataToItemsSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 6 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length != 2) { throw new UDFArgumentException("Two arguments expected"); } if (inspectors[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Primitive argument expected, but " + inspectors[0].getTypeName() + " was recieved"); } if (inspectors[1].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Primitive argument expected, but " + inspectors[1].getTypeName() + " was recieved"); } final PrimitiveObjectInspector inspector2 = (PrimitiveObjectInspector) inspectors[1]; if (inspector2.getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.INT) { throw new UDFArgumentTypeException(0, "Integer value expected as the second argument, but " + inspector2.getPrimitiveCategory().name() + " was received"); } return createEvaluator(); }
Example 5
Source File: UDAFToOrderedList.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo info) throws SemanticException { @SuppressWarnings("deprecation") TypeInfo[] typeInfo = info.getParameters(); ObjectInspector[] argOIs = info.getParameterObjectInspectors(); if ((typeInfo.length == 1) || (typeInfo.length == 2 && HiveUtils.isConstString(argOIs[1]))) { // sort values by value itself w/o key if (typeInfo[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted for value but " + typeInfo[0].getTypeName() + " was passed as the first parameter."); } } else if ((typeInfo.length == 2) || (typeInfo.length == 3 && HiveUtils.isConstString(argOIs[2]))) { // sort values by key if (typeInfo[1].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(1, "Only primitive type arguments are accepted for key but " + typeInfo[1].getTypeName() + " was passed as the second parameter."); } } else { throw new UDFArgumentTypeException(typeInfo.length - 1, "Number of arguments must be in [1, 3] including constant string for options: " + typeInfo.length); } return new UDAFToOrderedListEvaluator(); }
Example 6
Source File: UnionSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
/** * Perform argument count check and argument type checking, returns an * appropriate evaluator to perform based on input type (which should always * be BINARY sketch). Also check lgK and target HLL type parameters if they are passed in. * * @see org.apache.hadoop.hive.ql.udf.generic.AbstractGenericUDAFResolver * #getEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo) * * @param info The parameter info to validate * @return The GenericUDAFEvaluator to use to compute the function. */ @Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 1) { throw new UDFArgumentException("Please specify at least 1 argument"); } if (inspectors.length > 3) { throw new UDFArgumentTypeException(inspectors.length - 1, "Please specify no more than 3 arguments"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); // Validate second argument if present if (inspectors.length > 1) { ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1); if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[1])) { throw new UDFArgumentTypeException(1, "The second argument must be a constant"); } } // Validate third argument if present if (inspectors.length > 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[2], 2, PrimitiveCategory.STRING); if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[2])) { throw new UDFArgumentTypeException(2, "The third argument must be a constant"); } } return new UnionSketchUDAFEvaluator(); }
Example 7
Source File: DataToSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
/** * Performs argument number and type validation. DataToSketch expects * to receive between one and three arguments. * <ul> * <li>The first (required) is the value to add to the sketch and must be a primitive.</li> * * <li>The second (optional) is the lgK from 4 to 21 (default 12). * This must be an integral value and must be constant.</li> * * <li>The third (optional) is the target HLL type and must be a string 'HLL_4', * 'HLL_6' or 'HLL_8' (default 'HLL_4').</li> * </ul> * * @see org.apache.hadoop.hive.ql.udf.generic.AbstractGenericUDAFResolver * #getEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo) * * @param info Parameter info to validate * @return The GenericUDAFEvaluator that should be used to calculate the function. */ @Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); // Validate the correct number of parameters if (inspectors.length < 1) { throw new UDFArgumentException("Please specify at least 1 argument"); } if (inspectors.length > 3) { throw new UDFArgumentException("Please specify no more than 3 arguments"); } // Validate first parameter type ObjectInspectorValidator.validateCategoryPrimitive(inspectors[0], 0); // Validate second argument if present if (inspectors.length > 1) { ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1); if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[1])) { throw new UDFArgumentTypeException(1, "The second argument must be a constant"); } } // Validate third argument if present if (inspectors.length > 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[2], 2, PrimitiveCategory.STRING); if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[2])) { throw new UDFArgumentTypeException(2, "The third argument must be a constant"); } } return new DataToSketchEvaluator(); }
Example 8
Source File: UnionSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
/** * Perform argument count check and argument type checking, returns an * appropriate evaluator to perform based on input type (which should always * be BINARY sketch). Also check lgK and seed parameters if they are passed in. * * @see org.apache.hadoop.hive.ql.udf.generic.AbstractGenericUDAFResolver * #getEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo) * * @param info The parameter info to validate * @return The GenericUDAFEvaluator to use to compute the function. */ @Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 1) { throw new UDFArgumentException("Please specify at least 1 argument"); } if (inspectors.length > 3) { throw new UDFArgumentTypeException(inspectors.length - 1, "Please specify no more than 3 arguments"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); // Validate second argument if present if (inspectors.length > 1) { ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1); if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[1])) { throw new UDFArgumentTypeException(1, "The second argument must be a constant"); } } // Validate third argument if present if (inspectors.length > 2) { ObjectInspectorValidator.validateIntegralParameter(inspectors[2], 2); if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[2])) { throw new UDFArgumentTypeException(2, "The third argument must be a constant"); } } return new UnionSketchUDAFEvaluator(); }
Example 9
Source File: DataToSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
/** * Performs argument number and type validation. DataToSketch expects * to receive between one and three arguments. * <ul> * <li>The first (required) is the value to add to the sketch and must be a primitive.</li> * * <li>The second (optional) is the lgK from 4 to 21 (default 11). * This must be an integral value and must be constant.</li> * * <li>The third (optional) is the update seed. * </ul> * * @see org.apache.hadoop.hive.ql.udf.generic.AbstractGenericUDAFResolver * #getEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFParameterInfo) * * @param info Parameter info to validate * @return The GenericUDAFEvaluator that should be used to calculate the function. */ @Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); // Validate the correct number of parameters if (inspectors.length < 1) { throw new UDFArgumentException("Please specify at least 1 argument"); } if (inspectors.length > 3) { throw new UDFArgumentException("Please specify no more than 3 arguments"); } // Validate first parameter type ObjectInspectorValidator.validateCategoryPrimitive(inspectors[0], 0); // Validate second argument if present if (inspectors.length > 1) { ObjectInspectorValidator.validateIntegralParameter(inspectors[1], 1); if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[1])) { throw new UDFArgumentTypeException(1, "The second argument must be a constant"); } } // Validate third argument if present if (inspectors.length > 2) { ObjectInspectorValidator.validateIntegralParameter(inspectors[2], 2); if (!ObjectInspectorUtils.isConstantObjectInspector(inspectors[2])) { throw new UDFArgumentTypeException(2, "The third argument must be a constant"); } } return new DataToSketchEvaluator(); }
Example 10
Source File: DataToArrayOfDoublesSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 2) { throw new UDFArgumentException("Expected at least 2 arguments"); } ObjectInspectorValidator.validateCategoryPrimitive(inspectors[0], 0); int numValues = 0; while ((numValues + 1) < inspectors.length) { ObjectInspectorValidator.validateCategoryPrimitive(inspectors[numValues + 1], numValues + 1); final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspectors[numValues + 1]; if (primitiveInspector.getPrimitiveCategory() != PrimitiveCategory.DOUBLE) { break; } numValues++; } if (numValues == 0) { throw new UDFArgumentException("Expected at least 1 double value"); } // nominal number of entries if (inspectors.length > (numValues + 1)) { ObjectInspectorValidator.validateIntegralParameter(inspectors[numValues + 1], numValues + 1); } // sampling probability if (inspectors.length > (numValues + 2)) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[numValues + 2], numValues + 2, PrimitiveCategory.FLOAT); } // there must be nothing after sampling probability if (inspectors.length > (numValues + 3)) { throw new UDFArgumentException("Unexpected argument " + (numValues + 4)); } return new DataToArrayOfDoublesSketchEvaluator(); }
Example 11
Source File: DataToItemsSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if ((inspectors.length != 1) && (inspectors.length != 2)) { throw new UDFArgumentException("One or two arguments expected"); } ObjectInspectorValidator.validateCategoryPrimitive(inspectors[0], 0); if (inspectors.length == 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT); } return createEvaluator(); }
Example 12
Source File: DataToDoublesSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if ((inspectors.length != 1) && (inspectors.length != 2)) { throw new UDFArgumentException("One or two arguments expected"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.DOUBLE); if (inspectors.length == 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT); } return new DataToSketchEvaluator(); }
Example 13
Source File: UnionItemsSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if ((inspectors.length != 1) && (inspectors.length != 2)) { throw new UDFArgumentException("One or two arguments expected"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); if (inspectors.length == 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT); } return createEvaluator(); }
Example 14
Source File: UnionDoublesSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if ((inspectors.length != 1) && (inspectors.length != 2)) { throw new UDFArgumentException("One or two arguments expected"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); if (inspectors.length == 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT); } return new UnionEvaluator(); }
Example 15
Source File: UnionSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if ((inspectors.length != 1) && (inspectors.length != 2)) { throw new UDFArgumentException("One or two arguments expected"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.BINARY); if (inspectors.length == 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT); } return new UnionEvaluator(); }
Example 16
Source File: DataToSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if ((inspectors.length != 1) && (inspectors.length != 2)) { throw new UDFArgumentException("One or two arguments expected"); } ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[0], 0, PrimitiveCategory.FLOAT); if (inspectors.length == 2) { ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.INT); } return new DataToSketchEvaluator(); }
Example 17
Source File: DataToDoubleSummarySketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@SuppressWarnings("resource") @Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { super.getEvaluator(info); final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.DOUBLE); return createEvaluator(); }
Example 18
Source File: DataToSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); if (inspectors.length < 2) { throw new UDFArgumentException("Expected at least 2 arguments"); } ObjectInspectorValidator.validateCategoryPrimitive(inspectors[0], 0); // No validation of the value inspector since it can be anything. // Override this method to validate if needed. // nominal number of entries if (inspectors.length > 2) { ObjectInspectorValidator.validateIntegralParameter(inspectors[2], 2); } // sampling probability if (inspectors.length > 3) { ObjectInspectorValidator.validateCategoryPrimitive(inspectors[3], 3); final PrimitiveObjectInspector primitiveInspector = (PrimitiveObjectInspector) inspectors[3]; if ((primitiveInspector.getPrimitiveCategory() != PrimitiveCategory.FLOAT) && (primitiveInspector.getPrimitiveCategory() != PrimitiveCategory.DOUBLE)) { throw new UDFArgumentTypeException(3, "float or double value expected as parameter 4 but " + primitiveInspector.getPrimitiveCategory().name() + " was received"); } } checkExtraArguments(inspectors); return createEvaluator(); }
Example 19
Source File: DataToDoubleSummaryWithModeSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 5 votes |
@SuppressWarnings("resource") @Override public GenericUDAFEvaluator getEvaluator(final GenericUDAFParameterInfo info) throws SemanticException { super.getEvaluator(info); final ObjectInspector[] inspectors = info.getParameterObjectInspectors(); ObjectInspectorValidator.validateGivenPrimitiveCategory(inspectors[1], 1, PrimitiveCategory.DOUBLE); return createEvaluator(); }
Example 20
Source File: UDAFToOrderedMap.java From incubator-hivemall with Apache License 2.0 | 4 votes |
@Override public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo info) throws SemanticException { @SuppressWarnings("deprecation") final TypeInfo[] typeInfo = info.getParameters(); if (typeInfo.length != 2 && typeInfo.length != 3) { throw new UDFArgumentTypeException(typeInfo.length - 1, "Expecting two or three arguments: " + typeInfo.length); } if (typeInfo[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "Only primitive type arguments are accepted for the key but " + typeInfo[0].getTypeName() + " was passed as parameter 1."); } boolean reverseOrder = false; int size = 0; if (typeInfo.length == 3) { ObjectInspector[] argOIs = info.getParameterObjectInspectors(); ObjectInspector argOI2 = argOIs[2]; if (HiveUtils.isConstBoolean(argOI2)) { reverseOrder = HiveUtils.getConstBoolean(argOI2); } else if (HiveUtils.isConstInteger(argOI2)) { size = HiveUtils.getConstInt(argOI2); if (size == 0) { throw new UDFArgumentException("Map size must be non-zero value: " + size); } reverseOrder = (size > 0); // positive size => top-k } else { throw new UDFArgumentTypeException(2, "The third argument must be boolean or int type: " + typeInfo[2].getTypeName()); } } if (reverseOrder) { // descending if (size == 0) { return new ReverseOrderedMapEvaluator(); } else { return new TopKOrderedMapEvaluator(); } } else { // ascending if (size == 0) { return new NaturalOrderedMapEvaluator(); } else { return new TailKOrderedMapEvaluator(); } } }