@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { NTileBuffer rb = (NTileBuffer) agg; if (rb.numBuckets == null) { rb.numBuckets = PrimitiveObjectInspectorUtils.getInt(parameters[0], inputOI); } rb.numRows++; }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { NTileBuffer rb = (NTileBuffer) agg; if (rb.numBuckets == null) { rb.numBuckets = PrimitiveObjectInspectorUtils.getInt(parameters[0], inputOI); } rb.numRows++; }
@Override public Object convert(Object input) { if (input == null) { return null; } try { return outputOI.set(r, PrimitiveObjectInspectorUtils.getInt(input, inputOI)); } catch (NumberFormatException e) { return null; } } }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 1); Object p = parameters[0]; if (p != null) { BitmapAgg myagg = (BitmapAgg) agg; try { int row = PrimitiveObjectInspectorUtils.getInt(p, inputOI); addBitmap(row, myagg); } catch (NumberFormatException e) { LOG.warn(getClass().getSimpleName() + " " + StringUtils.stringifyException(e)); } } }
@Override public Object evaluate(DeferredObject[] arguments) throws HiveException { // groupingId = PrimitiveObjectInspectorUtils.getInt(arguments[0].get(), groupingIdOI); // Check that the bit at the given index is '1' or '0' byteWritable.set((byte) ((PrimitiveObjectInspectorUtils.getInt(arguments[0].get(), groupingIdOI) >> index) & 1)); return byteWritable; }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { NumericStatsAgg myagg = (NumericStatsAgg) agg; if (myagg.numDV == null) { int numVectors = parameters[1] == null ? 0 : PrimitiveObjectInspectorUtils.getInt(parameters[1], numVectorsOI); if (numVectors > MAX_BIT_VECTORS) { throw new HiveException("The maximum allowed value for number of bit vectors " + " is " + MAX_BIT_VECTORS + ", but was passed " + numVectors + " bit vectors"); } myagg.initNDVEstimator(numVectors); } //Update null counter if a null value is seen if (parameters[0] == null) { myagg.countNulls++; } else { try { myagg.update(parameters[0], inputOI); } catch (NumberFormatException e) { if (!warned) { warned = true; LOG.warn(getClass().getSimpleName() + " " + StringUtils.stringifyException(e)); LOG.warn(getClass().getSimpleName() + " ignoring similar exceptions."); } } } }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 2); if(parameters[0] == null || parameters[1] == null) { return; } StdAgg myagg = (StdAgg) agg; // Parse out the number of histogram bins only once, if we haven't already done // so before. We need at least 2 bins; otherwise, there is no point in creating // a histogram. if(!myagg.histogram.isReady()) { int nbins = PrimitiveObjectInspectorUtils.getInt(parameters[1], nbinsOI); if(nbins < 2) { throw new HiveException(getClass().getSimpleName() + " needs nbins to be at least 2," + " but you supplied " + nbins + "."); } // allocate memory for the histogram bins myagg.histogram.allocate(nbins); } // Process the current data point double v = PrimitiveObjectInspectorUtils.getDouble(parameters[0], inputOI); myagg.histogram.add(v); }
/** * Get the byte value out of a primitive object. Note that * NullPointerException will be thrown if o is null. Note that * NumberFormatException will be thrown if o is not a valid number. */ public static byte getByte(Object o, PrimitiveObjectInspector oi) { byte result; switch (oi.getPrimitiveCategory()) { case DECIMAL: { HiveDecimal dec = ((HiveDecimalObjectInspector) oi) .getPrimitiveJavaObject(o); if (!dec.isByte()) { throw new NumberFormatException(); } result = dec.byteValue(); } break; default: // For all other data types, use int conversion. At some point, we should have all // conversions make sure the value fits. return (byte) getInt(o, oi); } return result; }
/** * Get the short value out of a primitive object. Note that * NullPointerException will be thrown if o is null. Note that * NumberFormatException will be thrown if o is not a valid number. */ public static short getShort(Object o, PrimitiveObjectInspector oi) { short result; switch (oi.getPrimitiveCategory()) { case DECIMAL: { HiveDecimal dec = ((HiveDecimalObjectInspector) oi) .getPrimitiveJavaObject(o); if (!dec.isShort()) { throw new NumberFormatException(); } result = dec.shortValue(); } break; default: // For all other data types, use int conversion. At some point, we should have all // conversions make sure the value fits. return (short) getInt(o, oi); } return result; }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 2); if(parameters[0] == null || parameters[1] == null) { return; } StdAgg myagg = (StdAgg) agg; // Parse out the number of histogram bins only once, if we haven't already done // so before. We need at least 2 bins; otherwise, there is no point in creating // a histogram. if(!myagg.histogram.isReady()) { int nbins = PrimitiveObjectInspectorUtils.getInt(parameters[1], nbinsOI); if(nbins < 2) { throw new HiveException(getClass().getSimpleName() + " needs nbins to be at least 2," + " but you supplied " + nbins + "."); } // allocate memory for the histogram bins myagg.histogram.allocate(nbins); } // Process the current data point double v = PrimitiveObjectInspectorUtils.getDouble(parameters[0], inputOI); myagg.histogram.add(v); }
partition == null ? -1 : PrimitiveObjectInspectorUtils.getInt(partition, MetadataColumn.PARTITION.getObjectInspector());
@Override public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { super.init(m, parameters); // init input object inspectors if (m == Mode.PARTIAL1 || m == Mode.COMPLETE) { inputOI = (PrimitiveObjectInspector) parameters[0]; quantiles = getQuantileArray((ConstantObjectInspector)parameters[1]); if(parameters.length > 2) { nbins = PrimitiveObjectInspectorUtils.getInt( ((ConstantObjectInspector) parameters[2]).getWritableConstantValue(), (PrimitiveObjectInspector)parameters[2]); } } else { loi = (StandardListObjectInspector) parameters[0]; } // Init output object inspectors. // // The return type for a partial aggregation is still a list of doubles, as in // GenericUDAFHistogramNumeric, but we add on the percentile values requested to the // end, and handle serializing/deserializing before we pass things on to the parent // method. // The return type for FINAL and COMPLETE is a full aggregation result, which is also // a list of doubles return ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { NumericStatsAgg myagg = (NumericStatsAgg) agg; if (myagg.numDV == null) { String func = null; int numVectors = 0; // func may be null when GBY op is closing. // see mvn test -Dtest=TestMiniTezCliDriver -Dqfile=explainuser_3.q // original behavior is to create FMSketch func = parameters[1] == null ? "fm" : PrimitiveObjectInspectorUtils.getString( parameters[1], funcOI); if (parameters.length == 3) { numVectors = parameters[2] == null ? 0 : PrimitiveObjectInspectorUtils.getInt( parameters[2], numVectorsOI); if (numVectors > MAX_BIT_VECTORS) { throw new HiveException("The maximum allowed value for number of bit vectors " + " is " + MAX_BIT_VECTORS + ", but was passed " + numVectors + " bit vectors"); } } myagg.initNDVEstimator(func, numVectors); } // Update null counter if a null value is seen if (parameters[0] == null) { myagg.countNulls++; } else { myagg.update(parameters[0], inputOI); } }
parameters[1], funcOI); if (parameters.length > 2) { numVectors = PrimitiveObjectInspectorUtils.getInt(parameters[2], numVectorsOI); if (numVectors > MAX_BIT_VECTORS) { throw new HiveException("The maximum allowed value for number of bit vectors " + " is "
@Override public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { super.init(m, parameters); // init input object inspectors if (m == Mode.PARTIAL1 || m == Mode.COMPLETE) { inputOI = (PrimitiveObjectInspector) parameters[0]; quantiles = getQuantileArray((ConstantObjectInspector)parameters[1]); if(parameters.length > 2) { nbins = PrimitiveObjectInspectorUtils.getInt( ((ConstantObjectInspector) parameters[2]).getWritableConstantValue(), (PrimitiveObjectInspector)parameters[2]); } } else { loi = (StandardListObjectInspector) parameters[0]; } // Init output object inspectors. // // The return type for a partial aggregation is still a list of doubles, as in // GenericUDAFHistogramNumeric, but we add on the percentile values requested to the // end, and handle serializing/deserializing before we pass things on to the parent // method. // The return type for FINAL and COMPLETE is a full aggregation result, which is a // single double value if (m == Mode.PARTIAL1 || m == Mode.PARTIAL2) { return ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); } else { return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; } }
@Override public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { super.init(m, parameters); // init input object inspectors if (m == Mode.PARTIAL1 || m == Mode.COMPLETE) { inputOI = (PrimitiveObjectInspector) parameters[0]; quantiles = getQuantileArray((ConstantObjectInspector)parameters[1]); if(parameters.length > 2) { nbins = PrimitiveObjectInspectorUtils.getInt( ((ConstantObjectInspector) parameters[2]).getWritableConstantValue(), (PrimitiveObjectInspector)parameters[2]); } } else { loi = (StandardListObjectInspector) parameters[0]; } // Init output object inspectors. // // The return type for a partial aggregation is still a list of doubles, as in // GenericUDAFHistogramNumeric, but we add on the percentile values requested to the // end, and handle serializing/deserializing before we pass things on to the parent // method. // The return type for FINAL and COMPLETE is a full aggregation result, which is also // a list of doubles return ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); }
@Override public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { super.init(m, parameters); // init input object inspectors if (m == Mode.PARTIAL1 || m == Mode.COMPLETE) { inputOI = (PrimitiveObjectInspector) parameters[0]; quantiles = getQuantileArray((ConstantObjectInspector)parameters[1]); if(parameters.length > 2) { nbins = PrimitiveObjectInspectorUtils.getInt( ((ConstantObjectInspector) parameters[2]).getWritableConstantValue(), (PrimitiveObjectInspector)parameters[2]); } } else { loi = (StandardListObjectInspector) parameters[0]; } // Init output object inspectors. // // The return type for a partial aggregation is still a list of doubles, as in // GenericUDAFHistogramNumeric, but we add on the percentile values requested to the // end, and handle serializing/deserializing before we pass things on to the parent // method. // The return type for FINAL and COMPLETE is a full aggregation result, which is a // single double value if (m == Mode.PARTIAL1 || m == Mode.PARTIAL2) { return ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); } else { return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector; } }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 2) { throw new UDFArgumentLengthException( "grouping() requires at least 2 argument, got " + arguments.length); } if (arguments[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The first argument to grouping() must be primitive"); } PrimitiveObjectInspector arg1OI = (PrimitiveObjectInspector) arguments[0]; // INT can happen in cases where grouping() is used without grouping sets, in all other cases it should be LONG. if (!(arg1OI.getPrimitiveCategory() == PrimitiveCategory.INT || arg1OI.getPrimitiveCategory() == PrimitiveCategory.LONG)) { throw new UDFArgumentTypeException(0, "The first argument to grouping() must be an int/long. Got: " + arg1OI.getPrimitiveCategory()); } groupingIdOI = arg1OI; indices = new int[arguments.length - 1]; for (int i = 1; i < arguments.length; i++) { PrimitiveObjectInspector arg2OI = (PrimitiveObjectInspector) arguments[i]; if (!(arg2OI instanceof ConstantObjectInspector)) { throw new UDFArgumentTypeException(i, "Must be a constant. Got: " + arg2OI.getClass().getSimpleName()); } indices[i - 1] = PrimitiveObjectInspectorUtils .getInt(((ConstantObjectInspector) arguments[i]).getWritableConstantValue(), arg2OI); } return PrimitiveObjectInspectorFactory.writableLongObjectInspector; }
Object maxValue = this.maxValueConverterOI.convert(arguments[2].get()); int numBuckets = PrimitiveObjectInspectorUtils.getInt(arguments[3].get(), (PrimitiveObjectInspector) this.objectInspectors[3]);
int intVal = PrimitiveObjectInspectorUtils.getInt(arguments[intervalArg1Idx].get(), inputOIs[intervalArg1Idx]); Date dt1 = PrimitiveObjectInspectorUtils.getDate(