Search in sources :

Example 91 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project crate by crate.

the class InternalCountOperationTest method testCount.

@Test
public void testCount() throws Exception {
    execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
    ensureYellow();
    execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
    execute("refresh table t");
    CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
    ClusterService clusterService = internalCluster().getDataNodeInstance(ClusterService.class);
    CoordinatorTxnCtx txnCtx = CoordinatorTxnCtx.systemTransactionContext();
    Metadata metadata = clusterService.state().getMetadata();
    Index index = metadata.index(getFqn("t")).getIndex();
    IntArrayList shards = new IntArrayList(1);
    shards.add(0);
    Map<String, IntIndexedContainer> indexShards = Map.of(index.getName(), shards);
    {
        CompletableFuture<Long> count = countOperation.count(txnCtx, indexShards, Literal.BOOLEAN_TRUE);
        assertThat(count.get(5, TimeUnit.SECONDS), is(3L));
    }
    Schemas schemas = internalCluster().getInstance(Schemas.class);
    TableInfo tableInfo = schemas.getTableInfo(new RelationName(sqlExecutor.getCurrentSchema(), "t"));
    TableRelation tableRelation = new TableRelation(tableInfo);
    Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
    SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
    Symbol filter = sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'"));
    {
        CompletableFuture<Long> count = countOperation.count(txnCtx, indexShards, filter);
        assertThat(count.get(5, TimeUnit.SECONDS), is(1L));
    }
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Symbol(io.crate.expression.symbol.Symbol) Metadata(org.elasticsearch.cluster.metadata.Metadata) Index(org.elasticsearch.index.Index) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Schemas(io.crate.metadata.Schemas) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) TableRelation(io.crate.analyze.relations.TableRelation) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterService(org.elasticsearch.cluster.service.ClusterService) RelationName(io.crate.metadata.RelationName) TableInfo(io.crate.metadata.table.TableInfo) IntArrayList(com.carrotsearch.hppc.IntArrayList) SqlExpressions(io.crate.testing.SqlExpressions) Test(org.junit.Test)

Example 92 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project crate by crate.

the class FetchTaskTest method testSearcherIsAcquiredForShard.

@Test
public void testSearcherIsAcquiredForShard() throws Exception {
    IntArrayList shards = IntArrayList.from(1, 2);
    Routing routing = new Routing(Map.of("dummy", Map.of("i1", shards)));
    IndexBaseBuilder ibb = new IndexBaseBuilder();
    ibb.allocate("i1", shards);
    Map<RelationName, Collection<String>> tableIndices = new HashMap<>();
    tableIndices.put(new RelationName(Schemas.DOC_SCHEMA_NAME, "i1"), List.of("i1"));
    Metadata metadata = Metadata.builder().put(IndexMetadata.builder("i1").settings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put(SETTING_VERSION_CREATED, Version.CURRENT)).build(), true).build();
    final FetchTask context = new FetchTask(UUID.randomUUID(), new FetchPhase(1, null, ibb.build(), tableIndices, List.of(createReference("i1", new ColumnIdent("x"), DataTypes.STRING))), "dummy", new SharedShardContexts(mock(IndicesService.class, RETURNS_MOCKS), UnaryOperator.identity()), metadata, relationName -> null, List.of(routing));
    context.start();
    assertThat(context.searcher(1), Matchers.notNullValue());
    assertThat(context.searcher(2), Matchers.notNullValue());
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) HashMap(java.util.HashMap) FetchPhase(io.crate.execution.dsl.phases.FetchPhase) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) Routing(io.crate.metadata.Routing) RelationName(io.crate.metadata.RelationName) Collection(java.util.Collection) IntArrayList(com.carrotsearch.hppc.IntArrayList) IndexBaseBuilder(io.crate.planner.fetch.IndexBaseBuilder) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 93 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project crate by crate.

the class NodeFetchRequestTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    IntObjectHashMap<IntArrayList> toFetch = new IntObjectHashMap<>();
    IntArrayList docIds = new IntArrayList(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()));
}
Also used : IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) StreamInput(org.elasticsearch.common.io.stream.StreamInput) IntArrayList(com.carrotsearch.hppc.IntArrayList) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 94 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project crate by crate.

the class TransportFetchOperationTest method test_ram_accounting_on_non_empty_fetch_ids_and_close.

@Test
public void test_ram_accounting_on_non_empty_fetch_ids_and_close() {
    var toFetch = new IntObjectHashMap<IntContainer>();
    toFetch.put(1, new IntArrayList());
    RamAccounting ramAccounting = TransportFetchOperation.ramAccountingForIncomingResponse(RamAccounting.NO_ACCOUNTING, toFetch, true);
    assertThat(ramAccounting, instanceOf(BlockBasedRamAccounting.class));
}
Also used : BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) RamAccounting(io.crate.breaker.RamAccounting) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) IntArrayList(com.carrotsearch.hppc.IntArrayList) Test(org.junit.Test)

Aggregations

IntArrayList (com.carrotsearch.hppc.IntArrayList)94 Test (org.junit.jupiter.api.Test)16 RepeatedTest (org.junit.jupiter.api.RepeatedTest)13 GHPoint (com.graphhopper.util.shapes.GHPoint)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)7 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)5 HashMap (java.util.HashMap)5 UUID (java.util.UUID)5 GHIntArrayList (com.graphhopper.coll.GHIntArrayList)4 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)4 RelationName (io.crate.metadata.RelationName)4 IOException (java.io.IOException)4 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)3 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)3 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3