use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project pinot by linkedin.
the class ObjectCustomSerDe method deserializeIntOpenHashSet.
/**
* Helper method to de-serialize an {@link IntOpenHashSet}.
*/
private static IntOpenHashSet deserializeIntOpenHashSet(byte[] bytes) {
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
int size = byteBuffer.getInt();
IntOpenHashSet intOpenHashSet = new IntOpenHashSet(size);
for (int i = 0; i < size; i++) {
intOpenHashSet.add(byteBuffer.getInt());
}
return intOpenHashSet;
}
use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project pinot by linkedin.
the class DistinctCountAggregationFunction method setValueForGroupKey.
/**
* Helper method to set value for a groupKey into the result holder.
*
* @param groupByResultHolder Result holder
* @param groupKey Group-key for which to set the value
* @param value Value for the group key
*/
private void setValueForGroupKey(@Nonnull GroupByResultHolder groupByResultHolder, int groupKey, int value) {
IntOpenHashSet valueSet = groupByResultHolder.getResult(groupKey);
if (valueSet == null) {
valueSet = new IntOpenHashSet();
groupByResultHolder.setValueForKey(groupKey, valueSet);
}
valueSet.add(value);
}
use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project pinot by linkedin.
the class DistinctCountAggregationFunction method aggregate.
@Override
public void aggregate(int length, @Nonnull AggregationResultHolder aggregationResultHolder, @Nonnull BlockValSet... blockValSets) {
IntOpenHashSet valueSet = aggregationResultHolder.getResult();
if (valueSet == null) {
valueSet = new IntOpenHashSet();
aggregationResultHolder.setValue(valueSet);
}
FieldSpec.DataType valueType = blockValSets[0].getValueType();
switch(valueType) {
case INT:
int[] intValues = blockValSets[0].getIntValuesSV();
for (int i = 0; i < length; i++) {
valueSet.add(intValues[i]);
}
break;
case LONG:
long[] longValues = blockValSets[0].getLongValuesSV();
for (int i = 0; i < length; i++) {
valueSet.add(Long.valueOf(longValues[i]).hashCode());
}
break;
case FLOAT:
float[] floatValues = blockValSets[0].getFloatValuesSV();
for (int i = 0; i < length; i++) {
valueSet.add(Float.valueOf(floatValues[i]).hashCode());
}
break;
case DOUBLE:
double[] doubleValues = blockValSets[0].getDoubleValuesSV();
for (int i = 0; i < length; i++) {
valueSet.add(Double.valueOf(doubleValues[i]).hashCode());
}
break;
case STRING:
String[] stringValues = blockValSets[0].getStringValuesSV();
for (int i = 0; i < length; i++) {
valueSet.add(stringValues[i].hashCode());
}
break;
default:
throw new IllegalArgumentException("Illegal data type for distinct count aggregation function: " + valueType);
}
}
use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project pinot by linkedin.
the class DistinctCountMVAggregationFunction method aggregate.
@Override
public void aggregate(int length, @Nonnull AggregationResultHolder aggregationResultHolder, @Nonnull BlockValSet... blockValSets) {
IntOpenHashSet valueSet = aggregationResultHolder.getResult();
if (valueSet == null) {
valueSet = new IntOpenHashSet();
aggregationResultHolder.setValue(valueSet);
}
FieldSpec.DataType valueType = blockValSets[0].getValueType();
switch(valueType) {
case INT:
int[][] intValues = blockValSets[0].getIntValuesMV();
for (int i = 0; i < length; i++) {
for (int value : intValues[i]) {
valueSet.add(value);
}
}
break;
case LONG:
long[][] longValues = blockValSets[0].getLongValuesMV();
for (int i = 0; i < length; i++) {
for (long value : longValues[i]) {
valueSet.add(Long.valueOf(value).hashCode());
}
}
break;
case FLOAT:
float[][] floatValues = blockValSets[0].getFloatValuesMV();
for (int i = 0; i < length; i++) {
for (float value : floatValues[i]) {
valueSet.add(Float.valueOf(value).hashCode());
}
}
case DOUBLE:
double[][] doubleValues = blockValSets[0].getDoubleValuesMV();
for (int i = 0; i < length; i++) {
for (double value : doubleValues[i]) {
valueSet.add(Double.valueOf(value).hashCode());
}
}
break;
case STRING:
String[][] stringValues = blockValSets[0].getStringValuesMV();
for (int i = 0; i < length; i++) {
for (String value : stringValues[i]) {
valueSet.add(value.hashCode());
}
}
break;
default:
throw new IllegalArgumentException("Illegal data type for distinct count aggregation function: " + valueType);
}
}
use of it.unimi.dsi.fastutil.ints.IntOpenHashSet in project pinot by linkedin.
the class ObjectCustomSerDeTest method testIntOpenHashSet.
/**
* Test for ser/de of {@link IntOpenHashSet}.
*/
@Test
public void testIntOpenHashSet() throws IOException {
for (int i = 0; i < NUM_ITERATIONS; i++) {
int size = RANDOM.nextInt(100);
IntOpenHashSet expected = new IntOpenHashSet(size);
for (int j = 0; j < size; j++) {
expected.add(RANDOM.nextInt());
}
byte[] bytes = ObjectCustomSerDe.serialize(expected);
IntOpenHashSet actual = ObjectCustomSerDe.deserialize(bytes, ObjectType.IntOpenHashSet);
// Use Object comparison instead of Collection comparison because order might change.
Assert.assertEquals((Object) actual, expected, ERROR_MESSAGE);
}
}
Aggregations