Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils#getLong()

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils#getLong() . 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: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static long[] asLongArray(@Nullable final Object argObj,
        @Nonnull final ListObjectInspector listOI, @Nonnull PrimitiveObjectInspector elemOI) {
    if (argObj == null) {
        return null;
    }
    final int length = listOI.getListLength(argObj);
    final long[] ary = new long[length];
    for (int i = 0; i < length; i++) {
        Object o = listOI.getListElement(argObj, i);
        if (o == null) {
            continue;
        }
        ary[i] = PrimitiveObjectInspectorUtils.getLong(o, elemOI);
    }
    return ary;
}
 
Example 2
Source File: VectorAddUDF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nonnull
private List<Long> evaluateLong(@Nonnull final Object vecX, @Nonnull final Object vecY,
        @Nonnegative final int size) {
    final Long[] arr = new Long[size];
    for (int i = 0; i < size; i++) {
        Object x = xOI.getListElement(vecX, i);
        Object y = yOI.getListElement(vecY, i);
        if (x == null || y == null) {
            continue;
        }
        long xd = PrimitiveObjectInspectorUtils.getLong(x, xElemOI);
        long yd = PrimitiveObjectInspectorUtils.getLong(y, yElemOI);
        long v = xd + yd;
        arr[i] = Long.valueOf(v);
    }
    return Arrays.asList(arr);
}
 
Example 3
Source File: IntersectSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
@Override
public void iterate(final @SuppressWarnings("deprecation") AggregationBuffer buf,
    final Object[] data) throws HiveException {
  if (data[0] == null) { return; }
  final IntersectionState state = (IntersectionState) buf;
  if (!state.isInitialized()) {
    long seed = DEFAULT_UPDATE_SEED;
    if (seedObjectInspector != null) {
      seed = PrimitiveObjectInspectorUtils.getLong(data[1], seedObjectInspector);
    }
    state.init(seed);
  }
  final byte[] serializedSketch = (byte[]) inputObjectInspector.getPrimitiveJavaObject(data[0]);
  if (serializedSketch == null) { return; }
  state.update(Memory.wrap(serializedSketch));
}
 
Example 4
Source File: DataToSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 6 votes vote down vote up
private void initializeState(final UnionState state, final Object[] parameters) {
  int sketchSize = DEFAULT_NOMINAL_ENTRIES;
  if (nominalEntriesObjectInspector != null) {
    sketchSize = PrimitiveObjectInspectorUtils.getInt(parameters[1], nominalEntriesObjectInspector);
  }
  float samplingProbability = UnionState.DEFAULT_SAMPLING_PROBABILITY;
  if (samplingProbabilityObjectInspector != null) {
    samplingProbability = PrimitiveObjectInspectorUtils.getFloat(parameters[2],
        samplingProbabilityObjectInspector);
  }
  long seed = DEFAULT_UPDATE_SEED;
  if (seedObjectInspector != null) {
    seed = PrimitiveObjectInspectorUtils.getLong(parameters[3], seedObjectInspector);
  }
  state.init(sketchSize, samplingProbability, seed);
}
 
Example 5
Source File: GenerateSeriesUDTF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
private void generateLongSeries(@Nonnull final Object[] args) throws HiveException {
    final long start, end;
    long step = 1L;
    switch (args.length) {
        case 3:
            step = PrimitiveObjectInspectorUtils.getLong(args[2], stepOI);
            if (step == 0) {
                throw new UDFArgumentException("Step MUST NOT be zero");
            }
            // fall through
        case 2:
            start = PrimitiveObjectInspectorUtils.getLong(args[0], startOI);
            end = PrimitiveObjectInspectorUtils.getLong(args[1], endOI);
            break;
        default:
            throw new UDFArgumentException("Expected number of arguments: " + args.length);
    }

    final LongWritable row0 = new LongWritable();
    row[0] = row0;
    if (step > 0) {
        for (long i = start; i <= end; i += step) {
            row0.set(i);
            forward(row);
        }
    } else {
        for (long i = start; i >= end; i += step) {
            row0.set(i);
            forward(row);
        }
    }
}
 
Example 6
Source File: UnionSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
private void initializeState(final UnionState state, final Object[] parameters) {
  int lgK = DEFAULT_LG_K;
  if (lgKInspector_ != null) {
    lgK = PrimitiveObjectInspectorUtils.getInt(parameters[1], lgKInspector_);
  }
  long seed = DEFAULT_UPDATE_SEED;
  if (seedInspector_ != null) {
    seed = PrimitiveObjectInspectorUtils.getLong(parameters[2], seedInspector_);
  }
  state.init(lgK, seed);
}
 
Example 7
Source File: DataToSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
private void initializeState(final State state, final Object[] parameters) {
  int lgK = DEFAULT_LG_K;
  if (lgKInspector_ != null) {
    lgK = PrimitiveObjectInspectorUtils.getInt(parameters[1], lgKInspector_);
  }
  long seed = DEFAULT_UPDATE_SEED;
  if (seedInspector_ != null) {
    seed = PrimitiveObjectInspectorUtils.getLong(parameters[2], seedInspector_);
  }
  state.init(lgK, seed);
}
 
Example 8
Source File: UnionSketchUDAF.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
private void initializeState(final UnionState state, final Object[] parameters) {
  int nominalEntries = DEFAULT_NOMINAL_ENTRIES;
  if (nominalEntriesObjectInspector != null) {
    nominalEntries = PrimitiveObjectInspectorUtils.getInt(parameters[1], nominalEntriesObjectInspector);
  }
  long seed = DEFAULT_UPDATE_SEED;
  if (seedObjectInspector != null) {
    seed = PrimitiveObjectInspectorUtils.getLong(parameters[2], seedObjectInspector);
  }
  state.init(nominalEntries, seed);
}
 
Example 9
Source File: ST_BinEnvelope.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public Object evaluate(DeferredObject[] args) throws HiveException {
	double binSize = PrimitiveObjectInspectorUtils.getDouble(args[0].get(), oiBinSize);
	
	
	if (!binSizeIsConstant || bins == null) {
		bins = new BinUtils(binSize);
	} 
			
	Envelope env = new Envelope();
	
	if (oiBinId != null) {
		// argument 1 is a number, attempt to get the envelope with bin ID
		if (args[1].get() == null) {
			// null bin ID argument usually means the source point was null or failed to parse
			return null; 
		}
		
		long binId = PrimitiveObjectInspectorUtils.getLong(args[1].get(), oiBinId);
		bins.queryEnvelope(binId, env);
	} else {
		// argument 1 is a geometry, attempt to get the envelope with a point
		OGCPoint point = binPoint.getPoint(args);
		
		if (point == null) {
			return null;
		}
		
		bins.queryEnvelope(point.X(), point.Y(), env);
	}

	return GeometryUtils.geometryToEsriShapeBytesWritable(env, 0, OGCType.ST_POLYGON);
}
 
Example 10
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
public static long getLong(@Nullable Object o, @Nonnull PrimitiveObjectInspector oi) {
    if (o == null) {
        return 0L;
    }
    return PrimitiveObjectInspectorUtils.getLong(o, oi);
}
 
Example 11
Source File: SignalNoiseRatioUDAF.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Override
public void merge(@SuppressWarnings("deprecation") AggregationBuffer agg, Object other)
        throws HiveException {
    if (other == null) {
        return;
    }

    final SignalNoiseRatioAggregationBuffer myAgg = (SignalNoiseRatioAggregationBuffer) agg;

    final List<?> counts =
            countsOI.getList(structOI.getStructFieldData(other, countsField));
    final List<?> means = meansOI.getList(structOI.getStructFieldData(other, meansField));
    final List<?> variances =
            variancesOI.getList(structOI.getStructFieldData(other, variancesField));

    final int nClasses = counts.size();
    final int nFeatures = meanListOI.getListLength(means.get(0));
    if (myAgg.counts == null) {
        myAgg.init(nClasses, nFeatures);
    }

    for (int i = 0; i < nClasses; i++) {
        final long n = myAgg.counts[i];
        final long cnt = PrimitiveObjectInspectorUtils.getLong(counts.get(i), countOI);

        // no need to merge class `i`
        if (cnt == 0) {
            continue;
        }

        final List<?> mean = meanListOI.getList(means.get(i));
        final List<?> variance = varianceListOI.getList(variances.get(i));

        myAgg.counts[i] += cnt;
        for (int j = 0; j < nFeatures; j++) {
            final double meanN = myAgg.means[i][j];
            final double meanM =
                    PrimitiveObjectInspectorUtils.getDouble(mean.get(j), meanElemOI);
            final double varianceN = myAgg.variances[i][j];
            final double varianceM = PrimitiveObjectInspectorUtils.getDouble(
                variance.get(j), varianceElemOI);

            if (n == 0) {// only assign `other` into `myAgg`
                myAgg.means[i][j] = meanM;
                myAgg.variances[i][j] = varianceM;
            } else {
                // merge by Chan's method
                // http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf
                myAgg.means[i][j] = (n * meanN + cnt * meanM) / (double) (n + cnt);
                myAgg.variances[i][j] = (varianceN * (n - 1) + varianceM * (cnt - 1)
                        + Math.pow(meanN - meanM, 2) * n * cnt / (n + cnt)) / (n + cnt - 1);
            }
        }
    }
}