Search in sources :

Example 26 with TableIdent

use of io.crate.metadata.TableIdent 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 27 with TableIdent

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

the class FetchProjectorContext method createReaderBucket.

private ReaderBucket createReaderBucket(int readerId) {
    String index = readerIdToIndex.floorEntry(readerId).getValue();
    TableIdent tableIdent = indexToTable.get(index);
    FetchSource fetchSource = tableToFetchSource.get(tableIdent);
    assert fetchSource != null : "fetchSource must be available";
    return new ReaderBucket(!fetchSource.references().isEmpty(), partitionValues(index, fetchSource.partitionedByColumns()));
}
Also used : FetchSource(io.crate.planner.node.fetch.FetchSource) TableIdent(io.crate.metadata.TableIdent)

Example 28 with TableIdent

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

the class FetchProjectorContext method getFetchSource.

@Nullable
private FetchSource getFetchSource(int readerId) {
    String index = readerIdToIndex.floorEntry(readerId).getValue();
    TableIdent tableIdent = indexToTable.get(index);
    return tableToFetchSource.get(tableIdent);
}
Also used : TableIdent(io.crate.metadata.TableIdent) Nullable(javax.annotation.Nullable)

Example 29 with TableIdent

use of io.crate.metadata.TableIdent 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 30 with TableIdent

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

the class NodeFetchOperation method doFetch.

private void doFetch(FetchContext fetchContext, SettableFuture<IntObjectMap<StreamBucket>> resultFuture, IntObjectMap<? extends IntContainer> toFetch) throws Exception {
    final IntObjectHashMap<StreamBucket> fetched = new IntObjectHashMap<>(toFetch.size());
    HashMap<TableIdent, TableFetchInfo> tableFetchInfos = getTableFetchInfos(fetchContext);
    final AtomicReference<Throwable> lastThrowable = new AtomicReference<>(null);
    final AtomicInteger threadLatch = new AtomicInteger(toFetch.size());
    for (IntObjectCursor<? extends IntContainer> toFetchCursor : toFetch) {
        final int readerId = toFetchCursor.key;
        final IntContainer docIds = toFetchCursor.value;
        TableIdent ident = fetchContext.tableIdent(readerId);
        final TableFetchInfo tfi = tableFetchInfos.get(ident);
        assert tfi != null : "tfi must not be null";
        CollectRunnable runnable = new CollectRunnable(tfi.createCollector(readerId), docIds, fetched, readerId, lastThrowable, threadLatch, resultFuture, fetchContext.isKilled());
        try {
            executor.execute(runnable);
        } catch (EsRejectedExecutionException | RejectedExecutionException e) {
            runnable.run();
        }
    }
}
Also used : IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) TableIdent(io.crate.metadata.TableIdent) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamBucket(io.crate.executor.transport.StreamBucket) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntContainer(com.carrotsearch.hppc.IntContainer) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Aggregations

TableIdent (io.crate.metadata.TableIdent)41 Test (org.junit.Test)18 CrateUnitTest (io.crate.test.integration.CrateUnitTest)15 PartitionName (io.crate.metadata.PartitionName)8 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)7 Before (org.junit.Before)7 Reference (io.crate.metadata.Reference)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 List (java.util.List)5 Routing (io.crate.metadata.Routing)4 QualifiedName (io.crate.sql.tree.QualifiedName)4 BytesRef (org.apache.lucene.util.BytesRef)4 TableRelation (io.crate.analyze.relations.TableRelation)3 ReferenceIdent (io.crate.metadata.ReferenceIdent)3 TestingTableInfo (io.crate.metadata.table.TestingTableInfo)3 SqlExpressions (io.crate.testing.SqlExpressions)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)2 ImmutableList (com.google.common.collect.ImmutableList)2 SharedShardContexts (io.crate.action.job.SharedShardContexts)2