/* Enter a unique ExecutionPlan */
@Plan:name('APIMAnalytics-APIRequestPatternChangeAnalysisMatrixBuilder')


@Plan:trace('false')


@Import('org.wso2.analytics.apim.stateStream:1.0.0')
define stream stateStream (context string, method string, resourceTemplate string, tenantDomain string, state string, userId string, requestTimestamp string, consumerKey string, applicationName string, applicationOwner string);

@from(eventtable = 'analytics.table' , table.name = 'org_wso2_analytics_apim_MARKOVMODELTABLE',  primary.keys = 'consumerKey,startState,endState', indices = 'startState,endState, count, probability, consumerKey', merge.schema='false', wait.for.indexing = 'false')
define table MarkovModelTable (consumerKey string, startState string, endState string, probability double);

@info(name = 'query1')
from stateStream#amAnalytics:buildMarkovMatrix(consumerKey, userId, state,  1 min)
select appConsumerKey as consumerKey, startState, endState, probability
insert into MarkovModelTable;