Search in sources :

Example 11 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class JobCollectContextTest method testThreadPoolNameForNonDocTables.

@Test
public void testThreadPoolNameForNonDocTables() throws Exception {
    RoutedCollectPhase collectPhase = Mockito.mock(RoutedCollectPhase.class);
    Routing routing = Mockito.mock(Routing.class);
    when(collectPhase.routing()).thenReturn(routing);
    when(routing.containsShards(localNodeId)).thenReturn(false);
    // sys.cluster (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.CLUSTER);
    String threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
    // partition values only of a partitioned doc table (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.PARTITION);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
    // sys.nodes (single row collector)
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.NODE);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.MANAGEMENT));
    // sys.shards
    when(routing.containsShards(localNodeId)).thenReturn(true);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.SHARD);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.MANAGEMENT));
    when(routing.containsShards(localNodeId)).thenReturn(false);
    // information_schema.*
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    threadPoolExecutorName = JobCollectContext.threadPoolName(collectPhase, localNodeId);
    assertThat(threadPoolExecutorName, is(ThreadPool.Names.PERCOLATE));
}
Also used : Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 12 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class DistributingDownstreamFactoryTest method createDownstream.

private BatchConsumer createDownstream(Set<String> downstreamExecutionNodes) {
    UUID jobId = UUID.randomUUID();
    Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("n1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Arrays.asList(1, 2)).map()).map());
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 1, "collect", routing, RowGranularity.DOC, ImmutableList.<Symbol>of(), ImmutableList.<Projection>of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_MODULO);
    MergePhase mergePhase = new MergePhase(jobId, 2, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(LongType.INSTANCE), ImmutableList.<Projection>of(), DistributionInfo.DEFAULT_BROADCAST, null);
    mergePhase.executionNodes(downstreamExecutionNodes);
    NodeOperation nodeOperation = NodeOperation.withDownstream(collectPhase, mergePhase, (byte) 0, "nodeName");
    return rowDownstreamFactory.create(nodeOperation, collectPhase.distributionInfo(), jobId, Paging.PAGE_SIZE);
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Routing(io.crate.metadata.Routing) ImmutableList(com.google.common.collect.ImmutableList) NodeOperation(io.crate.operation.NodeOperation) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 13 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class WhereClauseAnalyzerTest method init.

@Before
public void init() throws Exception {
    SQLExecutor.Builder builder = SQLExecutor.builder(new NoopClusterService());
    registerTables(builder);
    TestingTableInfo.Builder genInfo = TestingTableInfo.builder(new TableIdent(DocSchemaInfo.NAME, GENERATED_COL_TABLE_NAME), new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of())).add("ts", DataTypes.TIMESTAMP, null).add("x", DataTypes.INTEGER, null).add("y", DataTypes.LONG, null).addGeneratedColumn("day", DataTypes.TIMESTAMP, "date_trunc('day', ts)", true).addGeneratedColumn("minus_y", DataTypes.LONG, "y * -1", true).addGeneratedColumn("x_incr", DataTypes.LONG, "x + 1", false).addPartitions(new PartitionName("generated_col", Arrays.asList(new BytesRef("1420070400000"), new BytesRef("-1"))).asIndexName(), new PartitionName("generated_col", Arrays.asList(new BytesRef("1420156800000"), new BytesRef("-2"))).asIndexName());
    builder.addDocTable(genInfo);
    TableIdent ident = new TableIdent(DocSchemaInfo.NAME, DOUBLE_GEN_PARTITIONED_TABLE_NAME);
    TestingTableInfo.Builder doubleGenPartedInfo = TestingTableInfo.builder(ident, new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of())).add("x", DataTypes.INTEGER, null).addGeneratedColumn("x1", DataTypes.LONG, "x+1", true).addGeneratedColumn("x2", DataTypes.LONG, "x+2", true).addPartitions(new PartitionName(ident, Arrays.asList(new BytesRef("4"), new BytesRef("5"))).toString(), new PartitionName(ident, Arrays.asList(new BytesRef("5"), new BytesRef("6"))).toString());
    builder.addDocTable(doubleGenPartedInfo);
    e = builder.build();
}
Also used : Routing(io.crate.metadata.Routing) TableIdent(io.crate.metadata.TableIdent) TestingTableInfo(io.crate.metadata.table.TestingTableInfo) PartitionName(io.crate.metadata.PartitionName) SQLExecutor(io.crate.testing.SQLExecutor) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) BytesRef(org.apache.lucene.util.BytesRef) Before(org.junit.Before)

Example 14 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class FetchContext method innerPrepare.

@Override
public void innerPrepare() {
    HashMap<String, TableIdent> index2TableIdent = new HashMap<>();
    for (Map.Entry<TableIdent, Collection<String>> entry : phase.tableIndices().asMap().entrySet()) {
        for (String indexName : entry.getValue()) {
            index2TableIdent.put(indexName, entry.getKey());
        }
    }
    Set<TableIdent> tablesWithFetchRefs = new HashSet<>();
    for (Reference reference : phase.fetchRefs()) {
        tablesWithFetchRefs.add(reference.ident().tableIdent());
    }
    for (Routing routing : routingIterable) {
        Map<String, Map<String, List<Integer>>> locations = routing.locations();
        Map<String, List<Integer>> indexShards = locations.get(localNodeId);
        for (Map.Entry<String, List<Integer>> indexShardsEntry : indexShards.entrySet()) {
            String index = indexShardsEntry.getKey();
            Integer base = phase.bases().get(index);
            if (base == null) {
                continue;
            }
            TableIdent ident = index2TableIdent.get(index);
            assert ident != null : "no tableIdent found for index " + index;
            tableIdents.put(base, ident);
            toFetch.put(ident, new ArrayList<Reference>());
            for (Integer shard : indexShardsEntry.getValue()) {
                ShardId shardId = new ShardId(index, shard);
                int readerId = base + shardId.id();
                SharedShardContext shardContext = shardContexts.get(readerId);
                if (shardContext == null) {
                    shardContext = sharedShardContexts.createContext(shardId, readerId);
                    shardContexts.put(readerId, shardContext);
                    if (tablesWithFetchRefs.contains(ident)) {
                        try {
                            searchers.put(readerId, shardContext.acquireSearcher());
                        } catch (IndexNotFoundException e) {
                            if (!PartitionName.isPartition(index)) {
                                throw e;
                            }
                        }
                    }
                }
            }
        }
    }
    for (Reference reference : phase.fetchRefs()) {
        Collection<Reference> references = toFetch.get(reference.ident().tableIdent());
        if (references != null) {
            references.add(reference);
        }
    }
}
Also used : IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) Reference(io.crate.metadata.Reference) Routing(io.crate.metadata.Routing) TableIdent(io.crate.metadata.TableIdent) ShardId(org.elasticsearch.index.shard.ShardId) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) SharedShardContext(io.crate.action.job.SharedShardContext)

Example 15 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class RoutedCollectPhaseTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    ImmutableList<Symbol> toCollect = ImmutableList.<Symbol>of(new Value(DataTypes.STRING));
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase cn = new RoutedCollectPhase(jobId, 0, "cn", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of()), RowGranularity.DOC, toCollect, ImmutableList.<Projection>of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_MODULO);
    BytesStreamOutput out = new BytesStreamOutput();
    cn.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    RoutedCollectPhase cn2 = RoutedCollectPhase.FACTORY.create();
    cn2.readFrom(in);
    assertThat(cn, equalTo(cn2));
    assertThat(cn.toCollect(), is(cn2.toCollect()));
    assertThat(cn.nodeIds(), is(cn2.nodeIds()));
    assertThat(cn.jobId(), is(cn2.jobId()));
    assertThat(cn.phaseId(), is(cn2.phaseId()));
    assertThat(cn.maxRowGranularity(), is(cn2.maxRowGranularity()));
    assertThat(cn.distributionInfo(), is(cn2.distributionInfo()));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Value(io.crate.analyze.symbol.Value) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Routing(io.crate.metadata.Routing) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Routing (io.crate.metadata.Routing)17 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)10 Test (org.junit.Test)9 CrateUnitTest (io.crate.test.integration.CrateUnitTest)6 ImmutableList (com.google.common.collect.ImmutableList)4 Reference (io.crate.metadata.Reference)4 TableIdent (io.crate.metadata.TableIdent)4 Map (java.util.Map)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Symbol (io.crate.analyze.symbol.Symbol)3 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)3 List (java.util.List)3 SharedShardContexts (io.crate.action.job.SharedShardContexts)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 PartitionName (io.crate.metadata.PartitionName)2 NodeOperation (io.crate.operation.NodeOperation)2 JobsLogs (io.crate.operation.collect.stats.JobsLogs)2 MergePhase (io.crate.planner.node.dql.MergePhase)2 SysUpdateProjection (io.crate.planner.projection.SysUpdateProjection)2 Before (org.junit.Before)2