Search in sources :

Example 26 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor in project siddhi by wso2.

the class AbstractQueryableRecordTable method compileCondition.

@Override
public CompiledCondition compileCondition(Expression condition, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiQueryContext siddhiQueryContext) {
    ExpressionExecutor inMemoryCompiledCondition = ExpressionParser.parseExpression(condition, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
    ExpressionBuilder expressionBuilder = new ExpressionBuilder(condition, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, new UpdateOrInsertReducer(inMemoryCompiledCondition, matchingMetaInfoHolder), null, siddhiQueryContext);
    CompiledCondition compileCondition = compileCondition(expressionBuilder);
    Map<String, ExpressionExecutor> expressionExecutorMap = expressionBuilder.getVariableExpressionExecutorMap();
    if (cacheEnabled) {
        CompiledCondition compiledConditionWithCache = new CompiledConditionWithCache(compileCondition, ((CacheTable) cacheTable).generateCacheCompileCondition(condition, matchingMetaInfoHolder, siddhiQueryContext, variableExpressionExecutors), siddhiQueryContext);
        return new RecordStoreCompiledCondition(expressionExecutorMap, compiledConditionWithCache, siddhiQueryContext);
    } else {
        return new RecordStoreCompiledCondition(expressionExecutorMap, compileCondition, siddhiQueryContext);
    }
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition)

Example 27 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor in project siddhi by wso2.

the class AbstractQueryableRecordTable method generateCSForSelectAll.

private CompiledSelection generateCSForSelectAll() {
    MetaStreamEvent metaStreamEventForSelectAll = new MetaStreamEvent();
    for (Attribute attribute : tableDefinition.getAttributeList()) {
        metaStreamEventForSelectAll.addOutputData(attribute);
    }
    metaStreamEventForSelectAll.addInputDefinition(tableDefinition);
    MetaStateEvent metaStateEventForSelectAll = new MetaStateEvent(1);
    metaStateEventForSelectAll.addEvent(metaStreamEventForSelectAll);
    MatchingMetaInfoHolder matchingMetaInfoHolderForSlectAll = new MatchingMetaInfoHolder(metaStateEventForSelectAll, -1, 0, tableDefinition, tableDefinition, 0);
    List<OutputAttribute> outputAttributesAll = new ArrayList<>();
    List<Attribute> attributeList = tableDefinition.getAttributeList();
    for (Attribute attribute : attributeList) {
        outputAttributesAll.add(new OutputAttribute(new Variable(attribute.getName())));
    }
    List<SelectAttributeBuilder> selectAttributeBuilders = new ArrayList<>(outputAttributesAll.size());
    List<VariableExpressionExecutor> variableExpressionExecutors = new ArrayList<>();
    for (OutputAttribute outputAttribute : outputAttributesAll) {
        ExpressionBuilder expressionBuilder = new ExpressionBuilder(outputAttribute.getExpression(), matchingMetaInfoHolderForSlectAll, variableExpressionExecutors, tableMap, null, null, null);
        selectAttributeBuilders.add(new SelectAttributeBuilder(expressionBuilder, outputAttribute.getRename()));
    }
    return compileSelection(selectAttributeBuilders, null, null, null, null, null);
}
Also used : Variable(io.siddhi.query.api.expression.Variable) MetaStateEventAttribute(io.siddhi.core.event.state.MetaStateEventAttribute) Attribute(io.siddhi.query.api.definition.Attribute) OrderByAttribute(io.siddhi.query.api.execution.query.selection.OrderByAttribute) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) OutputAttribute(io.siddhi.query.api.execution.query.selection.OutputAttribute) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 28 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor in project siddhi by wso2.

the class InMemoryTable method compileUpdateSet.

@Override
public CompiledUpdateSet compileUpdateSet(UpdateSet updateSet, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiQueryContext siddhiQueryContext) {
    Map<Integer, ExpressionExecutor> expressionExecutorMap = new HashMap<>();
    for (UpdateSet.SetAttribute setAttribute : updateSet.getSetAttributeList()) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(setAttribute.getAssignmentExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        int attributePosition = tableDefinition.getAttributePosition(setAttribute.getTableVariable().getAttributeName());
        expressionExecutorMap.put(attributePosition, expressionExecutor);
    }
    return new InMemoryCompiledUpdateSet(expressionExecutorMap);
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) HashMap(java.util.HashMap) UpdateSet(io.siddhi.query.api.execution.query.output.stream.UpdateSet)

Example 29 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor in project siddhi by wso2.

the class AbstractRecordTable method compileCondition.

@Override
public CompiledCondition compileCondition(Expression condition, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiQueryContext siddhiQueryContext) {
    ExpressionExecutor inMemoryCompiledCondition = ExpressionParser.parseExpression(condition, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
    ExpressionBuilder expressionBuilder = new ExpressionBuilder(condition, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, new UpdateOrInsertReducer(inMemoryCompiledCondition, matchingMetaInfoHolder), null, siddhiQueryContext);
    CompiledCondition compileCondition = compileCondition(expressionBuilder);
    Map<String, ExpressionExecutor> expressionExecutorMap = expressionBuilder.getVariableExpressionExecutorMap();
    return new RecordStoreCompiledCondition(expressionExecutorMap, compileCondition, siddhiQueryContext);
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition)

Example 30 with VariableExpressionExecutor

use of io.siddhi.core.executor.VariableExpressionExecutor 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);
}
Also used : LongConstant(io.siddhi.query.api.expression.constant.LongConstant) Variable(io.siddhi.query.api.expression.Variable) Attribute(io.siddhi.query.api.definition.Attribute) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) Expression(io.siddhi.query.api.expression.Expression) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) TableDefinition(io.siddhi.query.api.definition.TableDefinition) Subtract(io.siddhi.query.api.expression.math.Subtract) Compare(io.siddhi.query.api.expression.condition.Compare) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Aggregations

VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)48 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)32 Attribute (io.siddhi.query.api.definition.Attribute)27 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)23 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)23 ArrayList (java.util.ArrayList)20 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)18 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)15 Variable (io.siddhi.query.api.expression.Variable)14 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)13 Expression (io.siddhi.query.api.expression.Expression)13 Map (java.util.Map)13 HashMap (java.util.HashMap)11 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)10 StreamEvent (io.siddhi.core.event.stream.StreamEvent)9 Table (io.siddhi.core.table.Table)8 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)8 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)7 CompiledCondition (io.siddhi.core.util.collection.operator.CompiledCondition)7 AndConditionExpressionExecutor (io.siddhi.core.executor.condition.AndConditionExpressionExecutor)5