Search in sources :

Example 1 with OnDemandQuery

use of io.siddhi.query.api.execution.query.OnDemandQuery in project siddhi by wso2.

the class IncrementalExecutorsInitialiser method recreateState.

private void recreateState(Long lastData, TimePeriod.Duration recreateForDuration, Table recreateFromTable, boolean isBeforeRoot) {
    Executor incrementalExecutor = incrementalExecutorMap.get(recreateForDuration);
    if (lastData != null) {
        endOFLatestEventTimestamp = IncrementalTimeConverterUtil.getNextEmitTime(lastData, recreateForDuration, timeZone);
    }
    OnDemandQuery onDemandQuery = getOnDemandQuery(recreateFromTable, false, endOFLatestEventTimestamp);
    onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.FIND);
    OnDemandQueryRuntime onDemandQueryRuntime = OnDemandQueryParser.parse(onDemandQuery, null, siddhiAppContext, tableMap, windowMap, aggregationMap);
    Event[] events = onDemandQueryRuntime.execute();
    if (events != null) {
        long referenceToNextLatestEvent = (Long) events[events.length - 1].getData(0);
        ComplexEventChunk<StreamEvent> complexEventChunk = new ComplexEventChunk<>();
        for (Event event : events) {
            StreamEvent streamEvent = streamEventFactory.newInstance();
            streamEvent.setOutputData(event.getData());
            complexEventChunk.add(streamEvent);
        }
        incrementalExecutor.execute(complexEventChunk);
        if (isBeforeRoot) {
            TimePeriod.Duration rootDuration = incrementalDurations.get(0);
            Executor rootIncrementalExecutor = incrementalExecutorMap.get(rootDuration);
            long emitTimeOfLatestEventInTable = IncrementalTimeConverterUtil.getNextEmitTime(referenceToNextLatestEvent, rootDuration, timeZone);
            rootIncrementalExecutor.setEmitTime(emitTimeOfLatestEventInTable);
        }
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) OnDemandQueryRuntime(io.siddhi.core.query.OnDemandQueryRuntime) TimePeriod(io.siddhi.query.api.aggregation.TimePeriod) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) OnDemandQuery(io.siddhi.query.api.execution.query.OnDemandQuery)

Example 2 with OnDemandQuery

use of io.siddhi.query.api.execution.query.OnDemandQuery in project siddhi by wso2.

the class IncrementalDataPurger method isSafeToPurgeTheDuration.

private Map<String, Boolean> isSafeToPurgeTheDuration(long purgeTime, Table parentTable, Table currentTable, TimePeriod.Duration duration, String timeZone) {
    Event[] dataToDelete;
    Event[] dataInParentTable = null;
    Map<String, Boolean> purgingCheckState = new HashMap<>();
    try {
        dataToDelete = dataToDelete(purgeTime, currentTable);
        if (dataToDelete != null && dataToDelete.length != 0) {
            Map<String, Long> purgingValidationTimeDurations = getPurgingValidationTimeDurations(duration, (Long) dataToDelete[0].getData()[0], timeZone);
            OnDemandQuery onDemandQuery = getOnDemandQuery(parentTable, purgingValidationTimeDurations.get(AGGREGATION_START_TIME), purgingValidationTimeDurations.get(AGGREGATION_NEXT_EMIT_TIME));
            onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.FIND);
            OnDemandQueryRuntime onDemandQueryRuntime = OnDemandQueryParser.parse(onDemandQuery, null, siddhiQueryContext.getSiddhiAppContext(), tableMap, windowMap, aggregationMap);
            dataInParentTable = onDemandQueryRuntime.execute();
        }
        purgingCheckState.put(IS_DATA_AVAILABLE_TO_PURGE, dataToDelete != null && dataToDelete.length > 0);
        purgingCheckState.put(IS_PARENT_TABLE_HAS_AGGREGATED_DATA, dataInParentTable != null && dataInParentTable.length > 0);
    } catch (Exception e) {
        if (e.getMessage().contains("deadlocked")) {
            errorMessage = "Deadlock observed while checking whether the data is safe to purge from aggregation " + "tables for the aggregation " + aggregationDefinition.getId() + ". If this occurred in an Active Active deployment, this error can be ignored if other node " + "doesn't have this error";
        } else {
            errorMessage = "Error occurred while checking whether the data is safe to purge from aggregation " + "tables for the aggregation " + aggregationDefinition.getId();
        }
        LOG.error(errorMessage, e);
        purgingCheckState.put(IS_DATA_AVAILABLE_TO_PURGE, false);
        purgingCheckState.put(IS_PARENT_TABLE_HAS_AGGREGATED_DATA, false);
        errorMessage = "Error occurred while checking whether the data is safe to purge from aggregation tables" + " for the aggregation " + aggregationDefinition.getId();
        purgingHalted = true;
    }
    return purgingCheckState;
}
Also used : HashMap(java.util.HashMap) OnDemandQueryRuntime(io.siddhi.core.query.OnDemandQueryRuntime) Time.timeToLong(io.siddhi.query.api.expression.Expression.Time.timeToLong) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) StateEvent(io.siddhi.core.event.state.StateEvent) OnDemandQuery(io.siddhi.query.api.execution.query.OnDemandQuery) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) DataPurgingException(io.siddhi.core.exception.DataPurgingException)

Example 3 with OnDemandQuery

use of io.siddhi.query.api.execution.query.OnDemandQuery in project siddhi by wso2.

the class QueryStoreTestCase method test3.

@Test
public void test3() {
    OnDemandQuery query = SiddhiCompiler.parseOnDemandQuery("" + "from StockTable " + "on price > 40 " + "select symbol, price " + "group by symbol " + "having (7 > price) ;");
    AssertJUnit.assertNotNull(query);
    OnDemandQuery api = OnDemandQuery.query().from(InputStore.store("StockTable").on(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(40)))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select(Expression.variable("price")).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.value(7), Compare.Operator.GREATER_THAN, Expression.variable("price"))));
    AssertJUnit.assertEquals(api, query);
}
Also used : OnDemandQuery(io.siddhi.query.api.execution.query.OnDemandQuery) Test(org.testng.annotations.Test)

Example 4 with OnDemandQuery

use of io.siddhi.query.api.execution.query.OnDemandQuery in project siddhi by wso2.

the class QueryStoreTestCase method test4.

@Test
public void test4() {
    StoreQuery query = SiddhiCompiler.parseStoreQuery("" + "from StockTable " + "on price > 40 " + "within '2017/01/*' " + "per 'day' " + "select symbol, price " + "group by symbol " + "having (7 > price) ;");
    AssertJUnit.assertNotNull(query);
    OnDemandQuery api = OnDemandQuery.query().from(InputStore.store("StockTable").on(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(40)), Within.within(Expression.value("2017/01/*")), Expression.value("day"))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select(Expression.variable("price")).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.value(7), Compare.Operator.GREATER_THAN, Expression.variable("price"))));
    AssertJUnit.assertEquals(api, query);
}
Also used : StoreQuery(io.siddhi.query.api.execution.query.StoreQuery) OnDemandQuery(io.siddhi.query.api.execution.query.OnDemandQuery) Test(org.testng.annotations.Test)

Example 5 with OnDemandQuery

use of io.siddhi.query.api.execution.query.OnDemandQuery in project siddhi by wso2.

the class OnDemandQueryTestCase method test7.

@Test
public void test7() {
    OnDemandQuery storeQuery = OnDemandQuery.query();
    storeQuery.from(InputStore.store("StockTable")).select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price"))).updateOrInsertBy("StockTable", UpdateStream.updateSet().set(Expression.variable("symbol").ofStream("StockStream"), Expression.variable("symbol")).set(Expression.variable("pricd").ofStream("StockStream"), Expression.variable("price")), Expression.compare(Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.variable("symbol")));
}
Also used : OnDemandQuery(io.siddhi.query.api.execution.query.OnDemandQuery) Test(org.testng.annotations.Test)

Aggregations

OnDemandQuery (io.siddhi.query.api.execution.query.OnDemandQuery)11 OnDemandQueryRuntime (io.siddhi.core.query.OnDemandQueryRuntime)4 Test (org.testng.annotations.Test)4 Event (io.siddhi.core.event.Event)3 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)3 StreamEvent (io.siddhi.core.event.stream.StreamEvent)3 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)2 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)2 TimePeriod (io.siddhi.query.api.aggregation.TimePeriod)2 StoreQuery (io.siddhi.query.api.execution.query.StoreQuery)2 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)1 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)1 MetaStateEventAttribute (io.siddhi.core.event.state.MetaStateEventAttribute)1 StateEvent (io.siddhi.core.event.state.StateEvent)1 DataPurgingException (io.siddhi.core.exception.DataPurgingException)1 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)1 CacheTable (io.siddhi.core.table.CacheTable)1 CacheTableFIFO (io.siddhi.core.table.CacheTableFIFO)1 CacheTableLFU (io.siddhi.core.table.CacheTableLFU)1 CacheTableLRU (io.siddhi.core.table.CacheTableLRU)1