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);
}
}
}
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;
}
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);
}
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);
}
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")));
}
Aggregations