use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class CollectionExpressionParser method parseInternalCollectionExpression.
/**
* Parse the given expression and create the appropriate Executor by recursively traversing the expression.
*
* @param expression Expression to be parsed
* @param matchingMetaInfoHolder matchingMetaInfoHolder
* @param indexedEventHolder indexed event holder
* @return ExpressionExecutor
*/
private static CollectionExpression parseInternalCollectionExpression(Expression expression, MatchingMetaInfoHolder matchingMetaInfoHolder, IndexedEventHolder indexedEventHolder) {
if (expression instanceof And) {
CollectionExpression leftCollectionExpression = parseInternalCollectionExpression(((And) expression).getLeftExpression(), matchingMetaInfoHolder, indexedEventHolder);
CollectionExpression rightCollectionExpression = parseInternalCollectionExpression(((And) expression).getRightExpression(), matchingMetaInfoHolder, indexedEventHolder);
if (leftCollectionExpression.getCollectionScope() == NON && rightCollectionExpression.getCollectionScope() == NON) {
return new BasicCollectionExpression(expression, NON);
} else if ((leftCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET) && (rightCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET)) {
Set<String> primaryKeys = new HashSet<>();
primaryKeys.addAll(leftCollectionExpression.getMultiPrimaryKeys());
primaryKeys.addAll(rightCollectionExpression.getMultiPrimaryKeys());
if (indexedEventHolder.getPrimaryKeyReferenceHolders() != null && primaryKeys.size() == indexedEventHolder.getPrimaryKeyReferenceHolders().length) {
return new AndMultiPrimaryKeyCollectionExpression(expression, PRIMARY_KEY_RESULT_SET, leftCollectionExpression, rightCollectionExpression);
} else {
return new AndCollectionExpression(expression, PARTIAL_PRIMARY_KEY_RESULT_SET, leftCollectionExpression, rightCollectionExpression);
}
// TODO support query rewriting to group all PARTIAL_PRIMARY_KEY_RESULT_SETs together such that it can
// build AndMultiPrimaryKeyCollectionExpression.
} else if ((leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET || leftCollectionExpression.getCollectionScope() == NON || leftCollectionExpression.getCollectionScope() == EXHAUSTIVE) && (rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET || rightCollectionExpression.getCollectionScope() == NON || rightCollectionExpression.getCollectionScope() == EXHAUSTIVE)) {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
} else {
return new AndCollectionExpression(expression, OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET, leftCollectionExpression, rightCollectionExpression);
}
} else if (expression instanceof Or) {
CollectionExpression leftCollectionExpression = parseInternalCollectionExpression(((Or) expression).getLeftExpression(), matchingMetaInfoHolder, indexedEventHolder);
CollectionExpression rightCollectionExpression = parseInternalCollectionExpression(((Or) expression).getRightExpression(), matchingMetaInfoHolder, indexedEventHolder);
if (leftCollectionExpression.getCollectionScope() == NON && rightCollectionExpression.getCollectionScope() == NON) {
return new BasicCollectionExpression(expression, NON);
} else if (leftCollectionExpression.getCollectionScope() == EXHAUSTIVE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET || rightCollectionExpression.getCollectionScope() == EXHAUSTIVE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET) {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
} else {
return new OrCollectionExpression(expression, OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET, leftCollectionExpression, rightCollectionExpression);
}
} else if (expression instanceof Not) {
CollectionExpression notCollectionExpression = parseInternalCollectionExpression(((Not) expression).getExpression(), matchingMetaInfoHolder, indexedEventHolder);
switch(notCollectionExpression.getCollectionScope()) {
case NON:
return new BasicCollectionExpression(expression, NON);
case PRIMARY_KEY_ATTRIBUTE:
return new NotCollectionExpression(expression, PRIMARY_KEY_RESULT_SET, notCollectionExpression);
case INDEXED_ATTRIBUTE:
return new NotCollectionExpression(expression, INDEXED_RESULT_SET, notCollectionExpression);
case PRIMARY_KEY_RESULT_SET:
case INDEXED_RESULT_SET:
case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
return new NotCollectionExpression(expression, OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET, notCollectionExpression);
case PARTIAL_PRIMARY_KEY_ATTRIBUTE:
case PARTIAL_PRIMARY_KEY_RESULT_SET:
case EXHAUSTIVE:
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
} else if (expression instanceof Compare) {
CollectionExpression leftCollectionExpression = parseInternalCollectionExpression(((Compare) expression).getLeftExpression(), matchingMetaInfoHolder, indexedEventHolder);
CollectionExpression rightCollectionExpression = parseInternalCollectionExpression(((Compare) expression).getRightExpression(), matchingMetaInfoHolder, indexedEventHolder);
if (leftCollectionExpression.getCollectionScope() == NON && rightCollectionExpression.getCollectionScope() == NON) {
// comparing two stream attributes with O(1) time complexity
return new BasicCollectionExpression(expression, NON);
} else if ((leftCollectionExpression.getCollectionScope() == INDEXED_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE) && rightCollectionExpression.getCollectionScope() == NON) {
switch(leftCollectionExpression.getCollectionScope()) {
case INDEXED_ATTRIBUTE:
return new CompareCollectionExpression((Compare) expression, INDEXED_RESULT_SET, leftCollectionExpression, ((Compare) expression).getOperator(), rightCollectionExpression);
case PRIMARY_KEY_ATTRIBUTE:
return new CompareCollectionExpression((Compare) expression, PRIMARY_KEY_RESULT_SET, leftCollectionExpression, ((Compare) expression).getOperator(), rightCollectionExpression);
case PARTIAL_PRIMARY_KEY_ATTRIBUTE:
return new CompareCollectionExpression((Compare) expression, PARTIAL_PRIMARY_KEY_RESULT_SET, leftCollectionExpression, ((Compare) expression).getOperator(), rightCollectionExpression);
}
} else if (leftCollectionExpression.getCollectionScope() == NON && (rightCollectionExpression.getCollectionScope() == INDEXED_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE)) {
Compare.Operator operator = ((Compare) expression).getOperator();
// moving let to right
switch(operator) {
case LESS_THAN:
operator = Compare.Operator.GREATER_THAN;
break;
case GREATER_THAN:
operator = Compare.Operator.LESS_THAN;
break;
case LESS_THAN_EQUAL:
operator = Compare.Operator.GREATER_THAN_EQUAL;
break;
case GREATER_THAN_EQUAL:
operator = Compare.Operator.LESS_THAN_EQUAL;
break;
case EQUAL:
break;
case NOT_EQUAL:
break;
}
switch(rightCollectionExpression.getCollectionScope()) {
case INDEXED_ATTRIBUTE:
return new CompareCollectionExpression((Compare) expression, INDEXED_RESULT_SET, rightCollectionExpression, operator, leftCollectionExpression);
case PRIMARY_KEY_ATTRIBUTE:
return new CompareCollectionExpression((Compare) expression, PRIMARY_KEY_RESULT_SET, rightCollectionExpression, operator, leftCollectionExpression);
case PARTIAL_PRIMARY_KEY_ATTRIBUTE:
return new CompareCollectionExpression((Compare) expression, PARTIAL_PRIMARY_KEY_RESULT_SET, rightCollectionExpression, operator, leftCollectionExpression);
}
} else {
// comparing non indexed table with stream attributes or another table attribute
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
} else if (expression instanceof Constant) {
return new BasicCollectionExpression(expression, NON);
} else if (expression instanceof Variable) {
if (isCollectionVariable(matchingMetaInfoHolder, (Variable) expression)) {
if (indexedEventHolder.isAttributeIndexed(((Variable) expression).getAttributeName())) {
return new AttributeCollectionExpression(expression, ((Variable) expression).getAttributeName(), INDEXED_ATTRIBUTE);
} else if (indexedEventHolder.isMultiPrimaryKeyAttribute(((Variable) expression).getAttributeName())) {
if (indexedEventHolder.getPrimaryKeyReferenceHolders() != null && indexedEventHolder.getPrimaryKeyReferenceHolders().length == 1) {
return new AttributeCollectionExpression(expression, ((Variable) expression).getAttributeName(), PRIMARY_KEY_ATTRIBUTE);
} else {
return new AttributeCollectionExpression(expression, ((Variable) expression).getAttributeName(), PARTIAL_PRIMARY_KEY_ATTRIBUTE);
}
} else {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
} else {
return new BasicCollectionExpression(expression, NON);
}
} else if (expression instanceof Multiply) {
CollectionExpression left = parseInternalCollectionExpression(((Multiply) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
CollectionExpression right = parseInternalCollectionExpression(((Multiply) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
return new BasicCollectionExpression(expression, NON);
} else {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
} else if (expression instanceof Add) {
CollectionExpression left = parseInternalCollectionExpression(((Add) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
CollectionExpression right = parseInternalCollectionExpression(((Add) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
return new BasicCollectionExpression(expression, NON);
} else {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
} else if (expression instanceof Subtract) {
CollectionExpression left = parseInternalCollectionExpression(((Subtract) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
CollectionExpression right = parseInternalCollectionExpression(((Subtract) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
return new BasicCollectionExpression(expression, NON);
} else {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
} else if (expression instanceof Mod) {
CollectionExpression left = parseInternalCollectionExpression(((Mod) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
CollectionExpression right = parseInternalCollectionExpression(((Mod) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
return new BasicCollectionExpression(expression, NON);
} else {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
} else if (expression instanceof Divide) {
CollectionExpression left = parseInternalCollectionExpression(((Divide) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
CollectionExpression right = parseInternalCollectionExpression(((Divide) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
return new BasicCollectionExpression(expression, NON);
} else {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
} else if (expression instanceof AttributeFunction) {
Expression[] innerExpressions = ((AttributeFunction) expression).getParameters();
for (Expression aExpression : innerExpressions) {
CollectionExpression aCollectionExpression = parseInternalCollectionExpression(aExpression, matchingMetaInfoHolder, indexedEventHolder);
if (aCollectionExpression.getCollectionScope() != NON) {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
}
return new BasicCollectionExpression(expression, NON);
} else if (expression instanceof In) {
CollectionExpression inCollectionExpression = parseInternalCollectionExpression(((In) expression).getExpression(), matchingMetaInfoHolder, indexedEventHolder);
if (inCollectionExpression.getCollectionScope() != NON) {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
return new BasicCollectionExpression(expression, NON);
} else if (expression instanceof IsNull) {
CollectionExpression nullCollectionExpression = parseInternalCollectionExpression(((IsNull) expression).getExpression(), matchingMetaInfoHolder, indexedEventHolder);
if (nullCollectionExpression.getCollectionScope() == NON) {
return new BasicCollectionExpression(expression, NON);
} else if (nullCollectionExpression.getCollectionScope() == INDEXED_ATTRIBUTE) {
return new NullCollectionExpression(expression, INDEXED_RESULT_SET, ((AttributeCollectionExpression) nullCollectionExpression).getAttribute());
} else if (nullCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE) {
return new NullCollectionExpression(expression, PRIMARY_KEY_RESULT_SET, ((AttributeCollectionExpression) nullCollectionExpression).getAttribute());
} else {
return new BasicCollectionExpression(expression, EXHAUSTIVE);
}
}
throw new UnsupportedOperationException(expression.toString() + " not supported!");
}
use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class EventHolderPasser method parse.
public static EventHolder parse(AbstractDefinition tableDefinition, StreamEventPool tableStreamEventPool, SiddhiAppContext siddhiAppContext) {
ZeroStreamEventConverter eventConverter = new ZeroStreamEventConverter();
PrimaryKeyReferenceHolder[] primaryKeyReferenceHolders = null;
Map<String, Integer> indexMetaData = new HashMap<String, Integer>();
// primaryKey.
Annotation primaryKeyAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_PRIMARY_KEY, tableDefinition.getAnnotations());
if (primaryKeyAnnotation != null) {
if (primaryKeyAnnotation.getElements().size() == 0) {
throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_PRIMARY_KEY + " annotation " + "contains " + primaryKeyAnnotation.getElements().size() + " element, at '" + tableDefinition.getId() + "'");
}
primaryKeyReferenceHolders = primaryKeyAnnotation.getElements().stream().map(element -> element.getValue().trim()).map(key -> new PrimaryKeyReferenceHolder(key, tableDefinition.getAttributePosition(key))).toArray(PrimaryKeyReferenceHolder[]::new);
}
// indexes.
Annotation indexAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_INDEX, tableDefinition.getAnnotations());
if (indexAnnotation != null) {
if (indexAnnotation.getElements().size() == 0) {
throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_INDEX + " annotation contains " + indexAnnotation.getElements().size() + " element");
}
for (Element element : indexAnnotation.getElements()) {
Integer previousValue = indexMetaData.put(element.getValue().trim(), tableDefinition.getAttributePosition(element.getValue().trim()));
if (previousValue != null) {
throw new SiddhiAppCreationException("Multiple " + SiddhiConstants.ANNOTATION_INDEX + " " + "annotations defined with same attribute '" + element.getValue().trim() + "', at '" + tableDefinition.getId() + "'", indexAnnotation.getQueryContextStartIndex(), indexAnnotation.getQueryContextEndIndex());
}
}
}
// not support indexBy.
Annotation indexByAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_INDEX_BY, tableDefinition.getAnnotations());
if (indexByAnnotation != null) {
throw new OperationNotSupportedException(SiddhiConstants.ANNOTATION_INDEX_BY + " annotation is not " + "supported anymore, please use @PrimaryKey or @Index annotations instead," + " at '" + tableDefinition.getId() + "'");
}
if (primaryKeyReferenceHolders != null || indexMetaData.size() > 0) {
boolean isNumeric = false;
if (primaryKeyReferenceHolders != null) {
if (primaryKeyReferenceHolders.length == 1) {
Attribute.Type type = tableDefinition.getAttributeType(primaryKeyReferenceHolders[0].getPrimaryKeyAttribute());
if (type == Attribute.Type.DOUBLE || type == Attribute.Type.FLOAT || type == Attribute.Type.INT || type == Attribute.Type.LONG) {
isNumeric = true;
}
}
}
return new IndexEventHolder(tableStreamEventPool, eventConverter, primaryKeyReferenceHolders, isNumeric, indexMetaData, tableDefinition, siddhiAppContext);
} else {
return new ListEventHolder(tableStreamEventPool, eventConverter);
}
}
use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class ExpressionParser method parseInnerExpression.
/**
* Parse the set of inner expression of AttributeFunctionExtensions and handling all (*) cases
*
* @param innerExpressions InnerExpressions to be parsed
* @param metaEvent Meta Event
* @param currentState Current state number
* @param tableMap Event Table Map
* @param executorList List to hold VariableExpressionExecutors to update after query parsing @return
* @param siddhiAppContext SiddhiAppContext
* @param groupBy is for groupBy expression
* @param defaultStreamEventIndex Default StreamEvent Index
* @return List of expressionExecutors
*/
private static ExpressionExecutor[] parseInnerExpression(Expression[] innerExpressions, MetaComplexEvent metaEvent, int currentState, Map<String, Table> tableMap, List<VariableExpressionExecutor> executorList, SiddhiAppContext siddhiAppContext, boolean groupBy, int defaultStreamEventIndex, String queryName) {
ExpressionExecutor[] innerExpressionExecutors;
if (innerExpressions != null) {
if (innerExpressions.length > 0) {
innerExpressionExecutors = new ExpressionExecutor[innerExpressions.length];
for (int i = 0, innerExpressionsLength = innerExpressions.length; i < innerExpressionsLength; i++) {
innerExpressionExecutors[i] = parseExpression(innerExpressions[i], metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
}
} else {
List<Expression> outputAttributes = new ArrayList<Expression>();
if (metaEvent instanceof MetaStreamEvent) {
List<Attribute> attributeList = ((MetaStreamEvent) metaEvent).getLastInputDefinition().getAttributeList();
for (Attribute attribute : attributeList) {
outputAttributes.add(new Variable(attribute.getName()));
}
} else {
for (MetaStreamEvent metaStreamEvent : ((MetaStateEvent) metaEvent).getMetaStreamEvents()) {
List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList();
for (Attribute attribute : attributeList) {
Expression outputAttribute = new Variable(attribute.getName());
if (!outputAttributes.contains(outputAttribute)) {
outputAttributes.add(outputAttribute);
} else {
List<AbstractDefinition> definitions = new ArrayList<AbstractDefinition>();
for (MetaStreamEvent aMetaStreamEvent : ((MetaStateEvent) metaEvent).getMetaStreamEvents()) {
definitions.add(aMetaStreamEvent.getLastInputDefinition());
}
throw new DuplicateAttributeException("Duplicate attribute exist in streams " + definitions, attribute.getQueryContextStartIndex(), attribute.getQueryContextEndIndex());
}
}
}
}
innerExpressionExecutors = new ExpressionExecutor[outputAttributes.size()];
for (int i = 0, innerExpressionsLength = outputAttributes.size(); i < innerExpressionsLength; i++) {
innerExpressionExecutors[i] = parseExpression(outputAttributes.get(i), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
}
}
} else {
innerExpressionExecutors = new ExpressionExecutor[0];
}
return innerExpressionExecutors;
}
use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class OutputParser method constructOutputCallback.
public static OutputCallback constructOutputCallback(final OutputStream outStream, StreamDefinition outputStreamDefinition, Map<String, Table> tableMap, Map<String, Window> eventWindowMap, SiddhiAppContext siddhiAppContext, boolean convertToStreamEvent, String queryName) {
String id = outStream.getId();
Table table = null;
Window window = null;
if (id != null) {
table = tableMap.get(id);
window = eventWindowMap.get(id);
}
StreamEventPool streamEventPool = null;
StreamEventConverter streamEventConverter = null;
MetaStreamEvent tableMetaStreamEvent = null;
if (table != null) {
tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
TableDefinition matchingTableDefinition = TableDefinition.id("");
for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
}
matchingTableDefinition.setQueryContextStartIndex(outStream.getQueryContextStartIndex());
matchingTableDefinition.setQueryContextEndIndex(outStream.getQueryContextEndIndex());
tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
streamEventPool = new StreamEventPool(tableMetaStreamEvent, 10);
streamEventConverter = new ZeroStreamEventConverter();
}
// Construct CallBack
if (outStream instanceof InsertIntoStream) {
if (window != null) {
return new InsertIntoWindowCallback(window, outputStreamDefinition, queryName);
} else if (table != null) {
DefinitionParserHelper.validateOutputStream(outputStreamDefinition, table.getTableDefinition());
return new InsertIntoTableCallback(table, outputStreamDefinition, convertToStreamEvent, streamEventPool, streamEventConverter, queryName);
} else {
return new InsertIntoStreamCallback(outputStreamDefinition, queryName);
}
} else if (outStream instanceof DeleteStream || outStream instanceof UpdateStream || outStream instanceof UpdateOrInsertStream) {
if (table != null) {
if (outStream instanceof UpdateStream) {
if (((UpdateStream) outStream).getUpdateSet() == null) {
TableDefinition tableDefinition = table.getTableDefinition();
for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
if (!tableDefinition.getAttributeList().contains(attribute)) {
throw new SiddhiAppCreationException("Attribute " + attribute + " does not exist on " + "Event Table " + tableDefinition, outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
}
}
}
}
if (outStream instanceof UpdateOrInsertStream) {
TableDefinition tableDefinition = table.getTableDefinition();
for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
if (!tableDefinition.getAttributeList().contains(attribute)) {
throw new SiddhiAppCreationException("Attribute " + attribute + " does not exist on " + "Event Table " + tableDefinition, outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
}
}
}
if (outStream instanceof DeleteStream) {
try {
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
CompiledCondition compiledCondition = table.compileCondition((((DeleteStream) outStream).getOnDeleteExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
return new DeleteTableCallback(table, compiledCondition, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
} catch (SiddhiAppValidationException e) {
throw new SiddhiAppCreationException("Cannot create delete for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
}
} else if (outStream instanceof UpdateStream) {
try {
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
CompiledCondition compiledCondition = table.compileCondition((((UpdateStream) outStream).getOnUpdateExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
UpdateSet updateSet = ((UpdateStream) outStream).getUpdateSet();
if (updateSet == null) {
updateSet = new UpdateSet();
for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
}
}
CompiledUpdateSet compiledUpdateSet = table.compileUpdateSet(updateSet, matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
return new UpdateTableCallback(table, compiledCondition, compiledUpdateSet, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
} catch (SiddhiAppValidationException e) {
throw new SiddhiAppCreationException("Cannot create update for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext);
}
} else {
DefinitionParserHelper.validateOutputStream(outputStreamDefinition, table.getTableDefinition());
try {
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
CompiledCondition compiledCondition = table.compileCondition((((UpdateOrInsertStream) outStream).getOnUpdateExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
UpdateSet updateSet = ((UpdateOrInsertStream) outStream).getUpdateSet();
if (updateSet == null) {
updateSet = new UpdateSet();
for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
}
}
CompiledUpdateSet compiledUpdateSet = table.compileUpdateSet(updateSet, matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
return new UpdateOrInsertTableCallback(table, compiledCondition, compiledUpdateSet, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
} catch (SiddhiAppValidationException e) {
throw new SiddhiAppCreationException("Cannot create update or insert into for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext);
}
}
} else {
throw new SiddhiAppCreationException("Event table with id :" + id + " does not exist", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
}
} else {
throw new SiddhiAppCreationException(outStream.getClass().getName() + " not supported", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
}
}
use of org.wso2.balana.ctx.Attribute in project siddhi by wso2.
the class PartitionParser method createMetaEventForPartitioner.
/**
* Create metaEvent to be used by StreamPartitioner with output attributes
*
* @param stateEvent metaStateEvent of the queryRuntime
* @return metaStateEvent
*/
private static MetaStateEvent createMetaEventForPartitioner(MetaComplexEvent stateEvent) {
MetaStateEvent metaStateEvent;
if (stateEvent instanceof MetaStateEvent) {
metaStateEvent = new MetaStateEvent(((MetaStateEvent) stateEvent).getStreamEventCount());
for (MetaStreamEvent metaStreamEvent : ((MetaStateEvent) stateEvent).getMetaStreamEvents()) {
AbstractDefinition definition = metaStreamEvent.getLastInputDefinition();
MetaStreamEvent newMetaStreamEvent = new MetaStreamEvent();
for (Attribute attribute : definition.getAttributeList()) {
newMetaStreamEvent.addOutputData(attribute);
}
newMetaStreamEvent.addInputDefinition(definition);
newMetaStreamEvent.setEventType(metaStreamEvent.getEventType());
metaStateEvent.addEvent(newMetaStreamEvent);
}
} else {
metaStateEvent = new MetaStateEvent(1);
AbstractDefinition definition = ((MetaStreamEvent) stateEvent).getLastInputDefinition();
MetaStreamEvent newMetaStreamEvent = new MetaStreamEvent();
for (Attribute attribute : definition.getAttributeList()) {
newMetaStreamEvent.addOutputData(attribute);
}
newMetaStreamEvent.addInputDefinition(definition);
newMetaStreamEvent.setEventType(((MetaStreamEvent) stateEvent).getEventType());
metaStateEvent.addEvent(newMetaStreamEvent);
}
return metaStateEvent;
}
Aggregations