Search in sources :

Example 11 with RelationName

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

the class FilterOnJoinsUtil method moveQueryBelowJoin.

static LogicalPlan moveQueryBelowJoin(Symbol query, LogicalPlan join) {
    if (!WhereClause.canMatch(query)) {
        return join.replaceSources(List.of(getNewSource(query, join.sources().get(0)), getNewSource(query, join.sources().get(1))));
    }
    Map<Set<RelationName>, Symbol> splitQuery = QuerySplitter.split(query);
    int initialParts = splitQuery.size();
    if (splitQuery.size() == 1 && splitQuery.keySet().iterator().next().size() > 1) {
        return null;
    }
    assert join.sources().size() == 2 : "Join operator must only have 2 children, LHS and RHS";
    LogicalPlan lhs = join.sources().get(0);
    LogicalPlan rhs = join.sources().get(1);
    Set<RelationName> leftName = lhs.getRelationNames();
    Set<RelationName> rightName = rhs.getRelationNames();
    Symbol queryForLhs = splitQuery.remove(leftName);
    Symbol queryForRhs = splitQuery.remove(rightName);
    LogicalPlan newLhs = getNewSource(queryForLhs, lhs);
    LogicalPlan newRhs = getNewSource(queryForRhs, rhs);
    LogicalPlan newJoin = join.replaceSources(List.of(newLhs, newRhs));
    if (splitQuery.isEmpty()) {
        return newJoin;
    } else if (initialParts == splitQuery.size()) {
        return null;
    } else {
        return new Filter(newJoin, AndOperator.join(splitQuery.values()));
    }
}
Also used : Set(java.util.Set) Filter(io.crate.planner.operators.Filter) Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) LogicalPlan(io.crate.planner.operators.LogicalPlan)

Example 12 with RelationName

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

the class FetchPhase method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(executionPhaseId);
    out.writeVInt(executionNodes.size());
    for (String executionNode : executionNodes) {
        out.writeString(executionNode);
    }
    out.writeVInt(bases.size());
    for (Map.Entry<String, Integer> entry : bases.entrySet()) {
        out.writeString(entry.getKey());
        out.writeVInt(entry.getValue());
    }
    out.writeVInt(fetchRefs.size());
    for (Reference ref : fetchRefs) {
        Reference.toStream(ref, out);
    }
    out.writeVInt(tableIndices.size());
    for (Map.Entry<RelationName, Collection<String>> entry : tableIndices.entrySet()) {
        entry.getKey().writeTo(out);
        out.writeVInt(entry.getValue().size());
        for (String s : entry.getValue()) {
            out.writeString(s);
        }
    }
}
Also used : Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) Collection(java.util.Collection) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 13 with RelationName

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

the class FetchProjection method generateStreamersGroupedByReaderAndNode.

@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;
}
Also used : FetchSource(io.crate.planner.node.fetch.FetchSource) HashMap(java.util.HashMap) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) IntSet(com.carrotsearch.hppc.IntSet) Streamer(io.crate.Streamer) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) RelationName(io.crate.metadata.RelationName) HashMap(java.util.HashMap) IntObjectMap(com.carrotsearch.hppc.IntObjectMap) TreeMap(java.util.TreeMap) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) Map(java.util.Map)

Example 14 with RelationName

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

the class FetchProjection method getFetchSourceByReader.

public FetchSource getFetchSourceByReader(int readerId) {
    String index = readerIndices.floorEntry(readerId).getValue();
    RelationName relationName = indicesToIdents.get(index);
    assert relationName != null : "Must have a relationName for readerId=" + readerId;
    FetchSource fetchSource = fetchSources.get(relationName);
    assert fetchSource != null : "Must have a fetchSource for relationName=" + relationName;
    return fetchSource;
}
Also used : FetchSource(io.crate.planner.node.fetch.FetchSource) RelationName(io.crate.metadata.RelationName)

Example 15 with RelationName

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

the class TransportSwapRelationsAction method checkBlock.

@Override
protected ClusterBlockException checkBlock(SwapRelationsRequest request, ClusterState state) {
    Set<String> affectedIndices = new HashSet<>();
    for (RelationNameSwap swapAction : request.swapActions()) {
        affectedIndices.addAll(Arrays.asList(indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.LENIENT_EXPAND_OPEN, swapAction.source().indexNameOrAlias())));
        affectedIndices.addAll(Arrays.asList(indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.LENIENT_EXPAND_OPEN, swapAction.target().indexNameOrAlias())));
    }
    for (RelationName dropRelation : request.dropRelations()) {
        affectedIndices.addAll(Arrays.asList(indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.LENIENT_EXPAND_OPEN, dropRelation.indexNameOrAlias())));
    }
    return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, affectedIndices.toArray(new String[0]));
}
Also used : RelationName(io.crate.metadata.RelationName) HashSet(java.util.HashSet)

Aggregations

RelationName (io.crate.metadata.RelationName)180 Test (org.junit.Test)100 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 PartitionName (io.crate.metadata.PartitionName)47 Symbol (io.crate.expression.symbol.Symbol)42 Reference (io.crate.metadata.Reference)37 ColumnIdent (io.crate.metadata.ColumnIdent)31 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)21 ReferenceIdent (io.crate.metadata.ReferenceIdent)21 DocTableInfo (io.crate.metadata.doc.DocTableInfo)21 Map (java.util.Map)20 HashMap (java.util.HashMap)19 SqlExpressions (io.crate.testing.SqlExpressions)18 ArrayList (java.util.ArrayList)18 List (java.util.List)17 Before (org.junit.Before)17 DocTableRelation (io.crate.analyze.relations.DocTableRelation)13 SQLExecutor (io.crate.testing.SQLExecutor)11 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)10 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)10