Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils#isConstantObjectInspector()
The following examples show how to use
org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils#isConstantObjectInspector() .
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: ST_Bin.java From spatial-framework-for-hadoop with Apache License 2.0 | 6 votes |
@Override public ObjectInspector initialize(ObjectInspector[] OIs) throws UDFArgumentException { if (OIs.length != 2) { throw new UDFArgumentException("Function takes exactly 2 arguments"); } if (OIs[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentException("Argument 0 must be a number - got: " + OIs[0].getCategory()); } oiBinSize = (PrimitiveObjectInspector)OIs[0]; if (!EnumSet.of(PrimitiveCategory.DECIMAL,PrimitiveCategory.DOUBLE,PrimitiveCategory.INT,PrimitiveCategory.LONG,PrimitiveCategory.SHORT, PrimitiveCategory.FLOAT).contains(oiBinSize.getPrimitiveCategory())) { throw new UDFArgumentException("Argument 0 must be a number - got: " + oiBinSize.getPrimitiveCategory()); } geomHelper = HiveGeometryOIHelper.create(OIs[1], 1); binSizeIsConstant = ObjectInspectorUtils.isConstantObjectInspector(OIs[0]); return PrimitiveObjectInspectorFactory.javaLongObjectInspector; }
Example 2
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Nullable public static String[] getConstStringArray(@Nonnull final ObjectInspector oi) throws UDFArgumentException { if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) { throw new UDFArgumentException("argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } ConstantObjectInspector constOI = (ConstantObjectInspector) oi; if (constOI.getCategory() != Category.LIST) { throw new UDFArgumentException( "argument must be an array: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } final List<?> lst = (List<?>) constOI.getWritableConstantValue(); if (lst == null) { return null; } final int size = lst.size(); final String[] ary = new String[size]; for (int i = 0; i < size; i++) { Object o = lst.get(i); if (o != null) { ary[i] = o.toString(); } } return ary; }
Example 3
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public static ConstantObjectInspector asConstantObjectInspector( @Nonnull final ObjectInspector oi) throws UDFArgumentException { if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) { throw new UDFArgumentException("argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } return (ConstantObjectInspector) oi; }
Example 4
Source File: HiveGeometryOIHelper.java From spatial-framework-for-hadoop with Apache License 2.0 | 5 votes |
private HiveGeometryOIHelper(ObjectInspector oi, int argIndex) { this.oi = (PrimitiveObjectInspector)oi; this.argIndex = argIndex; // constant geometries only need to be processed once and can // be optimized in certain operations isConstant = ObjectInspectorUtils.isConstantObjectInspector(oi); }
Example 5
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 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 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 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 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 9
Source File: MapRouletteUDF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { if (argOIs.length != 1 && argOIs.length != 2) { throw new UDFArgumentLengthException( "Expected exactly one argument for map_roulette: " + argOIs.length); } if (argOIs[0].getCategory() != ObjectInspector.Category.MAP) { throw new UDFArgumentTypeException(0, "Only map type argument is accepted but got " + argOIs[0].getTypeName()); } this.mapOI = HiveUtils.asMapOI(argOIs[0]); this.valueOI = HiveUtils.asDoubleCompatibleOI(mapOI.getMapValueObjectInspector()); if (argOIs.length == 2) { ObjectInspector argOI1 = argOIs[1]; if (HiveUtils.isIntegerOI(argOI1) == false) { throw new UDFArgumentException( "The second argument of map_roulette must be integer type: " + argOI1.getTypeName()); } if (ObjectInspectorUtils.isConstantObjectInspector(argOI1)) { long seed = HiveUtils.getAsConstLong(argOI1); this._rand = new Random(seed); // fixed seed } else { this.seedOI = HiveUtils.asLongCompatibleOI(argOI1); } } else { this._rand = new Random(); // random seed } return mapOI.getMapKeyObjectInspector(); }
Example 10
Source File: StoptagsExcludeUDF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { if (argOIs.length != 1 && argOIs.length != 2) { throw new UDFArgumentException( "stoptags_exclude(array<string> tags, [, const string lang='ja']) takes one or two arguments: " + argOIs.length); } if (!HiveUtils.isStringListOI(argOIs[0])) { throw new UDFArgumentException( "stoptags_exclude(array<string> tags, [, const string lang='ja']) expects array<string> for the first argument : " + argOIs[0].getTypeName()); } this.tagsOI = HiveUtils.asListOI(argOIs[0]); if (argOIs.length == 2) { if (!HiveUtils.isConstString(argOIs[1])) { throw new UDFArgumentException( "stoptags_exclude(array<string> tags, [, const string lang='ja']) expects const string for the second argument: " + argOIs[1].getTypeName()); } String lang = HiveUtils.getConstString(argOIs[1]); if (!"ja".equalsIgnoreCase(lang)) { throw new UDFArgumentException("Unsupported lang: " + lang); } } this.stopTags = STOPTAGS_JA; if (ObjectInspectorUtils.isConstantObjectInspector(tagsOI)) { String[] excludeTags = HiveUtils.getConstStringArray(tagsOI); this.result = getStoptags(stopTags, excludeTags); } return ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.javaStringObjectInspector); }
Example 11
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nullable public static double[] getConstDoubleArray(@Nonnull final ObjectInspector oi) throws UDFArgumentException { if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) { throw new UDFArgumentException("argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } ConstantObjectInspector constOI = (ConstantObjectInspector) oi; if (constOI.getCategory() != Category.LIST) { throw new UDFArgumentException( "argument must be an array: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } StandardConstantListObjectInspector listOI = (StandardConstantListObjectInspector) constOI; PrimitiveObjectInspector elemOI = HiveUtils.asDoubleCompatibleOI(listOI.getListElementObjectInspector()); final List<?> lst = listOI.getWritableConstantValue(); if (lst == null) { return null; } final int size = lst.size(); final double[] ary = new double[size]; for (int i = 0; i < size; i++) { Object o = lst.get(i); if (o == null) { ary[i] = Double.NaN; } else { ary[i] = PrimitiveObjectInspectorUtils.getDouble(o, elemOI); } } return ary; }
Example 12
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Nullable public static <T extends Writable> T getConstValue(@Nonnull final ObjectInspector oi) throws UDFArgumentException { if (!ObjectInspectorUtils.isConstantObjectInspector(oi)) { throw new UDFArgumentException("argument must be a constant value: " + TypeInfoUtils.getTypeInfoFromObjectInspector(oi)); } ConstantObjectInspector constOI = (ConstantObjectInspector) oi; Object v = constOI.getWritableConstantValue(); return (T) v; }
Example 13
Source File: EachTopKUDTF.java From incubator-hivemall with Apache License 2.0 | 4 votes |
@Override public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { final int numArgs = argOIs.length; if (numArgs < 4) { throw new UDFArgumentException( "each_top_k(int K, Object group, double cmpKey, *) takes at least 4 arguments: " + numArgs); } this.argOIs = argOIs; this._constantK = ObjectInspectorUtils.isConstantObjectInspector(argOIs[0]); if (_constantK) { final int k = HiveUtils.getAsConstInt(argOIs[0]); if (k == 0) { throw new UDFArgumentException("k should not be 0"); } this._queue = getQueue(k); } else { this.kOI = HiveUtils.asIntCompatibleOI(argOIs[0]); this._prevK = 0; } this.prevGroupOI = ObjectInspectorUtils.getStandardObjectInspector(argOIs[1], ObjectInspectorCopyOption.DEFAULT); this.cmpKeyOI = HiveUtils.asDoubleCompatibleOI(argOIs[2]); this._tuple = null; this._previousGroup = null; final ArrayList<String> fieldNames = new ArrayList<String>(numArgs); final ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(numArgs); fieldNames.add("rank"); fieldOIs.add(PrimitiveObjectInspectorFactory.writableIntObjectInspector); fieldNames.add("key"); fieldOIs.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); for (int i = 3; i < numArgs; i++) { fieldNames.add("c" + (i - 2)); ObjectInspector rawOI = argOIs[i]; ObjectInspector retOI = ObjectInspectorUtils.getStandardObjectInspector(rawOI, ObjectInspectorCopyOption.DEFAULT); fieldOIs.add(retOI); } return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); }
Example 14
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 4 votes |
public static boolean isConstBoolean(@Nonnull final ObjectInspector oi) { return ObjectInspectorUtils.isConstantObjectInspector(oi) && isBooleanOI(oi); }
Example 15
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 4 votes |
public static boolean isConstInteger(@Nonnull final ObjectInspector oi) { return ObjectInspectorUtils.isConstantObjectInspector(oi) && isIntegerOI(oi); }
Example 16
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 4 votes |
public static boolean isConstInt(@Nonnull final ObjectInspector oi) { return ObjectInspectorUtils.isConstantObjectInspector(oi) && isIntOI(oi); }
Example 17
Source File: DataToSketchUDAF.java From incubator-datasketches-hive with Apache License 2.0 | 4 votes |
/** * Performs argument number and type validation. DataToSketch expects * to receive between one and four 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 sketch size to use. This must be an integral value * and must be constant.</li> * * <li>The third (optional) is the sampling probability and is a floating point value between * 0.0 and 1.0. It must be a constant</li> * * <li>The fourth (optional) is an update seed. * It must be an integral value and must be constant.</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[] parameters = info.getParameterObjectInspectors(); // Validate the correct number of parameters if (parameters.length < 1) { throw new UDFArgumentException("Please specify at least 1 argument"); } if (parameters.length > 4) { throw new UDFArgumentException("Please specify no more than 4 arguments"); } // Validate first parameter type ObjectInspectorValidator.validateCategoryPrimitive(parameters[0], 0); // Validate second argument if present if (parameters.length > 1) { ObjectInspectorValidator.validateIntegralParameter(parameters[1], 1); if (!ObjectInspectorUtils.isConstantObjectInspector(parameters[1])) { throw new UDFArgumentTypeException(1, "The second argument must be a constant"); } } // Validate third argument if present if (parameters.length > 2) { ObjectInspectorValidator.validateFloatingPointParameter(parameters[2], 2); if (!ObjectInspectorUtils.isConstantObjectInspector(parameters[2])) { throw new UDFArgumentTypeException(2, "The third argument must be a constant"); } } // Validate fourth argument if present if (parameters.length > 3) { ObjectInspectorValidator.validateIntegralParameter(parameters[3], 3); if (!ObjectInspectorUtils.isConstantObjectInspector(parameters[3])) { throw new UDFArgumentTypeException(3, "The fourth argument must be a constant"); } } return new DataToSketchEvaluator(); }
Example 18
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 4 votes |
public static boolean isConstString(@Nonnull final ObjectInspector oi) { return ObjectInspectorUtils.isConstantObjectInspector(oi) && isStringOI(oi); }
Example 19
Source File: HiveUtils.java From incubator-hivemall with Apache License 2.0 | 4 votes |
public static boolean isConstListOI(@Nonnull final ObjectInspector oi) { return ObjectInspectorUtils.isConstantObjectInspector(oi) && isListOI(oi); }