Java Code Examples for org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryArray

The following examples show how to use org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryArray. These examples are extracted from open source projects. 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
@Override
public void merge(AggregationBuffer agg, Object partial) throws HiveException {
    if (partial == null) {
        return;
    }
    RfAggregationBufferV2 buf = (RfAggregationBufferV2) agg;

    Object o1 = internalMergeOI.getStructFieldData(partial, sizeField);
    int size = sizeFieldOI.get(o1);
    Object posteriori = internalMergeOI.getStructFieldData(partial, posterioriField);

    // --------------------------------------------------------------
    // [workaround]
    // java.lang.ClassCastException: org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryArray
    // cannot be cast to [Ljava.lang.Object;
    if (posteriori instanceof LazyBinaryArray) {
        posteriori = ((LazyBinaryArray) posteriori).getList();
    }

    buf.merge(size, posteriori, posterioriFieldOI);
}
 
Example 2
Source Project: incubator-hivemall   Source File: BuildBinsUDAF.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void merge(@SuppressWarnings("deprecation") AggregationBuffer agg, Object other)
        throws HiveException {
    if (other == null) {
        return;
    }

    final BuildBinsAggregationBuffer myAgg = (BuildBinsAggregationBuffer) agg;

    myAgg.autoShrink =
            autoShrinkOI.get(structOI.getStructFieldData(other, autoShrinkField));

    final List<?> histogram = ((LazyBinaryArray) structOI.getStructFieldData(other,
        histogramField)).getList();
    myAgg.histogram.merge(histogram, histogramElOI);

    final double[] quantiles = HiveUtils.asDoubleArray(
        structOI.getStructFieldData(other, quantilesField), quantilesOI, quantileOI);
    if (quantiles != null && quantiles.length > 0) {
        myAgg.quantiles = quantiles;
    }
}
 
Example 3
Source Project: incubator-hivemall   Source File: FMPredictGenericUDAF.java    License: 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;
    }
    FMPredictAggregationBuffer buf = (FMPredictAggregationBuffer) agg;

    Object o1 = internalMergeOI.getStructFieldData(partial, retField);
    double ret = retOI.get(o1);

    Object sumVjXj = internalMergeOI.getStructFieldData(partial, sumVjXjField);
    Object sumV2X2 = internalMergeOI.getStructFieldData(partial, sumV2X2Field);

    // --------------------------------------------------------------
    // [workaround]
    // java.lang.ClassCastException: org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryArray
    // cannot be cast to [Ljava.lang.Object;
    if (sumVjXj instanceof LazyBinaryArray) {
        sumVjXj = ((LazyBinaryArray) sumVjXj).getList();
    }
    if (sumV2X2 instanceof LazyBinaryArray) {
        sumV2X2 = ((LazyBinaryArray) sumV2X2).getList();
    }
    // --------------------------------------------------------------

    buf.merge(ret, sumVjXj, sumV2X2, sumVjXjOI, sumV2X2OI);
}
 
Example 4
Source Project: incubator-hivemall   Source File: HiveUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Object castLazyBinaryObject(@Nonnull final Object obj) {
    if (obj instanceof LazyBinaryMap) {
        return ((LazyBinaryMap) obj).getMap();
    } else if (obj instanceof LazyBinaryArray) {
        return ((LazyBinaryArray) obj).getList();
    }
    return obj;
}
 
Example 5
Source Project: hive-funnel-udf   Source File: ListUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Cast an object to a list. Checks if it is a LazyBinaryArray or a
 * regular list.
 *
 * @param object Input object to try and cast to a list.
 * @return List of objects.
 */
public static List<Object> toList(Object object) {
    List<Object> result;
    if (object instanceof LazyBinaryArray) {
        result = ((LazyBinaryArray) object).getList();
    } else {
        result = (List<Object>) object;
    }
    return result;
}
 
Example 6
Source Project: presto   Source File: RcFileTester.java    License: Apache License 2.0 4 votes vote down vote up
private static Object decodeRecordReaderValue(Type type, Object actualValue)
{
    if (actualValue instanceof LazyPrimitive) {
        actualValue = ((LazyPrimitive<?, ?>) actualValue).getWritableObject();
    }
    if (actualValue instanceof BooleanWritable) {
        actualValue = ((BooleanWritable) actualValue).get();
    }
    else if (actualValue instanceof ByteWritable) {
        actualValue = ((ByteWritable) actualValue).get();
    }
    else if (actualValue instanceof BytesWritable) {
        actualValue = new SqlVarbinary(((BytesWritable) actualValue).copyBytes());
    }
    else if (actualValue instanceof DateWritable) {
        actualValue = new SqlDate(((DateWritable) actualValue).getDays());
    }
    else if (actualValue instanceof DoubleWritable) {
        actualValue = ((DoubleWritable) actualValue).get();
    }
    else if (actualValue instanceof FloatWritable) {
        actualValue = ((FloatWritable) actualValue).get();
    }
    else if (actualValue instanceof IntWritable) {
        actualValue = ((IntWritable) actualValue).get();
    }
    else if (actualValue instanceof LongWritable) {
        actualValue = ((LongWritable) actualValue).get();
    }
    else if (actualValue instanceof ShortWritable) {
        actualValue = ((ShortWritable) actualValue).get();
    }
    else if (actualValue instanceof HiveDecimalWritable) {
        DecimalType decimalType = (DecimalType) type;
        HiveDecimalWritable writable = (HiveDecimalWritable) actualValue;
        // writable messes with the scale so rescale the values to the Presto type
        BigInteger rescaledValue = rescale(writable.getHiveDecimal().unscaledValue(), writable.getScale(), decimalType.getScale());
        actualValue = new SqlDecimal(rescaledValue, decimalType.getPrecision(), decimalType.getScale());
    }
    else if (actualValue instanceof Text) {
        actualValue = actualValue.toString();
    }
    else if (actualValue instanceof TimestampWritable) {
        TimestampWritable timestamp = (TimestampWritable) actualValue;
        if (SESSION.isLegacyTimestamp()) {
            actualValue = SqlTimestamp.legacyFromMillis(3, (timestamp.getSeconds() * 1000) + (timestamp.getNanos() / 1000000L), UTC_KEY);
        }
        else {
            actualValue = SqlTimestamp.fromMillis(3, (timestamp.getSeconds() * 1000) + (timestamp.getNanos() / 1000000L));
        }
    }
    else if (actualValue instanceof StructObject) {
        StructObject structObject = (StructObject) actualValue;
        actualValue = decodeRecordReaderStruct(type, structObject.getFieldsAsList());
    }
    else if (actualValue instanceof LazyBinaryArray) {
        actualValue = decodeRecordReaderList(type, ((LazyBinaryArray) actualValue).getList());
    }
    else if (actualValue instanceof LazyBinaryMap) {
        actualValue = decodeRecordReaderMap(type, ((LazyBinaryMap) actualValue).getMap());
    }
    else if (actualValue instanceof LazyArray) {
        actualValue = decodeRecordReaderList(type, ((LazyArray) actualValue).getList());
    }
    else if (actualValue instanceof LazyMap) {
        actualValue = decodeRecordReaderMap(type, ((LazyMap) actualValue).getMap());
    }
    else if (actualValue instanceof List) {
        actualValue = decodeRecordReaderList(type, ((List<?>) actualValue));
    }
    return actualValue;
}