Search in sources :

Example 1 with IntOpenHashSet

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;
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) ByteBuffer(java.nio.ByteBuffer)

Example 2 with 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);
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet)

Example 3 with IntOpenHashSet

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);
    }
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) FieldSpec(com.linkedin.pinot.common.data.FieldSpec)

Example 4 with IntOpenHashSet

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);
    }
}
Also used : FieldSpec(com.linkedin.pinot.common.data.FieldSpec) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet)

Example 5 with IntOpenHashSet

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);
    }
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) Test(org.testng.annotations.Test)

Aggregations

IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)28 IntSet (it.unimi.dsi.fastutil.ints.IntSet)10 IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)4 Supplier (com.google.common.base.Supplier)2 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)2 PartitionKey (com.tencent.angel.PartitionKey)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)2 ArrayList (java.util.ArrayList)2 IAE (org.apache.druid.java.util.common.IAE)2 BitmapBackedSelection (tech.tablesaw.selection.BitmapBackedSelection)2 Selection (tech.tablesaw.selection.Selection)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 Preconditions (com.google.common.base.Preconditions)1 Predicate (com.google.common.base.Predicate)1 Suppliers (com.google.common.base.Suppliers)1