@Override public Object terminate(AggregationBuffer agg) throws HiveException { result.reset(); try { BloomKFilter.serialize(result, ((BloomFilterBuf)agg).bloomFilter); } catch (IOException e) { throw new HiveException(e); } finally { IOUtils.closeStream(result); } return new BytesWritable(result.toByteArray()); }
public Aggregation(long expectedEntries) { ByteArrayOutputStream bytesOut = null; try { BloomKFilter bf = new BloomKFilter(expectedEntries); bytesOut = new ByteArrayOutputStream(); BloomKFilter.serialize(bytesOut, bf); bfBytes = bytesOut.toByteArray(); } catch (Exception err) { throw new IllegalArgumentException("Error creating aggregation buffer", err); } finally { IOUtils.closeStream(bytesOut); } }
@Override public void assignRowColumn(VectorizedRowBatch batch, int batchIndex, int columnNum, AggregationBuffer agg) throws HiveException { BytesColumnVector outputColVector = (BytesColumnVector) batch.cols[columnNum]; Aggregation myagg = (Aggregation) agg; outputColVector.isNull[batchIndex] = false; try { Aggregation bfAgg = (Aggregation) agg; byteStream.reset(); BloomKFilter.serialize(byteStream, bfAgg.bf); byte[] bytes = byteStream.toByteArray(); outputColVector.setVal(batchIndex, bytes); } catch (IOException err) { throw new HiveException("Error encountered while serializing bloomfilter", err); } finally { IOUtils.closeStream(byteStream); } } }