com.espertech.esper.epl.join.plan
Class NStreamQueryPlanBuilder

java.lang.Object
  extended by com.espertech.esper.epl.join.plan.NStreamQueryPlanBuilder

public class NStreamQueryPlanBuilder
extends java.lang.Object

Builds a query plan for 3 or more streams in a join.


Nested Class Summary
static class NStreamQueryPlanBuilder.BestChainResult
          Encapsulates the chain information.
 
Constructor Summary
NStreamQueryPlanBuilder()
           
 
Method Summary
protected static QueryPlan build(QueryGraph queryGraph, EventType[] typesPerStream, HistoricalViewableDesc historicalViewableDesc, DependencyGraph dependencyGraph, HistoricalStreamIndexList[] historicalStreamIndexLists, boolean hasForceNestedIter, java.lang.String[][][] indexedStreamsUniqueProps, TableMetadata[] tablesPerStream)
          Build a query plan based on the stream property relationships indicated in queryGraph.
protected static int[] buildDefaultNestingOrder(int numStreams, int forStream)
          Returns default nesting order for a given number of streams for a certain stream.
protected static NStreamQueryPlanBuilder.BestChainResult computeBestPath(int lookupStream, QueryGraph queryGraph, DependencyGraph dependencyGraph)
          Compute a best chain or path for lookups to take for the lookup stream passed in and the query property relationships.
protected static int computeNavigableDepth(int lookupStream, int[] nextStreams, QueryGraph queryGraph)
          Given a chain of streams to look up and indexing information, compute the index within the chain of the first non-index lookup.
static TableLookupPlan createLookupPlan(QueryGraph queryGraph, int currentLookupStream, int indexedStream, QueryPlanIndex indexSpecs, EventType[] typesPerStream, TableMetadata indexedStreamTableMeta)
          Create the table lookup plan for a from-stream to look up in an indexed stream using the columns supplied in the query graph and looking at the actual indexes available and their index number.
protected static QueryPlanNode createStreamPlan(int lookupStream, int[] bestChain, QueryGraph queryGraph, QueryPlanIndex[] indexSpecsPerStream, EventType[] typesPerStream, boolean[] isHistorical, HistoricalStreamIndexList[] historicalStreamIndexLists, TableMetadata[] tablesPerStream)
          Walks the chain of lookups and constructs lookup strategy and plan specification based on the index specifications.
protected static boolean isDependencySatisfied(int lookupStream, int[] permutation, DependencyGraph dependencyGraph)
          Determine if the proposed permutation of lookups passes dependencies
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NStreamQueryPlanBuilder

public NStreamQueryPlanBuilder()
Method Detail

build

protected static QueryPlan build(QueryGraph queryGraph,
                                 EventType[] typesPerStream,
                                 HistoricalViewableDesc historicalViewableDesc,
                                 DependencyGraph dependencyGraph,
                                 HistoricalStreamIndexList[] historicalStreamIndexLists,
                                 boolean hasForceNestedIter,
                                 java.lang.String[][][] indexedStreamsUniqueProps,
                                 TableMetadata[] tablesPerStream)
Build a query plan based on the stream property relationships indicated in queryGraph.

Parameters:
queryGraph - - navigation info between streams
typesPerStream - - event types for each stream
dependencyGraph - - dependencies between historical streams
historicalStreamIndexLists - - index management, populated for the query plan
Returns:
query plan

createStreamPlan

protected static QueryPlanNode createStreamPlan(int lookupStream,
                                                int[] bestChain,
                                                QueryGraph queryGraph,
                                                QueryPlanIndex[] indexSpecsPerStream,
                                                EventType[] typesPerStream,
                                                boolean[] isHistorical,
                                                HistoricalStreamIndexList[] historicalStreamIndexLists,
                                                TableMetadata[] tablesPerStream)
Walks the chain of lookups and constructs lookup strategy and plan specification based on the index specifications.

Parameters:
lookupStream - - the stream to construct the query plan for
bestChain - - the chain that the lookup follows to make best use of indexes
queryGraph - - the repository for key properties to indexes
indexSpecsPerStream - - specifications of indexes
typesPerStream - - event types for each stream
isHistorical - - indicator for each stream if it is a historical streams or not
historicalStreamIndexLists - - index management, populated for the query plan
Returns:
NestedIterationNode with lookups attached underneath

createLookupPlan

public static TableLookupPlan createLookupPlan(QueryGraph queryGraph,
                                               int currentLookupStream,
                                               int indexedStream,
                                               QueryPlanIndex indexSpecs,
                                               EventType[] typesPerStream,
                                               TableMetadata indexedStreamTableMeta)
Create the table lookup plan for a from-stream to look up in an indexed stream using the columns supplied in the query graph and looking at the actual indexes available and their index number.

Parameters:
queryGraph - - contains properties joining the 2 streams
currentLookupStream - - stream to use key values from
indexedStream - - stream to look up in
indexSpecs - - index specification defining indexes to be created for stream
typesPerStream - - event types for each stream
Returns:
plan for performing a lookup in a given table using one of the indexes supplied

computeBestPath

protected static NStreamQueryPlanBuilder.BestChainResult computeBestPath(int lookupStream,
                                                                         QueryGraph queryGraph,
                                                                         DependencyGraph dependencyGraph)
Compute a best chain or path for lookups to take for the lookup stream passed in and the query property relationships. The method runs through all possible permutations of lookup path NumberSetPermutationEnumeration until a path is found in which all streams can be accessed via an index. If not such path is found, the method returns the path with the greatest depth, ie. where the first one or more streams are index accesses. If no depth other then zero is found, returns the default nesting order.

Parameters:
lookupStream - - stream to start look up
queryGraph - - navigability between streams
dependencyGraph - - dependencies between historical streams
Returns:
chain and chain depth

isDependencySatisfied

protected static boolean isDependencySatisfied(int lookupStream,
                                               int[] permutation,
                                               DependencyGraph dependencyGraph)
Determine if the proposed permutation of lookups passes dependencies

Parameters:
lookupStream - stream to initiate
permutation - permutation of lookups
dependencyGraph - dependencies
Returns:
pass or fail indication

computeNavigableDepth

protected static int computeNavigableDepth(int lookupStream,
                                           int[] nextStreams,
                                           QueryGraph queryGraph)
Given a chain of streams to look up and indexing information, compute the index within the chain of the first non-index lookup.

Parameters:
lookupStream - - stream to start lookup for
nextStreams - - list of stream numbers next in lookup
queryGraph - - indexing information
Returns:
value between 0 and (nextStreams.lenght - 1)

buildDefaultNestingOrder

protected static int[] buildDefaultNestingOrder(int numStreams,
                                                int forStream)
Returns default nesting order for a given number of streams for a certain stream. Example: numStreams = 5, forStream = 2, result = {0, 1, 3, 4} The resulting array has all streams except the forStream, in ascdending order.

Parameters:
numStreams - - number of streams
forStream - - stream to generate a nesting order for
Returns:
int array with all stream numbers starting at 0 to (numStreams - 1) leaving the forStream out

© 2006-2016 EsperTech Inc.
All rights reserved.
Visit us at espertech.com