use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class SiddhiQLBaseVisitorImpl method visitIn_math_operation.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Object visitIn_math_operation(@NotNull SiddhiQLParser.In_math_operationContext ctx) {
Expression expression = Expression.in((Expression) visit(ctx.math_operation()), (String) visit(ctx.name()));
populateQueryContext(expression, ctx);
return expression;
}
use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class SiddhiQLBaseVisitorImpl method visitAddition_math_operation.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Expression visitAddition_math_operation(@NotNull SiddhiQLParser.Addition_math_operationContext ctx) {
Expression expression;
if (ctx.add != null) {
expression = Expression.add((Expression) visit(ctx.math_operation(0)), (Expression) visit(ctx.math_operation(1)));
} else if (ctx.substract != null) {
expression = Expression.subtract((Expression) visit(ctx.math_operation(0)), (Expression) visit(ctx.math_operation(1)));
} else {
throw newSiddhiParserException(ctx);
}
populateQueryContext(expression, ctx);
return expression;
}
use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class SiddhiQLBaseVisitorImpl method visitEquality_math_operation.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Expression visitEquality_math_operation(@NotNull SiddhiQLParser.Equality_math_operationContext ctx) {
if (ctx.eq != null) {
Expression expression = Expression.compare((Expression) visit(ctx.math_operation(0)), Compare.Operator.EQUAL, (Expression) visit(ctx.math_operation(1)));
populateQueryContext(expression, ctx);
return expression;
} else if (ctx.not_eq != null) {
Expression expression = Expression.compare((Expression) visit(ctx.math_operation(0)), Compare.Operator.NOT_EQUAL, (Expression) visit(ctx.math_operation(1)));
populateQueryContext(expression, ctx);
return expression;
} else {
throw newSiddhiParserException(ctx);
}
}
use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.
the class SiddhiQLBaseVisitorImpl method visitFunction_operation.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Object visitFunction_operation(@NotNull SiddhiQLParser.Function_operationContext ctx) {
Expression expression;
if (ctx.function_namespace() != null) {
if (ctx.attribute_list() != null) {
expression = Expression.function((String) visit(ctx.function_namespace()), (String) visit(ctx.function_id()), (Expression[]) visit(ctx.attribute_list()));
} else {
expression = Expression.function((String) visit(ctx.function_namespace()), (String) visit(ctx.function_id()), null);
}
} else {
if (ctx.attribute_list() != null) {
expression = Expression.function((String) visit(ctx.function_id()), (Expression[]) visit(ctx.attribute_list()));
} else {
expression = Expression.function((String) visit(ctx.function_id()), null);
}
}
populateQueryContext(expression, ctx);
return expression;
}
use of org.ballerinalang.siddhi.query.api.expression.Expression 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()));
}
}
}
}
Aggregations