com.carrotsearch.hppc.LongArrayList Java Examples

The following examples show how to use com.carrotsearch.hppc.LongArrayList. 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
Source File: CorrelatedPushDown.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean pushdownPredWithColumn(ResultSetNode rsn, Predicate pred, ValueNode colRef)
        throws StandardException {
    try {
        ResultColumn rc = RSUtils.refToRC.apply(colRef);
        LongArrayList chain = rc.chain();
        long lastLink = chain.get(chain.size() - 1);
        List<ResultSetNode> subTree = RSUtils.getSelfAndDescendants(rsn);
        Map<Integer, ResultSetNode> nodeMap = zipMap(Iterables.transform(subTree, RSUtils.rsNum), subTree);
        int left = (int) (lastLink >> 32);
        int right = (int) lastLink;
        ResultSetNode targetRSN = nodeMap.get(left);
        rc.setResultSetNumber(left);
        rc.setVirtualColumnId(right);
        ((Optimizable)targetRSN).pushOptPredicate(pred);
    } catch (StandardException e) {
        LOG.warn("Exception pushing down topmost subquery predicate:", e);
        return false;
    }
    return true;
}
 
Example #2
Source File: SimpleTxnOperationFactory.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private byte[] encodeParentIds(TxnView txn,LongArrayList parentTxnIds){
    /*
     * For both active reads AND active writes, we only need to know the
     * parent's transaction ids, since we'll use the information immediately
     * available to determine other properties (additivity, etc.) Thus,
     * by doing this bit of logic, we can avoid a network call on the server
     * for every parent on the transaction chain, at the cost of 2-10 bytes
     * per parent on the chain--a cheap trade.
     */
    TxnView parent=txn.getParentTxnView();
    while(!Txn.ROOT_TRANSACTION.equals(parent)){
        parentTxnIds.add(parent.getTxnId());
        parent=parent.getParentTxnView();
    }
    int parentSize=parentTxnIds.size();
    long[] parentIds=parentTxnIds.buffer;
    MultiFieldEncoder parents=MultiFieldEncoder.create(parentSize);
    for(int i=1;i<=parentSize;i++){
        parents.encodeNext(parentIds[parentSize-i]);
    }
    return parents.build();
}
 
Example #3
Source File: SimpleTxnOperationFactory.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public byte[] encode(TxnView txn){
    MultiFieldEncoder encoder=MultiFieldEncoder.create(9)
            .encodeNext(txn.getTxnId())
            .encodeNext(txn.getBeginTimestamp())
            .encodeNext(txn.isAdditive())
            .encodeNext(txn.getIsolationLevel().encode())
            .encodeNext(txn.allowsWrites());

    TaskId taskId = txn.getTaskId();
    if (taskId != null) {
        encoder.encodeNext(taskId.getStageId()).encodeNext(taskId.getPartitionId()).encodeNext(taskId.getTaskAttemptNumber());
    } else {
        encoder.encodeNext(-1).encodeNext(-1).encodeNext(-1);
    }

    LongArrayList parentTxnIds= new LongArrayList();
    byte[] build=encodeParentIds(txn,parentTxnIds);
    encoder.setRawBytes(build);
    return encoder.build();
}
 
Example #4
Source File: TestingTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private long[] findActiveTransactions(long minTimestamp,long maxId,byte[] table){
    LongArrayList activeTxns=new LongArrayList(txnMap.size());
    for(Map.Entry<Long, TxnHolder> txnEntry : txnMap.entrySet()){
        if(isTimedOut(txnEntry.getValue())) continue;
        Txn value=txnEntry.getValue().txn;
        if(value.getEffectiveState()==Txn.State.ACTIVE && value.getTxnId()<=maxId && value.getTxnId()>=minTimestamp){
            Iterator<ByteSlice> destinationTables=value.getDestinationTables();
            while(destinationTables.hasNext()){
                ByteSlice data=destinationTables.next();
                if(data.equals(table,0,table.length))
                    activeTxns.add(txnEntry.getKey());
            }
        }
    }
    return activeTxns.toArray();
}
 
Example #5
Source File: ActiveTransactionTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void oldestActiveTransactionIgnoresCommitTimestampIds() throws IOException{
    final Txn t0=control.beginTransaction(DESTINATION_TABLE);
    transactorSetup.timestampSource.rememberTimestamp(t0.getTxnId());
    LongArrayList committedTxns=new LongArrayList();
    for(int i=0;i<4;i++){
        final Txn transactionId=control.beginTransaction(DESTINATION_TABLE);
        transactionId.commit();
        committedTxns.add(transactionId.getTxnId());
    }

    final Txn t1=control.beginTransaction(DESTINATION_TABLE);
    final long[] ids=txnStore.getActiveTransactionIds(t1,DESTINATION_TABLE);
    Assert.assertEquals(2,ids.length);
    Arrays.sort(ids);
    Assert.assertEquals(t0.getTxnId(),ids[0]);
    Assert.assertEquals(t1.getTxnId(),ids[1]);
    //this transaction should still be missing
}
 
Example #6
Source File: AbstractLongListUtil.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public static LongArrayList mergeSort(LongArrayList a, LongArrayList b) {
    int posa=0, posb=0;
    LongArrayList result = new LongArrayList(a.size()+b.size());
    while (posa<a.size() || posb<b.size()) {
        long next;
        if (posa>=a.size()) {
            next=b.get(posb++);
        } else if (posb>=b.size()) {
            next=a.get(posa++);
        } else if (a.get(posa)<=b.get(posb)) {
            next=a.get(posa++);
        } else {
            next=b.get(posb++);
        }
        Preconditions.checkArgument(result.isEmpty() || result.get(result.size()-1)<=next,
                "The input lists are not sorted");
        result.add(next);
    }
    return result;
}
 
Example #7
Source File: SimpleVertexQueryProcessor.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of adjacent vertex ids for this query. By reading those ids
 * from the entries directly (without creating objects) we get much better performance.
 *
 * @return
 */
public VertexList vertexIds() {
    LongArrayList list = new LongArrayList();
    long previousId = 0;
    for (Long id : Iterables.transform(this,new Function<Entry, Long>() {
        @Nullable
        @Override
        public Long apply(@Nullable Entry entry) {
            return edgeSerializer.readRelation(entry,true,tx).getOtherVertexId();
        }
    })) {
        list.add(id);
        if (id>=previousId && previousId>=0) previousId=id;
        else previousId=-1;
    }
    return new VertexLongList(tx,list,previousId>=0);
}
 
Example #8
Source File: ExhaustiveLongEncodingTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@DataPoints public static long[] powersOf2(){
    LongArrayList dataPoints = new LongArrayList(100);
    long l = 1l;
    while(l>0){
        dataPoints.add(l);
        dataPoints.add(-l);
        dataPoints.add(3*l);
        dataPoints.add(-3*l);
        dataPoints.add(5*l);
        dataPoints.add(-5*l);
        dataPoints.add(7*l);
        dataPoints.add(-7*l);
        l<<=1;
    }

    return dataPoints.toArray();
}
 
Example #9
Source File: MemTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private long[] findActiveTransactions(long minTimestamp,long maxId,byte[] table){
    LongArrayList activeTxns=new LongArrayList(txnMap.size());
    for(Map.Entry<Long, TxnHolder> txnEntry : txnMap.entrySet()){
        if(isTimedOut(txnEntry.getValue())) continue;
        Txn value=txnEntry.getValue().txn;
        if(value.getEffectiveState()==Txn.State.ACTIVE && value.getTxnId()<=maxId && value.getTxnId()>=minTimestamp){
            Iterator<ByteSlice> destinationTables=value.getDestinationTables();
            while(destinationTables.hasNext()){
                ByteSlice data=destinationTables.next();
                if(data.equals(table,0,table.length))
                    activeTxns.add(txnEntry.getKey());
            }
        }
    }
    return activeTxns.toArray();
}
 
Example #10
Source File: VertexArrayList.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method used to convert the list of vertices into a list of vertex ids (assuming all vertices have ids)
 *
 * @param vertices
 * @return
 */
private static final LongArrayList toLongList(List<TitanVertex> vertices) {
    LongArrayList result = new LongArrayList(vertices.size());
    for (TitanVertex n : vertices) {
        result.add(n.longId());
    }
    return result;
}
 
Example #11
Source File: StandardTitanGraph.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public List<EntryList> edgeMultiQuery(LongArrayList vids, SliceQuery query, BackendTransaction tx) {
    Preconditions.checkArgument(vids != null && !vids.isEmpty());
    List<StaticBuffer> vertexIds = new ArrayList<StaticBuffer>(vids.size());
    for (int i = 0; i < vids.size(); i++) {
        Preconditions.checkArgument(vids.get(i) > 0);
        vertexIds.add(idManager.getKey(vids.get(i)));
    }
    Map<StaticBuffer,EntryList> result = tx.edgeStoreMultiQuery(vertexIds, query);
    List<EntryList> resultList = new ArrayList<EntryList>(result.size());
    for (StaticBuffer v : vertexIds) resultList.add(result.get(v));
    return resultList;
}
 
Example #12
Source File: RegionTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public long[] getActiveTxnIds(long afterTs,long beforeTs,byte[] destinationTable) throws IOException{
    if(LOG.isTraceEnabled())
        SpliceLogUtils.trace(LOG,"getActiveTxnIds beforeTs=%d, afterTs=%s, destinationTable=%s",beforeTs,afterTs,destinationTable);

    LongArrayList lal = new LongArrayList();
    try (Source<TxnMessage.Txn> activeTxn = getActiveTxns(afterTs, beforeTs, destinationTable)) {
        while (activeTxn.hasNext()) {
            TxnMessage.Txn next = activeTxn.next();
            TxnMessage.TxnInfo info = next.getInfo();
            lal.add(info.getTxnId());
        }
    }
    return lal.toArray();
}
 
Example #13
Source File: QueryTreeNode.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * For a given ResultColumnList, return a map from
 * [resultSetNumber, virtualColumnId] => ResultColumn
 * where there is one entry for each ResultColumn down the chain of reference to
 * its source column on a table. This allows translation from a column reference at
 * any node below into the ResultColumn projected from the passed ResultColumnList.
 */
public LongObjectHashMap<ResultColumn> rsnChainMap()
        throws StandardException {
    LongObjectHashMap<ResultColumn> chain = new LongObjectHashMap<>();
    List<ResultColumn> cols = RSUtils.collectNodes(this, ResultColumn.class);
    for (ResultColumn rc : cols) {
        long top = rc.getCoordinates();
        chain.put(top, rc);
        LongArrayList list = rc.chain();
        for (int i = 0; i< list.size(); i++) {
            chain.put(list.buffer[i],rc);
        }
    }
    return chain;
}
 
Example #14
Source File: AbstractLongListUtil.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static LongArrayList mergeJoin(LongArrayList a, LongArrayList b, final boolean unique) {
    assert isSorted(a) : a.toString();
    assert isSorted(b) : b.toString();
    int counterA = 0, counterB = 0;
    int sizeA = a.size();
    int sizeB = b.size();
    LongArrayList merge = new LongArrayList(Math.min(sizeA, sizeB));
    int resultSize = 0;
    while (counterA < sizeA && counterB < sizeB) {
        if (a.get(counterA) == b.get(counterB)) {
            long value = a.get(counterA);
            if (!unique) {
                merge.add(value);
                resultSize++;
            } else {
                if (resultSize <= 0 || merge.get(resultSize - 1) != value) {
                    merge.add(value);
                    resultSize++;
                }
            }
            counterA++;
            counterB++;
        } else if (a.get(counterA) < b.get(counterB)) {
            counterA++;
        } else {
            assert a.get(counterA) > b.get(counterB);
            counterB++;
        }
    }
    return merge;
}
 
Example #15
Source File: ActiveTransactionTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
    @Ignore("This is subject to contamination failures when other tests are running concurrently")
    public void oldestActiveTransactionsManyActive() throws IOException{
        LongArrayList startedTxns=new LongArrayList();
        final Txn t0=control.beginTransaction(DESTINATION_TABLE);
        startedTxns.add(t0.getTxnId());
        transactorSetup.timestampSource.rememberTimestamp(t0.getTxnId());
//        long[] startIds = txnStore.getActiveTransactionIds(t0,DESTINATION_TABLE);
//        for(long sId:startIds){
//            startedTxns.add(sId);
//        }
        for(int i=0;i<4;i++){
            Txn transactionId=control.beginTransaction(DESTINATION_TABLE);
            startedTxns.add(transactionId.getTxnId());
        }
        final Txn t1=control.beginTransaction(DESTINATION_TABLE);
        startedTxns.add(t1.getTxnId());
        final long[] ids=txnStore.getActiveTransactionIds(t0.getTxnId(),t1.getTxnId(),DESTINATION_TABLE);
        System.out.println(startedTxns.toString());
        System.out.println(Arrays.toString(ids));

        Assert.assertEquals(startedTxns.size(),ids.length);
        Arrays.sort(ids);
        Assert.assertArrayEquals(startedTxns.toArray(),ids);
//        Assert.assertEquals(t0.getTxnId(), ids[0]);
//        Assert.assertEquals(t1.getTxnId(), result.get(ids.length - 1).getId());
    }
 
Example #16
Source File: ExhaustiveLongEncodingTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@DataPoints public static long[] powersOf7(){
    LongArrayList dataPoints = new LongArrayList(100);
    long l = 1l;
    while(l>0){
        dataPoints.add(l);
        dataPoints.add(-l);
        l*=7;
    }

    return dataPoints.toArray();
}
 
Example #17
Source File: TestingTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private long[] getAllActiveTransactions(long minTimestamp,long maxId) throws IOException{

        LongArrayList activeTxns=new LongArrayList(txnMap.size());
        for(Map.Entry<Long, TxnHolder> txnEntry : txnMap.entrySet()){
            if(isTimedOut(txnEntry.getValue())) continue;
            Txn value=txnEntry.getValue().txn;
            if(value.getEffectiveState()==Txn.State.ACTIVE
                    && value.getTxnId()<=maxId
                    && value.getTxnId()>=minTimestamp)
                activeTxns.add(txnEntry.getKey());
        }
        return activeTxns.toArray();
    }
 
Example #18
Source File: MemTxnStore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private long[] getAllActiveTransactions(long minTimestamp,long maxId) throws IOException{

        LongArrayList activeTxns=new LongArrayList(txnMap.size());
        for(Map.Entry<Long, TxnHolder> txnEntry : txnMap.entrySet()){
            if(isTimedOut(txnEntry.getValue())) continue;
            Txn value=txnEntry.getValue().txn;
            if(value.getEffectiveState()==Txn.State.ACTIVE
                    && value.getTxnId()<=maxId
                    && value.getTxnId()>=minTimestamp)
                activeTxns.add(txnEntry.getKey());
        }
        return activeTxns.toArray();
    }
 
Example #19
Source File: OnDiskIndexBuilder.java    From sasi with Apache License 2.0 4 votes vote down vote up
protected void flushMetadata(LongArrayList longArrayList) throws IOException
{
    out.writeInt(longArrayList.size());
    for (int i = 0; i < longArrayList.size(); i++)
        out.writeLong(longArrayList.get(i));
}
 
Example #20
Source File: MoreCollectors.java    From more-lambdas-java with Artistic License 2.0 4 votes vote down vote up
public static Collector<Long, ?, LongArrayList> toLongList() {
    return new CollectorImpl<>(LongArrayList::new, LongArrayList::add, (left, right) -> {
        left.addAll(right);
        return left;
    }, CH_ID);
}
 
Example #21
Source File: NumberFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public CustomLongNumericDocValuesField(String  name, long value) {
    super(name);
    values = new LongArrayList();
    add(value);
}
 
Example #22
Source File: AbstractLongListUtil.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static LongArrayList singleton(long el) {
    LongArrayList l = new LongArrayList(1);
    l.add(el);
    return l;
}
 
Example #23
Source File: AbstractLongListUtil.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static boolean isSorted(LongArrayList l) {
    return isSorted(l, false);
}
 
Example #24
Source File: AbstractLongListUtil.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static boolean isSorted(LongArrayList l, final boolean unique) {
    for (int i = 1; i < l.size(); i++) {
        if (l.get(i) < l.get(i - 1) || (unique && l.get(i) == l.get(i - 1))) return false;
    }
    return true;
}
 
Example #25
Source File: VertexArrayList.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public VertexLongList toVertexLongList() {
    LongArrayList list = toLongList(vertices);
    return new VertexLongList(tx,list,sorted);
}
 
Example #26
Source File: VertexArrayList.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public LongArrayList getIDs() {
    return toLongList(vertices);
}
 
Example #27
Source File: VertexLongList.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Override
public LongArrayList getIDs() {
    return vertices;
}
 
Example #28
Source File: VertexLongList.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public VertexLongList(StandardTitanTx tx, LongArrayList vertices, boolean sorted) {
    assert !sorted || AbstractLongListUtil.isSorted(vertices);
    this.tx = tx;
    this.vertices = vertices;
    this.sorted = sorted;
}
 
Example #29
Source File: VertexLongList.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public VertexLongList(StandardTitanTx tx) {
    this(tx,new LongArrayList(10),true);
}
 
Example #30
Source File: VertexList.java    From titan1withtp3.1 with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of ids of all vertices in this list of vertices in the same order of the original vertex list.
 * <p/>
 * Uses an efficient primitive variable-sized array.
 *
 * @return A list of idAuthorities of all vertices in this list of vertices in the same order of the original vertex list.
 * @see LongArrayList
 */
public LongArrayList getIDs();