Java Code Examples for org.apache.hadoop.hive.serde2.io.DoubleWritable#get()

The following examples show how to use org.apache.hadoop.hive.serde2.io.DoubleWritable#get() . 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: WeightVotedAvgUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
public boolean iterate(@Nullable DoubleWritable o) {
    if (o == null) {
        return true;
    }
    if (partial == null) {
        this.partial = new PartialResult();
        partial.init();
    }
    double w = o.get();
    if (w > 0) {
        partial.positiveSum += w;
        partial.positiveCnt++;
    } else if (w < 0) {
        partial.negativeSum += w;
        partial.negativeCnt++;
    }
    return true;
}
 
Example 2
Source File: VotedAvgUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
public boolean iterate(@Nullable DoubleWritable o) {
    if (o == null) {
        return true;
    }
    if (partial == null) {
        this.partial = new PartialResult();
        partial.init();
    }
    double w = o.get();
    if (w > 0) {
        partial.positiveSum += w;
        partial.positiveCnt++;
    } else if (w < 0) {
        partial.negativeSum += w;
        partial.negativeCnt++;
    }
    return true;
}
 
Example 3
Source File: HiveUtils.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
public static double asJavaDouble(@Nullable final Object o) {
    if (o == null) {
        throw new IllegalArgumentException();
    }
    if (o instanceof Double) {
        return ((Double) o).doubleValue();
    }
    if (o instanceof LazyDouble) {
        DoubleWritable d = ((LazyDouble) o).getWritableObject();
        return d.get();
    }
    if (o instanceof DoubleWritable) {
        return ((DoubleWritable) o).get();
    }
    String s = o.toString();
    return Double.parseDouble(s);
}
 
Example 4
Source File: TreePredictUDFv1Test.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
private static double evalPredict(RegressionTree tree, double[] x)
        throws HiveException, IOException {
    String opScript = tree.predictOpCodegen(StackMachine.SEP);
    debugPrint(opScript);

    TreePredictUDFv1 udf = new TreePredictUDFv1();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                PrimitiveObjectInspectorFactory.javaIntObjectInspector,
                PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaDoubleObjectInspector),
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, false)});
    DeferredObject[] arguments = new DeferredObject[] {new DeferredJavaObject("model_id#1"),
            new DeferredJavaObject(ModelType.opscode.getId()), new DeferredJavaObject(opScript),
            new DeferredJavaObject(ArrayUtils.toList(x)), new DeferredJavaObject(false)};

    DoubleWritable result = (DoubleWritable) udf.evaluate(arguments);
    udf.close();
    return result.get();
}
 
Example 5
Source File: TreePredictUDFTest.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
private static double evalPredict(RegressionTree tree, double[] x)
        throws HiveException, IOException {
    byte[] b = tree.serialize(true);
    byte[] encoded = Base91.encode(b);
    Text model = new Text(encoded);

    TreePredictUDF udf = new TreePredictUDF();
    udf.initialize(
        new ObjectInspector[] {PrimitiveObjectInspectorFactory.javaStringObjectInspector,
                PrimitiveObjectInspectorFactory.writableStringObjectInspector,
                ObjectInspectorFactory.getStandardListObjectInspector(
                    PrimitiveObjectInspectorFactory.javaDoubleObjectInspector),
                ObjectInspectorUtils.getConstantObjectInspector(
                    PrimitiveObjectInspectorFactory.javaBooleanObjectInspector, false)});
    DeferredObject[] arguments = new DeferredObject[] {new DeferredJavaObject("model_id#1"),
            new DeferredJavaObject(model), new DeferredJavaObject(ArrayUtils.toList(x)),
            new DeferredJavaObject(false)};

    DoubleWritable result = (DoubleWritable) udf.evaluate(arguments);
    udf.close();
    return result.get();
}
 
Example 6
Source File: ST_Point.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(DoubleWritable x, DoubleWritable y, DoubleWritable z, DoubleWritable m) {
	if (x == null || y == null) {
		//LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}
	try {
		Point stPt = new Point(x.get(), y.get());
		if (z != null)
			stPt.setZ(z.get());
		if (m != null)
			stPt.setM(m.get());
		BytesWritable ret = GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(stPt, null));
		return ret;
	} catch (Exception e) {
	    //LogUtils.Log_InternalError(LOG, "ST_Point: " + e);
	    return null;
	}
}
 
Example 7
Source File: UDFMathCosineSimilarityTest.java    From hive-third-functions with Apache License 2.0 5 votes vote down vote up
public Double getResult(Map<String, Double> leftMap, Map<String, Double> rightMap) throws HiveException {
    UDFMathCosineSimilarity udf = new UDFMathCosineSimilarity();

    ObjectInspector leftMapOI = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaDoubleObjectInspector);
    ObjectInspector rightMapOI = ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaDoubleObjectInspector);
    ObjectInspector[] arguments = {leftMapOI, rightMapOI};
    udf.initialize(arguments);

    GenericUDF.DeferredObject leftMapObj = new GenericUDF.DeferredJavaObject(leftMap);
    GenericUDF.DeferredObject rightMapObj = new GenericUDF.DeferredJavaObject(rightMap);
    GenericUDF.DeferredObject[] args = {leftMapObj, rightMapObj};
    DoubleWritable output = (DoubleWritable) udf.evaluate(args);
    return output == null ? null : output.get();
}
 
Example 8
Source File: KPAPredictUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public void merge(@SuppressWarnings("deprecation") AggregationBuffer agg, Object partial)
        throws HiveException {
    if (partial == null) {
        return;
    }

    AggrBuffer aggr = (AggrBuffer) agg;
    DoubleWritable other = (DoubleWritable) partial;
    double v = other.get();
    aggr.merge(v);
}
 
Example 9
Source File: ST_PointZ.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
public BytesWritable evaluate(DoubleWritable x, DoubleWritable y, DoubleWritable z, DoubleWritable m) {
	if (x == null || y == null || z == null) {
		return null;
	}
	Point stPt = new Point(x.get(), y.get(), z.get());
	if (m != null)
		stPt.setM(m.get());
	return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(stPt, null));
}