use of org.wso2.siddhi.query.api.expression.condition.Compare in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testUpdateApplicationWithPermissions.
@Test
public void testUpdateApplicationWithPermissions() throws Exception {
// add new app
Application currentApp = TestUtil.addTestApplication();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
// create new app with permissions
HashMap permissionMap = new HashMap();
permissionMap.put(APIMgtConstants.Permission.UPDATE, APIMgtConstants.Permission.UPDATE_PERMISSION);
Application newApp = SampleTestObjectCreator.createAlternativeApplication();
newApp.setId(currentApp.getId());
newApp.setCreatedTime(currentApp.getCreatedTime());
newApp.setPermissionMap(permissionMap);
// update app
applicationDAO.updateApplication(currentApp.getId(), newApp);
// get app
Application appFromDB = applicationDAO.getApplication(newApp.getId());
Assert.assertNotNull(appFromDB);
// compare
Assert.assertEquals(appFromDB, newApp, TestUtil.printDiff(appFromDB, newApp));
validateAppTimestamps(appFromDB, newApp);
}
use of org.wso2.siddhi.query.api.expression.condition.Compare in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testUpdateApplicationState.
@Test
public void testUpdateApplicationState() throws Exception {
// add new app
Application app = TestUtil.addTestApplication();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
// update app
applicationDAO.updateApplicationState(app.getId(), APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED);
// get app
Application appFromDB = applicationDAO.getApplication(app.getId());
Assert.assertNotNull(appFromDB);
// check whether the status has updated
Assert.assertEquals(appFromDB.getStatus(), APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED);
// compare
Assert.assertNotEquals(appFromDB, app, TestUtil.printDiff(appFromDB, app));
validateAppTimestamps(appFromDB, app);
}
use of org.wso2.siddhi.query.api.expression.condition.Compare in project siddhi by wso2.
the class ExpressionParser method parseExpression.
/**
* Parse the given expression and create the appropriate Executor by recursively traversing the expression
*
* @param expression Expression 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
* @param queryName query name of expression belongs to.
* @return ExpressionExecutor
*/
public static ExpressionExecutor parseExpression(Expression expression, MetaComplexEvent metaEvent, int currentState, Map<String, Table> tableMap, List<VariableExpressionExecutor> executorList, SiddhiAppContext siddhiAppContext, boolean groupBy, int defaultStreamEventIndex, String queryName) {
try {
if (expression instanceof And) {
return new AndConditionExpressionExecutor(parseExpression(((And) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((And) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
} else if (expression instanceof Or) {
return new OrConditionExpressionExecutor(parseExpression(((Or) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Or) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
} else if (expression instanceof Not) {
return new NotConditionExpressionExecutor(parseExpression(((Not) expression).getExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
} else if (expression instanceof Compare) {
if (((Compare) expression).getOperator() == Compare.Operator.EQUAL) {
return parseEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
} else if (((Compare) expression).getOperator() == Compare.Operator.NOT_EQUAL) {
return parseNotEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
} else if (((Compare) expression).getOperator() == Compare.Operator.GREATER_THAN) {
return parseGreaterThanCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
} else if (((Compare) expression).getOperator() == Compare.Operator.GREATER_THAN_EQUAL) {
return parseGreaterThanEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
} else if (((Compare) expression).getOperator() == Compare.Operator.LESS_THAN) {
return parseLessThanCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
} else if (((Compare) expression).getOperator() == Compare.Operator.LESS_THAN_EQUAL) {
return parseLessThanEqualCompare(parseExpression(((Compare) expression).getLeftExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName), parseExpression(((Compare) expression).getRightExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName));
}
} else if (expression instanceof Constant) {
if (expression instanceof BoolConstant) {
return new ConstantExpressionExecutor(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
} else if (expression instanceof StringConstant) {
return new ConstantExpressionExecutor(((StringConstant) expression).getValue(), Attribute.Type.STRING);
} else if (expression instanceof IntConstant) {
return new ConstantExpressionExecutor(((IntConstant) expression).getValue(), Attribute.Type.INT);
} else if (expression instanceof LongConstant) {
return new ConstantExpressionExecutor(((LongConstant) expression).getValue(), Attribute.Type.LONG);
} else if (expression instanceof FloatConstant) {
return new ConstantExpressionExecutor(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
} else if (expression instanceof DoubleConstant) {
return new ConstantExpressionExecutor(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
}
} else if (expression instanceof Variable) {
return parseVariable((Variable) expression, metaEvent, currentState, executorList, defaultStreamEventIndex);
} else if (expression instanceof Multiply) {
ExpressionExecutor left = parseExpression(((Multiply) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
ExpressionExecutor right = parseExpression(((Multiply) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
Attribute.Type type = parseArithmeticOperationResultType(left, right);
switch(type) {
case INT:
return new MultiplyExpressionExecutorInt(left, right);
case LONG:
return new MultiplyExpressionExecutorLong(left, right);
case FLOAT:
return new MultiplyExpressionExecutorFloat(left, right);
case DOUBLE:
return new MultiplyExpressionExecutorDouble(left, right);
// Will not happen. Handled in parseArithmeticOperationResultType()
default:
}
} else if (expression instanceof Add) {
ExpressionExecutor left = parseExpression(((Add) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
ExpressionExecutor right = parseExpression(((Add) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
Attribute.Type type = parseArithmeticOperationResultType(left, right);
switch(type) {
case INT:
return new AddExpressionExecutorInt(left, right);
case LONG:
return new AddExpressionExecutorLong(left, right);
case FLOAT:
return new AddExpressionExecutorFloat(left, right);
case DOUBLE:
return new AddExpressionExecutorDouble(left, right);
// Will not happen. Handled in parseArithmeticOperationResultType()
default:
}
} else if (expression instanceof Subtract) {
ExpressionExecutor left = parseExpression(((Subtract) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
ExpressionExecutor right = parseExpression(((Subtract) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
Attribute.Type type = parseArithmeticOperationResultType(left, right);
switch(type) {
case INT:
return new SubtractExpressionExecutorInt(left, right);
case LONG:
return new SubtractExpressionExecutorLong(left, right);
case FLOAT:
return new SubtractExpressionExecutorFloat(left, right);
case DOUBLE:
return new SubtractExpressionExecutorDouble(left, right);
// Will not happen. Handled in parseArithmeticOperationResultType()
default:
}
} else if (expression instanceof Mod) {
ExpressionExecutor left = parseExpression(((Mod) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
ExpressionExecutor right = parseExpression(((Mod) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
Attribute.Type type = parseArithmeticOperationResultType(left, right);
switch(type) {
case INT:
return new ModExpressionExecutorInt(left, right);
case LONG:
return new ModExpressionExecutorLong(left, right);
case FLOAT:
return new ModExpressionExecutorFloat(left, right);
case DOUBLE:
return new ModExpressionExecutorDouble(left, right);
// Will not happen. Handled in parseArithmeticOperationResultType()
default:
}
} else if (expression instanceof Divide) {
ExpressionExecutor left = parseExpression(((Divide) expression).getLeftValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
ExpressionExecutor right = parseExpression(((Divide) expression).getRightValue(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
Attribute.Type type = parseArithmeticOperationResultType(left, right);
switch(type) {
case INT:
return new DivideExpressionExecutorInt(left, right);
case LONG:
return new DivideExpressionExecutorLong(left, right);
case FLOAT:
return new DivideExpressionExecutorFloat(left, right);
case DOUBLE:
return new DivideExpressionExecutorDouble(left, right);
// Will not happen. Handled in parseArithmeticOperationResultType()
default:
}
} else if (expression instanceof AttributeFunction) {
// extensions
Object executor;
try {
if ((siddhiAppContext.isFunctionExist(((AttributeFunction) expression).getName())) && (((AttributeFunction) expression).getNamespace()).isEmpty()) {
executor = new ScriptFunctionExecutor(((AttributeFunction) expression).getName());
} else {
executor = SiddhiClassLoader.loadExtensionImplementation((AttributeFunction) expression, FunctionExecutorExtensionHolder.getInstance(siddhiAppContext));
}
} catch (SiddhiAppCreationException ex) {
try {
executor = SiddhiClassLoader.loadExtensionImplementation((AttributeFunction) expression, AttributeAggregatorExtensionHolder.getInstance(siddhiAppContext));
} catch (SiddhiAppCreationException e) {
throw new SiddhiAppCreationException("'" + ((AttributeFunction) expression).getName() + "' is" + " neither a function extension nor an aggregated attribute extension", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
}
}
ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(((AttributeFunction) expression).getNamespace(), ((AttributeFunction) expression).getName());
if (executor instanceof FunctionExecutor) {
FunctionExecutor expressionExecutor = (FunctionExecutor) executor;
Expression[] innerExpressions = ((AttributeFunction) expression).getParameters();
ExpressionExecutor[] innerExpressionExecutors = parseInnerExpression(innerExpressions, metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
expressionExecutor.initExecutor(innerExpressionExecutors, siddhiAppContext, queryName, configReader);
if (expressionExecutor.getReturnType() == Attribute.Type.BOOL) {
return new BoolConditionExpressionExecutor(expressionExecutor);
}
return expressionExecutor;
} else {
AttributeAggregator attributeAggregator = (AttributeAggregator) executor;
Expression[] innerExpressions = ((AttributeFunction) expression).getParameters();
ExpressionExecutor[] innerExpressionExecutors = parseInnerExpression(innerExpressions, metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
attributeAggregator.initAggregator(innerExpressionExecutors, siddhiAppContext, configReader);
AbstractAggregationAttributeExecutor aggregationAttributeProcessor;
if (groupBy) {
aggregationAttributeProcessor = new GroupByAggregationAttributeExecutor(attributeAggregator, innerExpressionExecutors, configReader, siddhiAppContext, queryName);
} else {
aggregationAttributeProcessor = new AggregationAttributeExecutor(attributeAggregator, innerExpressionExecutors, siddhiAppContext, queryName);
}
SelectorParser.getContainsAggregatorThreadLocal().set("true");
return aggregationAttributeProcessor;
}
} else if (expression instanceof In) {
Table table = tableMap.get(((In) expression).getSourceId());
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(metaEvent, defaultStreamEventIndex, table.getTableDefinition(), defaultStreamEventIndex);
CompiledCondition compiledCondition = table.compileCondition(((In) expression).getExpression(), matchingMetaInfoHolder, siddhiAppContext, executorList, tableMap, queryName);
return new InConditionExpressionExecutor(table, compiledCondition, matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents().length, metaEvent instanceof StateEvent, 0);
} else if (expression instanceof IsNull) {
IsNull isNull = (IsNull) expression;
if (isNull.getExpression() != null) {
ExpressionExecutor innerExpressionExecutor = parseExpression(isNull.getExpression(), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
return new IsNullConditionExpressionExecutor(innerExpressionExecutor);
} else {
String streamId = isNull.getStreamId();
Integer streamIndex = isNull.getStreamIndex();
if (metaEvent instanceof MetaStateEvent) {
int[] eventPosition = new int[2];
if (streamIndex != null) {
if (streamIndex <= LAST) {
eventPosition[STREAM_EVENT_INDEX_IN_CHAIN] = streamIndex + 1;
} else {
eventPosition[STREAM_EVENT_INDEX_IN_CHAIN] = streamIndex;
}
} else {
eventPosition[STREAM_EVENT_INDEX_IN_CHAIN] = defaultStreamEventIndex;
}
eventPosition[STREAM_EVENT_CHAIN_INDEX] = UNKNOWN_STATE;
MetaStateEvent metaStateEvent = (MetaStateEvent) metaEvent;
if (streamId == null) {
throw new SiddhiAppCreationException("IsNull does not support streamId being null", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
} else {
MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
AbstractDefinition definition = metaStreamEvent.getLastInputDefinition();
if (metaStreamEvent.getInputReferenceId() == null) {
if (definition.getId().equals(streamId)) {
eventPosition[STREAM_EVENT_CHAIN_INDEX] = i;
break;
}
} else {
if (metaStreamEvent.getInputReferenceId().equals(streamId)) {
eventPosition[STREAM_EVENT_CHAIN_INDEX] = i;
if (currentState > -1 && metaStreamEvents[currentState].getInputReferenceId() != null && streamIndex != null && streamIndex <= LAST) {
if (streamId.equals(metaStreamEvents[currentState].getInputReferenceId())) {
eventPosition[STREAM_EVENT_INDEX_IN_CHAIN] = streamIndex;
}
}
break;
}
}
}
}
return new IsNullStreamConditionExpressionExecutor(eventPosition);
} else {
return new IsNullStreamConditionExpressionExecutor(null);
}
}
}
throw new UnsupportedOperationException(expression.toString() + " not supported!");
} catch (Throwable t) {
ExceptionUtil.populateQueryContext(t, expression, siddhiAppContext);
throw t;
}
}
use of org.wso2.siddhi.query.api.expression.condition.Compare in project siddhi by wso2.
the class OrderByEventComparator method compare.
@Override
public int compare(ComplexEvent complexEvent1, ComplexEvent complexEvent2) {
if (groupByExecutors != null) {
for (int i = 0, groupByExecutorsLength = groupByExecutors.length; i < groupByExecutorsLength; i++) {
ExpressionExecutor executor = groupByExecutors[i];
boolean isAscending = isAscendingArray[i];
Object value1 = executor.execute(complexEvent1);
Object value2 = executor.execute(complexEvent2);
if (value1 != null && value2 != null) {
int results = 0;
Attribute.Type type = executor.getReturnType();
switch(type) {
case STRING:
results = ((String) value1).compareTo(((String) value2));
break;
case INT:
results = ((Integer) value1).compareTo(((Integer) value2));
break;
case LONG:
results = ((Long) value1).compareTo(((Long) value2));
break;
case FLOAT:
results = ((Float) value1).compareTo(((Float) value2));
break;
case DOUBLE:
results = ((Double) value1).compareTo(((Double) value2));
break;
case BOOL:
results = ((Boolean) value1).compareTo(((Boolean) value2));
break;
case OBJECT:
int hashDiff = value1.hashCode() - value2.hashCode();
if (hashDiff < 0) {
results = -1;
} else if (hashDiff > 0) {
results = 1;
}
}
if (!isAscending) {
results = results * -1;
}
if (results != 0) {
return results;
}
} else if (value1 != null) {
return -1;
} else if (value2 != null) {
return 1;
}
}
return 0;
} else {
return 0;
}
}
use of org.wso2.siddhi.query.api.expression.condition.Compare in project siddhi by wso2.
the class ExpressionBuilder method buildVariableExecutors.
private void buildVariableExecutors(Expression expression, ExpressionVisitor expressionVisitor) {
try {
if (expression instanceof And) {
expressionVisitor.beginVisitAnd();
expressionVisitor.beginVisitAndLeftOperand();
buildVariableExecutors(((And) expression).getLeftExpression(), expressionVisitor);
expressionVisitor.endVisitAndLeftOperand();
expressionVisitor.beginVisitAndRightOperand();
buildVariableExecutors(((And) expression).getRightExpression(), expressionVisitor);
expressionVisitor.endVisitAndRightOperand();
expressionVisitor.endVisitAnd();
} else if (expression instanceof Or) {
expressionVisitor.beginVisitOr();
expressionVisitor.beginVisitOrLeftOperand();
buildVariableExecutors(((Or) expression).getLeftExpression(), expressionVisitor);
expressionVisitor.endVisitOrLeftOperand();
expressionVisitor.beginVisitOrRightOperand();
buildVariableExecutors(((Or) expression).getRightExpression(), expressionVisitor);
expressionVisitor.endVisitOrRightOperand();
expressionVisitor.endVisitOr();
} else if (expression instanceof Not) {
expressionVisitor.beginVisitNot();
buildVariableExecutors(((Not) expression).getExpression(), expressionVisitor);
expressionVisitor.endVisitNot();
} else if (expression instanceof Compare) {
expressionVisitor.beginVisitCompare(((Compare) expression).getOperator());
expressionVisitor.beginVisitCompareLeftOperand(((Compare) expression).getOperator());
buildVariableExecutors(((Compare) expression).getLeftExpression(), expressionVisitor);
expressionVisitor.endVisitCompareLeftOperand(((Compare) expression).getOperator());
expressionVisitor.beginVisitCompareRightOperand(((Compare) expression).getOperator());
buildVariableExecutors(((Compare) expression).getRightExpression(), expressionVisitor);
expressionVisitor.endVisitCompareRightOperand(((Compare) expression).getOperator());
expressionVisitor.endVisitCompare(((Compare) expression).getOperator());
} else if (expression instanceof Add) {
expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.ADD);
expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.ADD);
buildVariableExecutors(((Add) expression).getLeftValue(), expressionVisitor);
expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.ADD);
expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.ADD);
buildVariableExecutors(((Add) expression).getRightValue(), expressionVisitor);
expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.ADD);
expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.ADD);
} else if (expression instanceof Subtract) {
expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.SUBTRACT);
expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.SUBTRACT);
buildVariableExecutors(((Subtract) expression).getLeftValue(), expressionVisitor);
expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.SUBTRACT);
expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.SUBTRACT);
buildVariableExecutors(((Subtract) expression).getRightValue(), expressionVisitor);
expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.SUBTRACT);
expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.SUBTRACT);
} else if (expression instanceof Divide) {
expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.DIVIDE);
expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.DIVIDE);
buildVariableExecutors(((Divide) expression).getLeftValue(), expressionVisitor);
expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.DIVIDE);
expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.DIVIDE);
buildVariableExecutors(((Divide) expression).getRightValue(), expressionVisitor);
expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.DIVIDE);
expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.DIVIDE);
} else if (expression instanceof Multiply) {
expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.MULTIPLY);
expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.MULTIPLY);
buildVariableExecutors(((Multiply) expression).getLeftValue(), expressionVisitor);
expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.MULTIPLY);
expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.MULTIPLY);
buildVariableExecutors(((Multiply) expression).getRightValue(), expressionVisitor);
expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.MULTIPLY);
expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.MULTIPLY);
} else if (expression instanceof Mod) {
expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.MOD);
expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.MOD);
buildVariableExecutors(((Mod) expression).getLeftValue(), expressionVisitor);
expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.MOD);
expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.MOD);
buildVariableExecutors(((Mod) expression).getRightValue(), expressionVisitor);
expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.MOD);
expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.MOD);
} else if (expression instanceof IsNull) {
IsNull isNull = (IsNull) expression;
if (isNull.getExpression() != null) {
expressionVisitor.beginVisitIsNull(null);
buildVariableExecutors(((IsNull) expression).getExpression(), expressionVisitor);
expressionVisitor.endVisitIsNull(null);
} else {
String streamId = isNull.getStreamId();
MetaStateEvent metaStateEvent = matchingMetaInfoHolder.getMetaStateEvent();
if (streamId == null) {
throw new SiddhiAppCreationException("IsNull does not support streamId being null");
} else {
AbstractDefinition definitionOutput = null;
MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
AbstractDefinition definition = metaStreamEvent.getLastInputDefinition();
if (metaStreamEvent.getInputReferenceId() == null) {
if (definition.getId().equals(streamId)) {
definitionOutput = definition;
break;
}
} else {
if (metaStreamEvent.getInputReferenceId().equals(streamId)) {
definitionOutput = definition;
break;
}
}
}
if (definitionOutput != null) {
expressionVisitor.beginVisitIsNull(definitionOutput.getId());
expressionVisitor.endVisitIsNull(definitionOutput.getId());
} else {
expressionVisitor.beginVisitIsNull(null);
expressionVisitor.endVisitIsNull(null);
}
}
}
} else if (expression instanceof In) {
expressionVisitor.beginVisitIn(((In) expression).getSourceId());
buildVariableExecutors(((In) expression).getExpression(), expressionVisitor);
expressionVisitor.endVisitIn(((In) expression).getSourceId());
} else if (expression instanceof Constant) {
if (expression instanceof DoubleConstant) {
expressionVisitor.beginVisitConstant(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
expressionVisitor.endVisitConstant(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
} else if (expression instanceof StringConstant) {
expressionVisitor.beginVisitConstant(((StringConstant) expression).getValue(), Attribute.Type.STRING);
expressionVisitor.endVisitConstant(((StringConstant) expression).getValue(), Attribute.Type.STRING);
} else if (expression instanceof IntConstant) {
expressionVisitor.beginVisitConstant(((IntConstant) expression).getValue(), Attribute.Type.INT);
expressionVisitor.endVisitConstant(((IntConstant) expression).getValue(), Attribute.Type.INT);
} else if (expression instanceof BoolConstant) {
expressionVisitor.beginVisitConstant(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
expressionVisitor.endVisitConstant(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
} else if (expression instanceof FloatConstant) {
expressionVisitor.beginVisitConstant(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
expressionVisitor.endVisitConstant(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
} else if (expression instanceof LongConstant) {
expressionVisitor.beginVisitConstant(((LongConstant) expression).getValue(), Attribute.Type.LONG);
expressionVisitor.endVisitConstant(((LongConstant) expression).getValue(), Attribute.Type.LONG);
} else {
throw new OperationNotSupportedException("No constant exist with type " + expression.getClass().getName());
}
} else if (expression instanceof AttributeFunction) {
expressionVisitor.beginVisitAttributeFunction(((AttributeFunction) expression).getNamespace(), ((AttributeFunction) expression).getName());
Expression[] expressions = ((AttributeFunction) expression).getParameters();
for (int i = 0; i < expressions.length; i++) {
expressionVisitor.beginVisitParameterAttributeFunction(i);
buildVariableExecutors(expressions[i], expressionVisitor);
expressionVisitor.endVisitParameterAttributeFunction(i);
}
expressionVisitor.endVisitAttributeFunction(((AttributeFunction) expression).getNamespace(), ((AttributeFunction) expression).getName());
} else if (expression instanceof Variable) {
Variable variable = ((Variable) expression);
String attributeName = variable.getAttributeName();
AbstractDefinition definition;
Attribute.Type type = null;
int streamEventChainIndex = matchingMetaInfoHolder.getCurrentState();
if (variable.getStreamId() == null) {
MetaStreamEvent[] metaStreamEvents = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents();
if (streamEventChainIndex == UNKNOWN_STATE) {
String firstInput = null;
for (int i = 0; i < metaStreamEvents.length; i++) {
MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
definition = metaStreamEvent.getLastInputDefinition();
if (type == null) {
try {
type = definition.getAttributeType(attributeName);
firstInput = "Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId();
streamEventChainIndex = i;
} catch (AttributeNotExistException e) {
// do nothing
}
} else {
try {
definition.getAttributeType(attributeName);
throw new SiddhiAppValidationException(firstInput + " and Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId() + " contains attribute " + "with same" + " name '" + attributeName + "'");
} catch (AttributeNotExistException e) {
// do nothing as its expected
}
}
}
if (streamEventChainIndex != UNKNOWN_STATE) {
if (matchingMetaInfoHolder.getMatchingStreamEventIndex() == streamEventChainIndex) {
buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
} else {
buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
}
}
} else {
MetaStreamEvent metaStreamEvent = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvent(matchingMetaInfoHolder.getCurrentState());
definition = metaStreamEvent.getLastInputDefinition();
try {
type = definition.getAttributeType(attributeName);
} catch (AttributeNotExistException e) {
throw new SiddhiAppValidationException(e.getMessageWithOutContext() + " Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId(), e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
}
if (matchingMetaInfoHolder.getCurrentState() == matchingMetaInfoHolder.getMatchingStreamEventIndex()) {
buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
} else {
buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
}
}
} else {
MetaStreamEvent[] metaStreamEvents = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents();
for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
definition = metaStreamEvent.getLastInputDefinition();
if (metaStreamEvent.getInputReferenceId() == null) {
if (definition.getId().equals(variable.getStreamId())) {
type = definition.getAttributeType(attributeName);
streamEventChainIndex = i;
break;
}
} else {
if (metaStreamEvent.getInputReferenceId().equals(variable.getStreamId())) {
type = definition.getAttributeType(attributeName);
streamEventChainIndex = i;
break;
}
}
}
if (matchingMetaInfoHolder.getMatchingStreamEventIndex() == streamEventChainIndex) {
buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
} else {
buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
}
}
}
} catch (Throwable t) {
ExceptionUtil.populateQueryContext(t, expression, siddhiAppContext);
throw t;
}
}
Aggregations