use of io.siddhi.query.api.expression.Expression in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitAnd_math_operation.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Expression visitAnd_math_operation(@NotNull SiddhiQLParser.And_math_operationContext ctx) {
if (ctx.AND() != null) {
Expression expression = Expression.and((Expression) visit(ctx.math_operation(0)), (Expression) visit(ctx.math_operation(1)));
populateQueryContext(expression, ctx);
return expression;
} else {
throw newSiddhiParserException(ctx);
}
}
use of io.siddhi.query.api.expression.Expression in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitWithin_time_range.
@Override
public Object visitWithin_time_range(SiddhiQLParser.Within_time_rangeContext ctx) {
Within within;
if (ctx.end_pattern == null) {
within = Within.within((Expression) visit(ctx.start_pattern));
} else {
within = Within.within((Expression) visit(ctx.start_pattern), (Expression) visit(ctx.end_pattern));
}
populateQueryContext(within, ctx);
return within;
}
use of io.siddhi.query.api.expression.Expression in project siddhi by wso2.
the class AvgIncrementalAttributeAggregator method init.
@Override
public void init(String attributeName, Attribute.Type attributeType) {
// Send the relevant attribute to this
Attribute sum;
Attribute count;
Expression sumInitialValue;
Expression countInitialValue;
if (attributeName == null) {
throw new SiddhiAppCreationException("Average incremental attribute aggregation cannot be executed " + "when no parameters are given");
}
SumIncrementalAttributeAggregator sumIncrementalAttributeAggregator = new SumIncrementalAttributeAggregator();
sumIncrementalAttributeAggregator.init(attributeName, attributeType);
CountIncrementalAttributeAggregator countIncrementalAttributeAggregator = new CountIncrementalAttributeAggregator();
countIncrementalAttributeAggregator.init(null, null);
// Only one attribute exists for sum and count
sum = sumIncrementalAttributeAggregator.getBaseAttributes()[0];
count = countIncrementalAttributeAggregator.getBaseAttributes()[0];
// Only one init value exists for sum and count
sumInitialValue = sumIncrementalAttributeAggregator.getBaseAttributeInitialValues()[0];
countInitialValue = countIncrementalAttributeAggregator.getBaseAttributeInitialValues()[0];
this.baseAttributes = new Attribute[] { sum, count };
this.baseAttributesInitialValues = new Expression[] { sumInitialValue, countInitialValue };
}
use of io.siddhi.query.api.expression.Expression in project siddhi by wso2.
the class CountIncrementalAttributeAggregator method init.
@Override
public void init(String attributeName, Attribute.Type attributeType) {
if (attributeName != null) {
LOG.warn("Aggregation count function will return the count of all events and count(" + attributeName + ") will be considered as count().");
}
Attribute count;
Expression countInitialValue;
// Since we set the initial value of count, we can simply set it as long
// However, since count is summed internally (in avg incremental calculation),
// ensure that either double or long is used here (since return value of sum is long or
// double. Long is chosen here)
count = new Attribute("AGG_COUNT", Attribute.Type.LONG);
countInitialValue = Expression.value(1L);
this.baseAttributes = new Attribute[] { count };
this.baseAttributesInitialValues = new Expression[] { countInitialValue };
}
use of io.siddhi.query.api.expression.Expression in project siddhi by wso2.
the class CacheExpirer method generateExpiryCompiledCondition.
private CompiledCondition generateExpiryCompiledCondition() {
MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
TableDefinition matchingTableDefinition = TableDefinition.id(cacheTable.getTableDefinition().getId());
for (Attribute attribute : cacheTable.getTableDefinition().getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
}
tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
streamEventFactory = new StreamEventFactory(tableMetaStreamEvent);
Variable rightExpressionForSubtract = new Variable(CACHE_TABLE_TIMESTAMP_ADDED);
rightExpressionForSubtract.setStreamId(cacheTable.getTableDefinition().getId());
Expression rightExpressionForCompare = new LongConstant(retentionPeriod);
Compare.Operator greaterThanOperator = Compare.Operator.GREATER_THAN;
MetaStreamEvent currentTimeMetaStreamEvent = new MetaStreamEvent();
currentTimeMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
Attribute currentTimeAttribute = new Attribute(CACHE_EXPIRE_CURRENT_TIME, Attribute.Type.LONG);
currentTimeMetaStreamEvent.addOutputData(currentTimeAttribute);
TableDefinition currentTimeTableDefinition = TableDefinition.id("");
currentTimeTableDefinition.attribute(CACHE_EXPIRE_CURRENT_TIME, Attribute.Type.LONG);
currentTimeMetaStreamEvent.addInputDefinition(currentTimeTableDefinition);
MetaStateEvent metaStateEvent = new MetaStateEvent(2);
metaStateEvent.addEvent(currentTimeMetaStreamEvent);
metaStateEvent.addEvent(tableMetaStreamEvent);
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(metaStateEvent, 0, cacheTable.getTableDefinition(), 0);
List<VariableExpressionExecutor> variableExpressionExecutors = new ArrayList<>();
Expression leftExpressionForSubtract = new Variable(CACHE_EXPIRE_CURRENT_TIME);
Expression leftExpressionForCompare = new Subtract(leftExpressionForSubtract, rightExpressionForSubtract);
Expression deleteCondition = new Compare(leftExpressionForCompare, greaterThanOperator, rightExpressionForCompare);
SiddhiQueryContext siddhiQueryContext = new SiddhiQueryContext(siddhiAppContext, "expiryDeleteQuery");
return cacheTable.compileCondition(deleteCondition, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiQueryContext);
}
Aggregations