Search in sources :

Example 1 with LongOpenHashSet

use of it.unimi.dsi.fastutil.longs.LongOpenHashSet in project druid by druid-io.

the class InDimFilter method getLongPredicateSupplier.

// As the set of filtered values can be large, parsing them as longs should be done only if needed, and only once.
// Pass in a common long predicate supplier to all filters created by .toFilter(), so that
// we only compute the long hashset/array once per query.
// This supplier must be thread-safe, since this DimFilter will be accessed in the query runners.
private Supplier<DruidLongPredicate> getLongPredicateSupplier() {
    return new Supplier<DruidLongPredicate>() {

        private final Object initLock = new Object();

        private DruidLongPredicate predicate;

        private void initLongValues() {
            if (predicate != null) {
                return;
            }
            synchronized (initLock) {
                if (predicate != null) {
                    return;
                }
                LongArrayList longs = new LongArrayList(values.size());
                for (String value : values) {
                    Long longValue = GuavaUtils.tryParseLong(value);
                    if (longValue != null) {
                        longs.add(longValue);
                    }
                }
                if (longs.size() > NUMERIC_HASHING_THRESHOLD) {
                    final LongOpenHashSet longHashSet = new LongOpenHashSet(longs);
                    predicate = new DruidLongPredicate() {

                        @Override
                        public boolean applyLong(long input) {
                            return longHashSet.contains(input);
                        }
                    };
                } else {
                    final long[] longArray = longs.toLongArray();
                    Arrays.sort(longArray);
                    predicate = new DruidLongPredicate() {

                        @Override
                        public boolean applyLong(long input) {
                            return Arrays.binarySearch(longArray, input) >= 0;
                        }
                    };
                }
            }
        }

        @Override
        public DruidLongPredicate get() {
            initLongValues();
            return predicate;
        }
    };
}
Also used : LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) Supplier(com.google.common.base.Supplier) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet)

Example 2 with LongOpenHashSet

use of it.unimi.dsi.fastutil.longs.LongOpenHashSet in project geode by apache.

the class PersistentOplogSet method createOplogs.

public void createOplogs(boolean needsOplogs, Map<File, DirectoryHolder> backupFiles) {
    LongOpenHashSet foundCrfs = new LongOpenHashSet();
    LongOpenHashSet foundDrfs = new LongOpenHashSet();
    for (Map.Entry<File, DirectoryHolder> entry : backupFiles.entrySet()) {
        File file = entry.getKey();
        String absolutePath = file.getAbsolutePath();
        int underscorePosition = absolutePath.lastIndexOf("_");
        int pointPosition = absolutePath.lastIndexOf(".");
        String opid = absolutePath.substring(underscorePosition + 1, pointPosition);
        long oplogId = Long.parseLong(opid);
        maxRecoveredOplogId = Math.max(maxRecoveredOplogId, oplogId);
        // if deleted then don't process it.
        if (Oplog.isCRFFile(file.getName())) {
            if (!isCrfOplogIdPresent(oplogId)) {
                deleteFileOnRecovery(file);
                try {
                    String krfFileName = Oplog.getKRFFilenameFromCRFFilename(file.getAbsolutePath());
                    File krfFile = new File(krfFileName);
                    deleteFileOnRecovery(krfFile);
                } catch (Exception ex) {
                // ignore
                }
                // this file we unable to delete earlier
                continue;
            }
        } else if (Oplog.isDRFFile(file.getName())) {
            if (!isDrfOplogIdPresent(oplogId)) {
                deleteFileOnRecovery(file);
                // this file we unable to delete earlier
                continue;
            }
        }
        Oplog oplog = getChild(oplogId);
        if (oplog == null) {
            oplog = new Oplog(oplogId, this);
            // oplogSet.add(oplog);
            addRecoveredOplog(oplog);
        }
        if (oplog.addRecoveredFile(file, entry.getValue())) {
            foundCrfs.add(oplogId);
        } else {
            foundDrfs.add(oplogId);
        }
    }
    if (needsOplogs) {
        verifyOplogs(foundCrfs, foundDrfs);
    }
}
Also used : LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) DiskAccessException(org.apache.geode.cache.DiskAccessException)

Example 3 with LongOpenHashSet

use of it.unimi.dsi.fastutil.longs.LongOpenHashSet in project presto by prestodb.

the class ArrayUnionFunction method bigintUnion.

@SqlType("array(bigint)")
public static Block bigintUnion(@SqlType("array(bigint)") Block leftArray, @SqlType("array(bigint)") Block rightArray) {
    int leftArrayCount = leftArray.getPositionCount();
    int rightArrayCount = rightArray.getPositionCount();
    LongSet set = new LongOpenHashSet(leftArrayCount + rightArrayCount);
    BlockBuilder distinctElementBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), leftArrayCount + rightArrayCount);
    AtomicBoolean containsNull = new AtomicBoolean(false);
    appendBigintArray(leftArray, containsNull, set, distinctElementBlockBuilder);
    appendBigintArray(rightArray, containsNull, set, distinctElementBlockBuilder);
    return distinctElementBlockBuilder.build();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongSet(it.unimi.dsi.fastutil.longs.LongSet) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) SqlType(com.facebook.presto.spi.function.SqlType)

Example 4 with LongOpenHashSet

use of it.unimi.dsi.fastutil.longs.LongOpenHashSet in project geode by apache.

the class DiskInitFile method verifyOplogs.

public void verifyOplogs(LongOpenHashSet foundCrfs, LongOpenHashSet foundDrfs, LongOpenHashSet expectedCrfIds, LongOpenHashSet expectedDrfIds) {
    LongOpenHashSet missingCrfs = calcMissing(foundCrfs, expectedCrfIds);
    LongOpenHashSet missingDrfs = calcMissing(foundDrfs, expectedDrfIds);
    // Note that finding extra ones is ok; it is possible we died just
    // after creating one but before we could record it in the if file
    // Or died just after deleting it but before we could record it in the if file.
    boolean failed = false;
    String msg = null;
    if (!missingCrfs.isEmpty()) {
        failed = true;
        msg = "*.crf files with these ids: " + Arrays.toString(missingCrfs.toArray());
    }
    if (!missingDrfs.isEmpty()) {
        failed = true;
        if (msg == null) {
            msg = "";
        } else {
            msg += ", ";
        }
        msg += "*.drf files with these ids: " + Arrays.toString(missingDrfs.toArray());
    }
    if (failed) {
        msg = "The following required files could not be found: " + msg + ".";
        throw new IllegalStateException(msg);
    }
}
Also used : LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet)

Example 5 with LongOpenHashSet

use of it.unimi.dsi.fastutil.longs.LongOpenHashSet in project symja_android_library by axkr.

the class DateTimeColumn method unique.

@Override
public DateTimeColumn unique() {
    LongSet ints = new LongOpenHashSet(data.size());
    for (long i : data) {
        ints.add(i);
    }
    DateTimeColumn column = emptyCopy(ints.size());
    column.setName(name() + " Unique values");
    column.data = LongArrayList.wrap(ints.toLongArray());
    return column;
}
Also used : LongSet(it.unimi.dsi.fastutil.longs.LongSet) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet)

Aggregations

LongOpenHashSet (it.unimi.dsi.fastutil.longs.LongOpenHashSet)13 LongSet (it.unimi.dsi.fastutil.longs.LongSet)5 LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)3 SqlType (com.facebook.presto.spi.function.SqlType)2 Supplier (com.google.common.base.Supplier)2 File (java.io.File)2 Collection (java.util.Collection)2 Map (java.util.Map)2 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)1 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)1 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