Java Code Examples for com.carrotsearch.hppc.IntObjectHashMap#put()

The following examples show how to use com.carrotsearch.hppc.IntObjectHashMap#put() . 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: BulkWriteResult.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public BulkWriteResult read(Kryo kryo, Input input, Class<BulkWriteResult> type) {
		WriteResult globalStatus = kryo.readObject(input,WriteResult.class);
		int notRunSize = input.readInt();
		IntHashSet notRunRows = new IntHashSet(notRunSize);
		for(int i=0;i<notRunSize;i++){
				notRunRows.add(input.readInt());
		}
		int failedSize = input.readInt();
		IntObjectHashMap<WriteResult> failedRows = new IntObjectHashMap<>(failedSize,0.9f);
		for(int i=0;i<failedSize;i++){
				int k = input.readInt();
				WriteResult result = kryo.readObject(input,WriteResult.class);
				failedRows.put(k,result);
		}
		return new BulkWriteResult(globalStatus,notRunRows,failedRows);
}
 
Example 2
Source File: FetchProjection.java    From crate with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public Map<String, ? extends IntObjectMap<Streamer[]>> generateStreamersGroupedByReaderAndNode() {
    HashMap<String, IntObjectHashMap<Streamer[]>> streamersByReaderByNode = new HashMap<>();
    for (Map.Entry<String, IntSet> entry : nodeReaders.entrySet()) {
        IntObjectHashMap<Streamer[]> streamersByReaderId = new IntObjectHashMap<>();
        String nodeId = entry.getKey();
        streamersByReaderByNode.put(nodeId, streamersByReaderId);
        for (IntCursor readerIdCursor : entry.getValue()) {
            int readerId = readerIdCursor.value;
            String index = readerIndices.floorEntry(readerId).getValue();
            RelationName relationName = indicesToIdents.get(index);
            FetchSource fetchSource = fetchSources.get(relationName);
            if (fetchSource == null) {
                continue;
            }
            streamersByReaderId.put(readerIdCursor.value, Symbols.streamerArray(fetchSource.references()));
        }
    }
    return streamersByReaderByNode;
}
 
Example 3
Source File: NodeFetchRequest.java    From crate with Apache License 2.0 6 votes vote down vote up
public NodeFetchRequest(StreamInput in) throws IOException {
    super(in);
    jobId = new UUID(in.readLong(), in.readLong());
    fetchPhaseId = in.readVInt();
    closeContext = in.readBoolean();
    int numReaders = in.readVInt();
    if (numReaders > 0) {
        IntObjectHashMap<IntArrayList> toFetch = new IntObjectHashMap<>(numReaders);
        for (int i = 0; i < numReaders; i++) {
            int readerId = in.readVInt();
            int numDocs = in.readVInt();
            IntArrayList docs = new IntArrayList(numDocs);
            toFetch.put(readerId, docs);
            for (int j = 0; j < numDocs; j++) {
                docs.add(in.readInt());
            }
        }
        this.toFetch = toFetch;
    } else {
        this.toFetch = null;
    }
}
 
Example 4
Source File: NodeFetchRequestTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testStreaming() throws Exception {

    IntObjectHashMap<IntContainer> toFetch = new IntObjectHashMap<>();
    IntHashSet docIds = new IntHashSet(3);
    toFetch.put(1, docIds);

    NodeFetchRequest orig = new NodeFetchRequest(UUID.randomUUID(), 1, true, toFetch);

    BytesStreamOutput out = new BytesStreamOutput();
    orig.writeTo(out);

    StreamInput in = out.bytes().streamInput();

    NodeFetchRequest streamed = new NodeFetchRequest(in);

    assertThat(orig.jobId(), is(streamed.jobId()));
    assertThat(orig.fetchPhaseId(), is(streamed.fetchPhaseId()));
    assertThat(orig.isCloseContext(), is(streamed.isCloseContext()));
    assertThat(orig.toFetch().toString(), is(streamed.toFetch().toString()));
}
 
Example 5
Source File: QueryManager.java    From Bats with Apache License 2.0 5 votes vote down vote up
private void addFragment(final FragmentData fragmentData) {
  final FragmentHandle fragmentHandle = fragmentData.getHandle();
  final int majorFragmentId = fragmentHandle.getMajorFragmentId();
  final int minorFragmentId = fragmentHandle.getMinorFragmentId();

  IntObjectHashMap<FragmentData> minorMap = fragmentDataMap.get(majorFragmentId);
  if (minorMap == null) {
    minorMap = new IntObjectHashMap<>();
    fragmentDataMap.put(majorFragmentId, minorMap);
  }
  minorMap.put(minorFragmentId, fragmentData);
  fragmentDataSet.add(fragmentData);
}
 
Example 6
Source File: NumericDateAnalyzer.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public static synchronized NamedAnalyzer buildNamedAnalyzer(FormatDateTimeFormatter formatter, int precisionStep) {
    IntObjectHashMap<NamedAnalyzer> precisionMap = globalAnalyzers.get(formatter.format());
    if (precisionMap == null) {
        precisionMap = new IntObjectHashMap<>();
        globalAnalyzers.put(formatter.format(), precisionMap);
    }
    NamedAnalyzer namedAnalyzer = precisionMap.get(precisionStep);
    if (namedAnalyzer == null) {
        String name = "_date/" + ((precisionStep == Integer.MAX_VALUE) ? "max" : precisionStep);
        namedAnalyzer = new NamedAnalyzer(name, AnalyzerScope.GLOBAL, new NumericDateAnalyzer(precisionStep, formatter.parser()));
        precisionMap.put(precisionStep, namedAnalyzer);
    }
    return namedAnalyzer;
}
 
Example 7
Source File: HppcIntObjectMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final IntObjectHashMap<Integer> m_map = new IntObjectHashMap<>( m_keys.length, 0.5f );
    for ( int i = 0; i < m_keys.length; ++i )
        m_map.put( m_keys[ i ], null );
    for ( int i = 0; i < m_keys.length; ++i )
        m_map.put( m_keys[ i ], null );
    return m_map.size();
}
 
Example 8
Source File: HppcIntObjectMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final IntObjectHashMap<Integer> m_map = new IntObjectHashMap<>( m_keys.length / 2 + 1, 0.5f );
    final Integer value = 1;
    int add = 0, remove = 0;
    while ( add < m_keys.length )
    {
        m_map.put( m_keys[ add ], value );
        ++add;
        m_map.put( m_keys[ add ], value );
        ++add;
        m_map.remove( m_keys[ remove++ ] );
    }
    return m_map.size();
}
 
Example 9
Source File: ReaderBuckets.java    From crate with Apache License 2.0 5 votes vote down vote up
public IntObjectHashMap<IntContainer> generateToFetch(IntSet readerIds) {
    IntObjectHashMap<IntContainer> toFetch = new IntObjectHashMap<>(readerIds.size());
    for (IntCursor readerIdCursor : readerIds) {
        ReaderBucket readerBucket = readerBuckets.get(readerIdCursor.value);
        if (readerBucket != null && readerBucket.docs.size() > 0) {
            toFetch.put(readerIdCursor.value, readerBucket.docs.keys());
        }
    }
    return toFetch;
}
 
Example 10
Source File: JobSetup.java    From crate with Apache License 2.0 5 votes vote down vote up
private static IntObjectHashMap<NodeOperation> groupNodeOperationsByPhase(Collection<? extends NodeOperation> nodeOperations) {
    IntObjectHashMap<NodeOperation> map = new IntObjectHashMap<>(nodeOperations.size());
    for (NodeOperation nodeOperation : nodeOperations) {
        map.put(nodeOperation.executionPhase().phaseId(), nodeOperation);
    }
    return map;
}
 
Example 11
Source File: NodeFetchResponseTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Before
public void setUpStreamBucketsAndStreamer() throws Exception {
    streamers = new IntObjectHashMap<>(1);
    streamers.put(1, new Streamer[]{DataTypes.BOOLEAN.streamer()});

    IntObjectHashMap<IntContainer> toFetch = new IntObjectHashMap<>();
    IntHashSet docIds = new IntHashSet(3);
    toFetch.put(1, docIds);
    StreamBucket.Builder builder = new StreamBucket.Builder(streamers.get(1), RamAccounting.NO_ACCOUNTING);
    builder.add(new RowN(new Object[]{true}));
    fetched = new IntObjectHashMap<>(1);
    fetched.put(1, builder.build());
}
 
Example 12
Source File: BulkWriteActionRetryTest.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testRetryNoRouteToHostException() throws Throwable {
    WriteConfiguration config = new DefaultWriteConfiguration(new Monitor(0,0,10,10L,0),pef);
    WriteResult writeResult = new WriteResult(Code.FAILED, "NoRouteToHostException:No route to host");
    BulkWriteResult bulkWriteResult = new BulkWriteResult(writeResult);
    WriteResponse response = config.processGlobalResult(bulkWriteResult);
    Assert.assertEquals(WriteResponse.RETRY, response);

    writeResult = new WriteResult(Code.FAILED, "FailedServerException:This server is in the failed servers list");
    bulkWriteResult = new BulkWriteResult(writeResult);
    response = config.processGlobalResult(bulkWriteResult);
    Assert.assertEquals(WriteResponse.RETRY, response);

    writeResult = new WriteResult(Code.FAILED, "ServerNotRunningYetException");
    bulkWriteResult = new BulkWriteResult(writeResult);
    response = config.processGlobalResult(bulkWriteResult);
    Assert.assertEquals(WriteResponse.RETRY, response);

    writeResult = new WriteResult(Code.FAILED, "ConnectTimeoutException");
    bulkWriteResult = new BulkWriteResult(writeResult);
    response = config.processGlobalResult(bulkWriteResult);
    Assert.assertEquals(WriteResponse.RETRY, response);

    writeResult = new WriteResult(Code.PARTIAL);
    IntObjectHashMap<WriteResult> failedRows = new IntObjectHashMap<>();
    failedRows.put(1, new WriteResult(Code.FAILED, "NoRouteToHostException:No route to host"));
    bulkWriteResult = new BulkWriteResult(writeResult, new IntHashSet(), failedRows);
    response = config.partialFailure(bulkWriteResult, null);
    Assert.assertEquals(WriteResponse.RETRY, response);


    writeResult = new WriteResult(Code.PARTIAL);
    failedRows = new IntObjectHashMap<>();
    failedRows.put(1, new WriteResult(Code.FAILED, "FailedServerException:This server is in the failed servers list"));
    bulkWriteResult = new BulkWriteResult(writeResult, new IntHashSet(), failedRows);
    response = config.partialFailure(bulkWriteResult, null);
    Assert.assertEquals(WriteResponse.RETRY, response);

    writeResult = new WriteResult(Code.PARTIAL);
    failedRows = new IntObjectHashMap<>();
    failedRows.put(1, new WriteResult(Code.FAILED, "ServerNotRunningYetException"));
    bulkWriteResult = new BulkWriteResult(writeResult, new IntHashSet(), failedRows);
    response = config.partialFailure(bulkWriteResult, null);
    Assert.assertEquals(WriteResponse.RETRY, response);

    writeResult = new WriteResult(Code.PARTIAL);
    failedRows = new IntObjectHashMap<>();
    failedRows.put(1, new WriteResult(Code.FAILED, "ConnectTimeoutException"));
    bulkWriteResult = new BulkWriteResult(writeResult, new IntHashSet(), failedRows);
    response = config.partialFailure(bulkWriteResult, null);
    Assert.assertEquals(WriteResponse.RETRY, response);


    NoRouteToHostException nrthe = new NoRouteToHostException();
    response = config.globalError(nrthe);
    Assert.assertEquals(WriteResponse.RETRY, response);

    FailedServerException failedServerException = new FailedServerException("Failed server");
    response = config.globalError(failedServerException);
    Assert.assertEquals(WriteResponse.RETRY, response);

    ServerNotRunningYetException serverNotRunningYetException = new ServerNotRunningYetException("Server not running");
    response = config.globalError(serverNotRunningYetException);
    Assert.assertEquals(WriteResponse.RETRY, response);

    ConnectTimeoutException connectTimeoutException = new ConnectTimeoutException("connect timeout");
    response = config.globalError(connectTimeoutException);
    Assert.assertEquals(WriteResponse.RETRY, response);
}
 
Example 13
Source File: FetchRowsTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void test_fetch_rows_can_map_inputs_and_buckets_to_outputs() throws Exception {
    var e = SQLExecutor.builder(clusterService)
        .addTable("create table t1 (x text)")
        .addTable("create table t2 (y text, z int)")
        .build();
    var t1 = e.resolveTableInfo("t1");
    var x = (Reference) e.asSymbol("x");
    var fetchSource1 = new FetchSource();
    fetchSource1.addFetchIdColumn(new InputColumn(0, DataTypes.LONG));
    fetchSource1.addRefToFetch(x);

    var t2 = e.resolveTableInfo("t2");
    var y = (Reference) e.asSymbol("y");
    var fetchSource2 = new FetchSource();
    fetchSource2.addFetchIdColumn(new InputColumn(1, DataTypes.LONG));
    fetchSource2.addRefToFetch(y);

    var fetchSources = Map.of(
        t1.ident(), fetchSource1,
        t2.ident(), fetchSource2
    );
    var fetchRows = FetchRows.create(
        CoordinatorTxnCtx.systemTransactionContext(),
        e.functions(),
        fetchSources,
        List.of(
            new FetchReference(new InputColumn(0, DataTypes.LONG), x),
            new FetchReference(new InputColumn(1, DataTypes.LONG), y),
            new InputColumn(2, DataTypes.INTEGER)
        )
    );
    long fetchIdRel1 = FetchId.encode(1, 1);
    long fetchIdRel2 = FetchId.encode(2, 1);
    var readerBuckets = new ReaderBuckets(fetchRows);
    readerBuckets.add(new RowN(fetchIdRel1, fetchIdRel2, 42));
    IntObjectHashMap<Bucket> results = new IntObjectHashMap<>();
    results.put(1, new ArrayBucket($$($("Arthur"))));
    results.put(2, new ArrayBucket($$($("Trillian"))));

    var it = readerBuckets.getOutputRows(List.of(results));
    assertThat(it.hasNext(), is(true));
    var outputRow = it.next();

    assertThat(outputRow.get(0), is("Arthur"));
    assertThat(outputRow.get(1), is("Trillian"));
    assertThat(outputRow.get(2), is(42));
}