use of org.wso2.siddhi.core.query.selector.OrderByEventComparator in project siddhi by wso2.
the class QuerySelector method clone.
public QuerySelector clone(String key) {
QuerySelector clonedQuerySelector = new QuerySelector(id + key, selector, currentOn, expiredOn, siddhiAppContext);
List<AttributeProcessor> clonedAttributeProcessorList = new ArrayList<AttributeProcessor>();
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
clonedAttributeProcessorList.add(attributeProcessor.cloneProcessor(key));
}
clonedQuerySelector.attributeProcessorList = clonedAttributeProcessorList;
clonedQuerySelector.isGroupBy = isGroupBy;
clonedQuerySelector.containsAggregator = containsAggregator;
clonedQuerySelector.groupByKeyGenerator = groupByKeyGenerator;
clonedQuerySelector.havingConditionExecutor = havingConditionExecutor;
clonedQuerySelector.eventPopulator = eventPopulator;
clonedQuerySelector.batchingEnabled = batchingEnabled;
clonedQuerySelector.isOrderBy = isOrderBy;
clonedQuerySelector.orderByEventComparator = orderByEventComparator;
clonedQuerySelector.limit = limit;
return clonedQuerySelector;
}
use of org.wso2.siddhi.core.query.selector.OrderByEventComparator in project siddhi by wso2.
the class SelectorParser method parse.
/**
* Parse Selector portion of a query and return corresponding QuerySelector.
*
* @param selector selector to be parsed
* @param outputStream output stream
* @param siddhiAppContext query to be parsed
* @param metaComplexEvent Meta event used to collect execution info of stream associated with query
* @param tableMap Table Map
* @param variableExpressionExecutors variable expression executors
* @param queryName query name of selector belongs to.
* @param metaPosition helps to identify the meta position of aggregates
* @return QuerySelector
*/
public static QuerySelector parse(Selector selector, OutputStream outputStream, SiddhiAppContext siddhiAppContext, MetaComplexEvent metaComplexEvent, Map<String, Table> tableMap, List<VariableExpressionExecutor> variableExpressionExecutors, String queryName, int metaPosition) {
boolean currentOn = false;
boolean expiredOn = false;
String id = null;
if (outputStream.getOutputEventType() == OutputStream.OutputEventType.CURRENT_EVENTS || outputStream.getOutputEventType() == OutputStream.OutputEventType.ALL_EVENTS) {
currentOn = true;
}
if (outputStream.getOutputEventType() == OutputStream.OutputEventType.EXPIRED_EVENTS || outputStream.getOutputEventType() == OutputStream.OutputEventType.ALL_EVENTS) {
expiredOn = true;
}
id = outputStream.getId();
containsAggregatorThreadLocal.remove();
QuerySelector querySelector = new QuerySelector(id, selector, currentOn, expiredOn, siddhiAppContext);
List<AttributeProcessor> attributeProcessors = getAttributeProcessors(selector, id, siddhiAppContext, metaComplexEvent, tableMap, variableExpressionExecutors, outputStream, queryName, metaPosition);
querySelector.setAttributeProcessorList(attributeProcessors, "true".equals(containsAggregatorThreadLocal.get()));
containsAggregatorThreadLocal.remove();
ConditionExpressionExecutor havingCondition = generateHavingExecutor(selector.getHavingExpression(), metaComplexEvent, siddhiAppContext, tableMap, variableExpressionExecutors, queryName);
querySelector.setHavingConditionExecutor(havingCondition, "true".equals(containsAggregatorThreadLocal.get()));
containsAggregatorThreadLocal.remove();
if (!selector.getGroupByList().isEmpty()) {
querySelector.setGroupByKeyGenerator(new GroupByKeyGenerator(selector.getGroupByList(), metaComplexEvent, SiddhiConstants.UNKNOWN_STATE, null, variableExpressionExecutors, siddhiAppContext, queryName));
}
if (!selector.getOrderByList().isEmpty()) {
querySelector.setOrderByEventComparator(new OrderByEventComparator(selector.getOrderByList(), metaComplexEvent, SiddhiConstants.HAVING_STATE, null, variableExpressionExecutors, siddhiAppContext, queryName));
}
if (selector.getLimit() != null) {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression((Expression) selector.getLimit(), metaComplexEvent, SiddhiConstants.HAVING_STATE, tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
containsAggregatorThreadLocal.remove();
querySelector.setLimit(((Number) (((ConstantExpressionExecutor) expressionExecutor).getValue())).longValue());
}
return querySelector;
}
use of org.wso2.siddhi.core.query.selector.OrderByEventComparator in project siddhi by wso2.
the class QuerySelector method orderEventChunk.
private void orderEventChunk(ComplexEventChunk complexEventChunk) {
ComplexEventChunk orderingComplexEventChunk = new ComplexEventChunk(complexEventChunk.isBatch());
List<ComplexEvent> eventList = new ArrayList<>();
ComplexEvent.Type currentEventType = null;
complexEventChunk.reset();
if (complexEventChunk.getFirst() != null) {
currentEventType = complexEventChunk.getFirst().getType();
while (complexEventChunk.hasNext()) {
ComplexEvent event = complexEventChunk.next();
complexEventChunk.remove();
if (currentEventType == event.getType()) {
eventList.add(event);
} else {
currentEventType = event.getType();
eventList.sort(orderByEventComparator);
for (ComplexEvent complexEvent : eventList) {
orderingComplexEventChunk.add(complexEvent);
}
eventList.clear();
eventList.add(event);
}
}
eventList.sort(orderByEventComparator);
for (ComplexEvent complexEvent : eventList) {
orderingComplexEventChunk.add(complexEvent);
}
complexEventChunk.clear();
complexEventChunk.add(orderingComplexEventChunk.getFirst());
}
}
Aggregations