use of org.ballerinalang.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.
the class StoreQueryParser method constructStoreQueryRuntime.
private static StoreQueryRuntime constructStoreQueryRuntime(Table table, StoreQuery storeQuery, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String queryName, int metaPosition, Expression onCondition, MetaStreamEvent metaStreamEvent, List<VariableExpressionExecutor> variableExpressionExecutors) {
metaStreamEvent.setEventType(EventType.TABLE);
initMetaStreamEvent(metaStreamEvent, table.getTableDefinition());
MatchingMetaInfoHolder metaStreamInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, table.getTableDefinition());
CompiledCondition compiledCondition = table.compileCondition(onCondition, metaStreamInfoHolder, siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
if (table instanceof QueryableProcessor) {
List<Attribute> expectedOutputAttributes = buildExpectedOutputAttributes(storeQuery, siddhiAppContext, tableMap, queryName, metaPosition, metaStreamInfoHolder);
CompiledSelection compiledSelection = ((QueryableProcessor) table).compileSelection(storeQuery.getSelector(), expectedOutputAttributes, metaStreamInfoHolder, siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
SelectStoreQueryRuntime storeQueryRuntime = new SelectStoreQueryRuntime((QueryableProcessor) table, compiledCondition, compiledSelection, expectedOutputAttributes, queryName);
QueryParserHelper.reduceMetaComplexEvent(metaStreamInfoHolder.getMetaStateEvent());
QueryParserHelper.updateVariablePosition(metaStreamInfoHolder.getMetaStateEvent(), variableExpressionExecutors);
return storeQueryRuntime;
} else {
FindStoreQueryRuntime storeQueryRuntime = new FindStoreQueryRuntime(table, compiledCondition, queryName, metaStreamEvent);
populateFindStoreQueryRuntime(storeQueryRuntime, metaStreamInfoHolder, storeQuery.getSelector(), variableExpressionExecutors, siddhiAppContext, tableMap, queryName, metaPosition);
return storeQueryRuntime;
}
}
use of org.ballerinalang.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.
the class AggregationParser method populateIncomingAggregatorsAndExecutors.
private static void populateIncomingAggregatorsAndExecutors(AggregationDefinition aggregationDefinition, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, List<VariableExpressionExecutor> incomingVariableExpressionExecutors, String aggregatorName, MetaStreamEvent incomingMetaStreamEvent, List<ExpressionExecutor> incomingExpressionExecutors, List<IncrementalAttributeAggregator> incrementalAttributeAggregators, List<Variable> groupByVariableList, List<Expression> outputExpressions) {
ExpressionExecutor[] timeStampTimeZoneExecutors = setTimeStampTimeZoneExecutors(aggregationDefinition, siddhiAppContext, tableMap, incomingVariableExpressionExecutors, aggregatorName, incomingMetaStreamEvent);
ExpressionExecutor timestampExecutor = timeStampTimeZoneExecutors[0];
ExpressionExecutor timeZoneExecutor = timeStampTimeZoneExecutors[1];
Attribute timestampAttribute = new Attribute("AGG_TIMESTAMP", Attribute.Type.LONG);
incomingMetaStreamEvent.addOutputData(timestampAttribute);
incomingExpressionExecutors.add(timestampExecutor);
incomingMetaStreamEvent.addOutputData(new Attribute("AGG_TIMEZONE", Attribute.Type.STRING));
incomingExpressionExecutors.add(timeZoneExecutor);
AbstractDefinition incomingLastInputStreamDefinition = incomingMetaStreamEvent.getLastInputDefinition();
for (Variable groupByVariable : groupByVariableList) {
incomingMetaStreamEvent.addOutputData(incomingLastInputStreamDefinition.getAttributeList().get(incomingLastInputStreamDefinition.getAttributePosition(groupByVariable.getAttributeName())));
incomingExpressionExecutors.add(ExpressionParser.parseExpression(groupByVariable, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, siddhiAppContext, false, 0, aggregatorName));
}
// Add AGG_TIMESTAMP to output as well
outputExpressions.add(Expression.variable("AGG_TIMESTAMP"));
aggregationDefinition.getAttributeList().add(timestampAttribute);
for (OutputAttribute outputAttribute : aggregationDefinition.getSelector().getSelectionList()) {
Expression expression = outputAttribute.getExpression();
if (expression instanceof AttributeFunction) {
IncrementalAttributeAggregator incrementalAggregator = null;
try {
incrementalAggregator = (IncrementalAttributeAggregator) SiddhiClassLoader.loadExtensionImplementation(new AttributeFunction("incrementalAggregator", ((AttributeFunction) expression).getName(), ((AttributeFunction) expression).getParameters()), IncrementalAttributeAggregatorExtensionHolder.getInstance(siddhiAppContext));
} catch (SiddhiAppCreationException ex) {
try {
SiddhiClassLoader.loadExtensionImplementation((AttributeFunction) expression, FunctionExecutorExtensionHolder.getInstance(siddhiAppContext));
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, siddhiAppContext, false, 0, aggregatorName);
incomingExpressionExecutors.add(expressionExecutor);
incomingMetaStreamEvent.addOutputData(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
outputExpressions.add(Expression.variable(outputAttribute.getRename()));
} catch (SiddhiAppCreationException e) {
throw new SiddhiAppCreationException("'" + ((AttributeFunction) expression).getName() + "' is neither a incremental attribute aggregator extension or a function" + " extension", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
}
}
if (incrementalAggregator != null) {
initIncrementalAttributeAggregator(incomingLastInputStreamDefinition, (AttributeFunction) expression, incrementalAggregator);
incrementalAttributeAggregators.add(incrementalAggregator);
aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), incrementalAggregator.getReturnType()));
outputExpressions.add(incrementalAggregator.aggregate());
}
} else {
if (expression instanceof Variable && groupByVariableList.contains(expression)) {
Attribute groupByAttribute = null;
for (Attribute attribute : incomingMetaStreamEvent.getOutputData()) {
if (attribute.getName().equals(((Variable) expression).getAttributeName())) {
groupByAttribute = attribute;
break;
}
}
if (groupByAttribute == null) {
throw new SiddhiAppCreationException("Expected GroupBy attribute '" + ((Variable) expression).getAttributeName() + "' not used in aggregation '" + aggregatorName + "' processing.", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
}
aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), groupByAttribute.getType()));
outputExpressions.add(Expression.variable(groupByAttribute.getName()));
} else {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, siddhiAppContext, false, 0, aggregatorName);
incomingExpressionExecutors.add(expressionExecutor);
incomingMetaStreamEvent.addOutputData(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
outputExpressions.add(Expression.variable(outputAttribute.getRename()));
}
}
}
}
use of org.ballerinalang.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.
the class AggregationParser method constructProcessExpressionExecutors.
private static List<ExpressionExecutor> constructProcessExpressionExecutors(SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String aggregatorName, int baseAggregatorBeginIndex, List<Expression> finalBaseAggregators, StreamDefinition incomingOutputStreamDefinition, MetaStreamEvent processedMetaStreamEvent, List<VariableExpressionExecutor> processVariableExpressionExecutors, boolean groupBy) {
List<ExpressionExecutor> processExpressionExecutors = new ArrayList<>();
List<Attribute> attributeList = incomingOutputStreamDefinition.getAttributeList();
for (int i = 0; i < baseAggregatorBeginIndex; i++) {
Attribute attribute = attributeList.get(i);
VariableExpressionExecutor variableExpressionExecutor = (VariableExpressionExecutor) ExpressionParser.parseExpression(new Variable(attribute.getName()), processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, siddhiAppContext, groupBy, 0, aggregatorName);
processExpressionExecutors.add(variableExpressionExecutor);
}
for (Expression expression : finalBaseAggregators) {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, siddhiAppContext, groupBy, 0, aggregatorName);
processExpressionExecutors.add(expressionExecutor);
}
return processExpressionExecutors;
}
use of org.ballerinalang.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.
the class AggregationParser method getFinalBaseAggregators.
private static List<Expression> getFinalBaseAggregators(SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, List<VariableExpressionExecutor> incomingVariableExpressionExecutors, String aggregatorName, MetaStreamEvent incomingMetaStreamEvent, List<ExpressionExecutor> incomingExpressionExecutors, List<IncrementalAttributeAggregator> incrementalAttributeAggregators) {
List<Attribute> finalBaseAttributes = new ArrayList<>();
List<Expression> finalBaseAggregators = new ArrayList<>();
for (IncrementalAttributeAggregator incrementalAttributeAggregator : incrementalAttributeAggregators) {
Attribute[] baseAttributes = incrementalAttributeAggregator.getBaseAttributes();
Expression[] baseAttributeInitialValues = incrementalAttributeAggregator.getBaseAttributeInitialValues();
Expression[] baseAggregators = incrementalAttributeAggregator.getBaseAggregators();
for (int i = 0; i < baseAttributes.length; i++) {
validateBaseAggregators(incrementalAttributeAggregators, incrementalAttributeAggregator, baseAttributes, baseAttributeInitialValues, baseAggregators, i);
if (!finalBaseAttributes.contains(baseAttributes[i])) {
finalBaseAttributes.add(baseAttributes[i]);
finalBaseAggregators.add(baseAggregators[i]);
incomingMetaStreamEvent.addOutputData(baseAttributes[i]);
incomingExpressionExecutors.add(ExpressionParser.parseExpression(baseAttributeInitialValues[i], incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, siddhiAppContext, false, 0, aggregatorName));
}
}
}
return finalBaseAggregators;
}
use of org.ballerinalang.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.
the class CollectionExpressionParser method buildCollectionExecutor.
public static CollectionExecutor buildCollectionExecutor(CollectionExpression collectionExpression, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiAppContext siddhiAppContext, boolean isFirst, String queryName) {
if (collectionExpression instanceof AttributeCollectionExpression) {
ExpressionExecutor expressionExecutor = null;
if (isFirst) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
}
return new CompareCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex(), ((AttributeCollectionExpression) collectionExpression).getAttribute(), Compare.Operator.EQUAL, new ConstantExpressionExecutor(true, Attribute.Type.BOOL));
} else if (collectionExpression instanceof CompareCollectionExpression) {
ExpressionExecutor valueExpressionExecutor = ExpressionParser.parseExpression(((CompareCollectionExpression) collectionExpression).getValueCollectionExpression().getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
AttributeCollectionExpression attributeCollectionExpression = ((AttributeCollectionExpression) ((CompareCollectionExpression) collectionExpression).getAttributeCollectionExpression());
ExpressionExecutor expressionExecutor = null;
if (isFirst) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
}
return new CompareCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex(), attributeCollectionExpression.getAttribute(), ((CompareCollectionExpression) collectionExpression).getOperator(), valueExpressionExecutor);
} else if (collectionExpression instanceof NullCollectionExpression) {
ExpressionExecutor expressionExecutor = null;
if (isFirst) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
}
return new CompareCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex(), ((NullCollectionExpression) collectionExpression).getAttribute(), Compare.Operator.EQUAL, new ConstantExpressionExecutor(null, Attribute.Type.OBJECT));
} else if (collectionExpression instanceof AndMultiPrimaryKeyCollectionExpression) {
Map<String, ExpressionExecutor> multiPrimaryKeyExpressionExecutors = buildMultiPrimaryKeyExpressionExecutors(collectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, queryName);
List<Attribute> attributes = matchingMetaInfoHolder.getStoreDefinition().getAttributeList();
StringBuilder compositePrimaryKey = new StringBuilder();
List<ExpressionExecutor> sortedExecutors = new ArrayList<ExpressionExecutor>();
for (Attribute attribute : attributes) {
ExpressionExecutor expressionExecutor = multiPrimaryKeyExpressionExecutors.get(attribute.getName());
if (expressionExecutor != null) {
sortedExecutors.add(expressionExecutor);
compositePrimaryKey.append(attribute.getName()).append(SiddhiConstants.KEY_DELIMITER);
}
}
return new AndMultiPrimaryKeyCollectionExecutor(compositePrimaryKey.toString(), sortedExecutors);
} else if (collectionExpression instanceof AndCollectionExpression) {
CollectionExpression leftCollectionExpression = ((AndCollectionExpression) collectionExpression).getLeftCollectionExpression();
CollectionExpression rightCollectionExpression = ((AndCollectionExpression) collectionExpression).getRightCollectionExpression();
ExpressionExecutor expressionExecutor = null;
CollectionExecutor aCollectionExecutor = null;
ExhaustiveCollectionExecutor exhaustiveCollectionExecutor = null;
CollectionExecutor leftCollectionExecutor;
CollectionExecutor rightCollectionExecutor;
switch(leftCollectionExpression.getCollectionScope()) {
case NON:
switch(rightCollectionExpression.getCollectionScope()) {
case NON:
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
return new NonCollectionExecutor(expressionExecutor);
case INDEXED_ATTRIBUTE:
case INDEXED_RESULT_SET:
case PRIMARY_KEY_ATTRIBUTE:
case PRIMARY_KEY_RESULT_SET:
case PARTIAL_PRIMARY_KEY_RESULT_SET:
case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
case EXHAUSTIVE:
expressionExecutor = ExpressionParser.parseExpression(leftCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
aCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
return new NonAndCollectionExecutor(expressionExecutor, aCollectionExecutor, rightCollectionExpression.getCollectionScope());
}
break;
case INDEXED_ATTRIBUTE:
case PRIMARY_KEY_ATTRIBUTE:
switch(rightCollectionExpression.getCollectionScope()) {
case NON:
expressionExecutor = ExpressionParser.parseExpression(rightCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
aCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
return new NonAndCollectionExecutor(expressionExecutor, aCollectionExecutor, rightCollectionExpression.getCollectionScope());
case INDEXED_ATTRIBUTE:
case INDEXED_RESULT_SET:
case PRIMARY_KEY_ATTRIBUTE:
case PRIMARY_KEY_RESULT_SET:
case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
return new AnyAndCollectionExecutor(leftCollectionExecutor, rightCollectionExecutor, exhaustiveCollectionExecutor);
case PARTIAL_PRIMARY_KEY_RESULT_SET:
case EXHAUSTIVE:
leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
if (isFirst || leftCollectionExecutor.getDefaultCost() == CollectionExecutor.Cost.SINGLE_RETURN_INDEX_MATCHING) {
exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
}
return new CompareExhaustiveAndCollectionExecutor(leftCollectionExecutor, exhaustiveCollectionExecutor);
}
break;
case INDEXED_RESULT_SET:
case PRIMARY_KEY_RESULT_SET:
case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
switch(rightCollectionExpression.getCollectionScope()) {
case NON:
expressionExecutor = ExpressionParser.parseExpression(rightCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
aCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
return new NonAndCollectionExecutor(expressionExecutor, aCollectionExecutor, rightCollectionExpression.getCollectionScope());
case INDEXED_ATTRIBUTE:
case PRIMARY_KEY_ATTRIBUTE:
exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
return new AnyAndCollectionExecutor(rightCollectionExecutor, leftCollectionExecutor, exhaustiveCollectionExecutor);
case INDEXED_RESULT_SET:
case PRIMARY_KEY_RESULT_SET:
case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
return new AnyAndCollectionExecutor(leftCollectionExecutor, rightCollectionExecutor, exhaustiveCollectionExecutor);
case PARTIAL_PRIMARY_KEY_RESULT_SET:
case EXHAUSTIVE:
leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
if (isFirst || leftCollectionExecutor.getDefaultCost() == CollectionExecutor.Cost.SINGLE_RETURN_INDEX_MATCHING) {
exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
}
return new CompareExhaustiveAndCollectionExecutor(leftCollectionExecutor, exhaustiveCollectionExecutor);
}
break;
case PARTIAL_PRIMARY_KEY_RESULT_SET:
case EXHAUSTIVE:
switch(rightCollectionExpression.getCollectionScope()) {
case NON:
expressionExecutor = ExpressionParser.parseExpression(rightCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
aCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
return new NonAndCollectionExecutor(expressionExecutor, aCollectionExecutor, rightCollectionExpression.getCollectionScope());
case INDEXED_ATTRIBUTE:
case INDEXED_RESULT_SET:
case PRIMARY_KEY_ATTRIBUTE:
case PRIMARY_KEY_RESULT_SET:
case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
if (isFirst || rightCollectionExecutor.getDefaultCost() == CollectionExecutor.Cost.SINGLE_RETURN_INDEX_MATCHING) {
exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
}
return new CompareExhaustiveAndCollectionExecutor(rightCollectionExecutor, exhaustiveCollectionExecutor);
case PARTIAL_PRIMARY_KEY_RESULT_SET:
case EXHAUSTIVE:
if (isFirst) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
}
return new ExhaustiveCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
}
break;
}
} else if (collectionExpression instanceof OrCollectionExpression) {
CollectionExpression leftCollectionExpression = ((OrCollectionExpression) collectionExpression).getLeftCollectionExpression();
CollectionExpression rightCollectionExpression = ((OrCollectionExpression) collectionExpression).getRightCollectionExpression();
ExpressionExecutor expressionExecutor = null;
CollectionExecutor aCollectionExecutor = null;
CollectionExecutor leftCollectionExecutor;
CollectionExecutor rightCollectionExecutor;
if (leftCollectionExpression.getCollectionScope() == NON && rightCollectionExpression.getCollectionScope() == NON) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
return new NonCollectionExecutor(expressionExecutor);
} else if ((leftCollectionExpression.getCollectionScope() == EXHAUSTIVE && leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET) || (rightCollectionExpression.getCollectionScope() == EXHAUSTIVE && rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET)) {
if (isFirst) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
}
return new ExhaustiveCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
} else {
if (isFirst) {
aCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
}
leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
return new OrCollectionExecutor(leftCollectionExecutor, rightCollectionExecutor, aCollectionExecutor);
}
} else if (collectionExpression instanceof NotCollectionExpression) {
ExpressionExecutor expressionExecutor = null;
switch(collectionExpression.getCollectionScope()) {
case NON:
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
return new NonCollectionExecutor(expressionExecutor);
case INDEXED_ATTRIBUTE:
case INDEXED_RESULT_SET:
case PRIMARY_KEY_ATTRIBUTE:
case PRIMARY_KEY_RESULT_SET:
case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
ExhaustiveCollectionExecutor exhaustiveCollectionExecutor = null;
if (isFirst) {
exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
}
CollectionExecutor notCollectionExecutor = buildCollectionExecutor(((NotCollectionExpression) collectionExpression).getCollectionExpression(), matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
return new NotCollectionExecutor(notCollectionExecutor, exhaustiveCollectionExecutor);
case PARTIAL_PRIMARY_KEY_RESULT_SET:
case EXHAUSTIVE:
if (isFirst) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
}
return new ExhaustiveCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
}
} else {
// Basic
ExpressionExecutor expressionExecutor = null;
if (collectionExpression.getCollectionScope() == NON) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
return new NonCollectionExecutor(expressionExecutor);
} else {
// EXHAUSTIVE
if (isFirst) {
expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
}
return new ExhaustiveCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
}
}
throw new UnsupportedOperationException(collectionExpression.getClass().getName() + " not supported!");
}
Aggregations