io.siddhi.core.executor.ExpressionExecutor Java Examples

The following examples show how to use io.siddhi.core.executor.ExpressionExecutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultFunctionExecutor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors,
                            ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        // check whether all the arguments passed
        throw new SiddhiAppValidationException("Invalid no of parameters passed to default() function, " +
                "it require only 2 (attribute, default value) , "
                + "but found "
                + attributeExpressionExecutors.length);
    } else if (!(attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor)) {
        throw new SiddhiAppValidationException("Invalid parameter passed to default() function, " +
                "this only consumes constants, but found "
                + attributeExpressionExecutors[1].getClass().getName());

    } else if ((attributeExpressionExecutors[0].getReturnType() != attributeExpressionExecutors[1]
            .getReturnType())) {
        throw new SiddhiAppValidationException("Both attribute and default value parameters need to be of "
                + "same return type but they are of " +
                attributeExpressionExecutors[0].getReturnType() + "and" +
                attributeExpressionExecutors[1].getReturnType());
    }
    returnType = attributeExpressionExecutors[0].getReturnType();
    return null;
}
 
Example #2
Source File: BaseIncrementalValueStore.java    From siddhi with Apache License 2.0 6 votes vote down vote up
public synchronized void process(StreamEvent streamEvent) {
    ValueState state = valueStateHolder.getState();
    try {
        boolean shouldUpdate = true;
        if (shouldUpdateTimestamp != null) {
            shouldUpdate = shouldUpdate(shouldUpdateTimestamp.execute(streamEvent), state);
        }
        for (int i = 0; i < expressionExecutors.size(); i++) { // keeping timestamp value location as null
            ExpressionExecutor expressionExecutor = expressionExecutors.get(i);
            if (shouldUpdate) {
                state.setValue(expressionExecutor.execute(streamEvent), i + 1);
            } else if (!(expressionExecutor instanceof VariableExpressionExecutor)) {
                state.setValue(expressionExecutor.execute(streamEvent), i + 1);
            }
        }
        setProcessed(true);
    } finally {
        valueStateHolder.returnState(state);
    }
}
 
Example #3
Source File: IfThenElseFunctionExecutor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors,
                            ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 3) {
        // check whether all the arguments passed
        throw new SiddhiAppValidationException("Invalid no of arguments passed to ifThenElse() function, " +
                "required only 3, but found " + attributeExpressionExecutors.length);
    } else if (!attributeExpressionExecutors[0].getReturnType().equals(Attribute.Type.BOOL)) {
        // check whether first argument Boolean or not
        throw new SiddhiAppValidationException("Input type of if in ifThenElse function should be of " +
                "type BOOL, but found " + attributeExpressionExecutors[0].getReturnType());
    } else if (!attributeExpressionExecutors[1].getReturnType().equals(
            attributeExpressionExecutors[2].getReturnType())) {
        // check whether second and thirds argument's return type are equivalent.
        throw new SiddhiAppValidationException("Input type of then in ifThenElse function and else in " +
                "ifThenElse function should be of equivalent type. but found then type: " +
                attributeExpressionExecutors[1].getReturnType() + " and else type: " +
                attributeExpressionExecutors[2].getReturnType());
    } else {
        returnType = attributeExpressionExecutors[1].getReturnType();
    }
    return null;
}
 
Example #4
Source File: EqualsIgnoreCaseExtension.java    From eagle with Apache License 2.0 6 votes vote down vote up
/**
 * The initialization method for EqualsIgnoreCaseExtension,
 * this method will be called before the other methods.
 *
 * @param attributeExpressionExecutors the executors of each function parameter
 * @param configReader                 the config reader for the Siddhi app
 * @param siddhiQueryContext           the context of the Siddhi query
 */
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("Invalid no of arguments passed to str:equalsIgnoreCase() "
                + "function, required 2, but found " + attributeExpressionExecutors.length);
    }
    if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the first argument of "
                + "str:equalsIgnoreCase() function, required " + Attribute.Type.STRING + ", but found "
                + attributeExpressionExecutors[0].getReturnType().toString());
    }
    if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the second argument of "
                + "str:equalsIgnoreCase() function, required " + Attribute.Type.STRING + ", but found "
                + attributeExpressionExecutors[1].getReturnType().toString());
    }
    return null;
}
 
Example #5
Source File: CollectionOperator.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, Object storeEvents,
                   InMemoryCompiledUpdateSet compiledUpdateSet) {
    if (((Collection<StreamEvent>) storeEvents).size() > 0) {
        updatingEventChunk.reset();
        while (updatingEventChunk.hasNext()) {
            StateEvent updatingEvent = updatingEventChunk.next();
            try {
                for (StreamEvent storeEvent : ((Collection<StreamEvent>) storeEvents)) {
                    updatingEvent.setEvent(storeEventPosition, storeEvent);
                    if ((Boolean) expressionExecutor.execute(updatingEvent)) {
                        for (Map.Entry<Integer, ExpressionExecutor> entry :
                                compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                            storeEvent.setOutputData(entry.getValue().execute(updatingEvent), entry.getKey());
                        }
                    }
                }
            } finally {
                updatingEvent.setEvent(storeEventPosition, null);
            }
        }
    }
}
 
Example #6
Source File: StringListSizeFunctionExtension.java    From eagle with Apache License 2.0 6 votes vote down vote up
/**
 * The initialization method for StringListSizeFunctionExtension,
 * this method will be called before the other methods.
 *
 * @param attributeExpressionExecutors  the executors of each function parameter
 * @param configReader                  the config reader for the Siddhi app
 * @param siddhiQueryContext            the context of the Siddhi query
 */
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 1) {
        throw new SiddhiAppValidationException("Invalid no of arguments passed to str:listSize() function, "
                + "required 1, but found " + attributeExpressionExecutors.length);
    }

    Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType();
    if (attributeType != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the argument of str:listSize() "
                + "function, required " + Attribute.Type.STRING + ", but found " + attributeType.toString());
    }
    return null;
}
 
Example #7
Source File: DelayWindowProcessor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    this.siddhiQueryContext = siddhiQueryContext;
    if (attributeExpressionExecutors.length == 1) {
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT ||
                    attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                delayInMilliSeconds = Long.parseLong(((ConstantExpressionExecutor) attributeExpressionExecutors[0])
                        .getValue().toString());
            } else {
                throw new SiddhiAppValidationException("Delay window's parameter attribute should be either " +
                        "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("Delay window should have constant parameter attribute but " +
                    "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
    } else {
        throw new SiddhiAppValidationException("Delay window should only have one parameter (<int|long|time> " +
                "delayTime), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    return () -> new DelayedWindowState(streamEventClonerHolder);
}
 
Example #8
Source File: AttributeStreamFunction.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(AbstractDefinition inputDefinition,
                            ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            boolean outputExpectsExpiredEvents, SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 1) {
        throw new SiddhiAppCreationException("Only one attribute is expected but found " +
                attributeExpressionExecutors.length);
    }
    if (!(attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor)) {
        throw new SiddhiAppCreationException("Attribute is expected to be constant, but its not!");
    }
    newAttributes = new ArrayList<>();
    newAttributes.add(
            new Attribute(((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue().toString(),
                    inputDefinition.getAttributeList().get(0).getType()));
    return null;
}
 
Example #9
Source File: IncrementalAggregateBaseTimeFunctionExecutor.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 2) {
        throw new SiddhiAppValidationException("incrementalAggregator:getAggregationStartTime() function accepts " +
                "two arguments, but found " + attributeExpressionExecutors.length);
    }
    if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) {
        throw new SiddhiAppValidationException("Second argument of " +
                "incrementalAggregator:getAggregationStartTime() function accepts should be of type 'STRING', " +
                "but found '" + attributeExpressionExecutors[1].getReturnType() + "'.");
    }
    this.timeZone = siddhiQueryContext.getSiddhiContext().getConfigManager().extractProperty(SiddhiConstants
            .AGG_TIME_ZONE);
    if (timeZone == null) {
        this.timeZone = SiddhiConstants.AGG_TIME_ZONE_DEFAULT;
    }
    return null;
}
 
Example #10
Source File: InMemoryTable.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #11
Source File: EventTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = OperationNotSupportedException.class)
    public void testConditionExpressionExecutorValidation() {
//        StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
// .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);

        VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute
                ("volume", Attribute.Type.INT), 0, 0);
        volumeVariableExpressionExecutor.setPosition(new int[]{0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants
                .OUTPUT_DATA_INDEX, 2});

        ConstantExpressionExecutor constantExpressionExecutor = new ConstantExpressionExecutor(10f, Attribute.Type
                .FLOAT);
        ExpressionExecutor compareGreaterThanExecutor = new GreaterThanCompareConditionExpressionExecutorIntInt(new
                ConstantExpressionExecutor(10, Attribute.Type.INT), volumeVariableExpressionExecutor);
        ExpressionExecutor andExecutor = new AndConditionExpressionExecutor(constantExpressionExecutor,
                compareGreaterThanExecutor);
    }
 
Example #12
Source File: GroupByKeyGenerator.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public GroupByKeyGenerator(List<Expression> groupByList,
                           MetaComplexEvent metaComplexEvent,
                           int currentState, Map<String, Table> tableMap,
                           List<VariableExpressionExecutor> executors,
                           SiddhiQueryContext siddhiQueryContext) {
    if (!groupByList.isEmpty()) {
        groupByExecutors = new ExpressionExecutor[groupByList.size()];
        for (int i = 0, expressionsSize = groupByList.size(); i < expressionsSize; i++) {
            groupByExecutors[i] = ExpressionParser.parseExpression(
                    groupByList.get(i), metaComplexEvent, currentState, tableMap, executors,
                    false, 0, ProcessingMode.BATCH, false,
                    siddhiQueryContext);
        }
    }
}
 
Example #13
Source File: CoalesceFunctionExecutor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                         SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length == 0) {
        throw new SiddhiAppValidationException("Coalesce must have at least one parameter");
    }
    Attribute.Type type = attributeExpressionExecutors[0].getReturnType();
    for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) {
        if (type != expressionExecutor.getReturnType()) {
            throw new SiddhiAppValidationException("Coalesce cannot have parameters with different type");
        }
    }
    returnType = type;
    return null;
}
 
Example #14
Source File: AggregationParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static ExpressionExecutor getTimeStampExecutor(SiddhiQueryContext siddhiQueryContext,
                                                       Map<String, Table> tableMap,
                                                       List<VariableExpressionExecutor> variableExpressionExecutors,
                                                       MetaStreamEvent metaStreamEvent) {

    Expression timestampExpression;
    ExpressionExecutor timestampExecutor;

    // Execution is based on system time, the GMT time zone would be used.
    timestampExpression = AttributeFunction.function("currentTimeMillis", null);
    timestampExecutor = ExpressionParser.parseExpression(timestampExpression, metaStreamEvent, 0, tableMap,
            variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
    return timestampExecutor;
}
 
Example #15
Source File: MaximumFunctionExecutor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    Attribute.Type attributeTypeOne = attributeExpressionExecutors[0].getReturnType();
    if (!((attributeTypeOne == Attribute.Type.DOUBLE) || (attributeTypeOne == Attribute.Type.INT) ||
            (attributeTypeOne == Attribute.Type.FLOAT) || (attributeTypeOne == Attribute.Type.LONG))) {
        throw new SiddhiAppValidationException("Invalid parameter type found for the argument" + 1 +
                " of maximum() function, " +
                "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG +
                " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE +
                ", but found " + attributeTypeOne.toString());
    }
    for (int i = 1; i < attributeExpressionExecutors.length; i++) {
        Attribute.Type attributeType = attributeExpressionExecutors[i].getReturnType();
        if (!((attributeType == Attribute.Type.DOUBLE) || (attributeType == Attribute.Type.INT) ||
                (attributeType == Attribute.Type.FLOAT) || (attributeType == Attribute.Type.LONG))) {
            throw new SiddhiAppValidationException("Invalid parameter type found for the argument" + i +
                    " of maximum() function, " +
                    "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG +
                    " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE +
                    ", but found " + attributeType.toString());
        }
        if (attributeTypeOne != attributeType) {
            throw new SiddhiAppValidationException("Invalid parameter type found for arguments  " +
                    "of maximum() function, all parameters should be of same type, but found " +
                    attributeTypeOne + " and " + attributeExpressionExecutors[i].getReturnType());
        }

    }
    returnType = attributeTypeOne;
    return null;
}
 
Example #16
Source File: GroupByKeyGenerator.java    From siddhi with Apache License 2.0 5 votes vote down vote up
/**
 * generate groupBy key of a streamEvent
 *
 * @param event complexEvent
 * @return GroupByKey
 */
public String constructEventKey(ComplexEvent event) {
    if (groupByExecutors != null) {
        StringBuilder sb = new StringBuilder();
        for (ExpressionExecutor executor : groupByExecutors) {
            sb.append(executor.execute(event)).append(SiddhiConstants.KEY_DELIMITER);
        }
        return sb.toString();
    } else {
        return null;
    }
}
 
Example #17
Source File: TimeWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory<WindowState> init(ExpressionExecutor[] attributeExpressionExecutors,
                                         ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) {
    this.siddhiQueryContext = siddhiQueryContext;

    if (attributeExpressionExecutors.length == 1) {
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
                timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0])
                        .getValue();

            } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0])
                        .getValue();
            } else {
                throw new SiddhiAppValidationException("Time window's parameter attribute should be either " +
                        "int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("Time window should have constant parameter attribute but " +
                    "found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
    } else {
        throw new SiddhiAppValidationException("Time window should only have one parameter (<int|long|time> " +
                "windowTime), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    return () -> new WindowState(streamEventClonerHolder);
}
 
Example #18
Source File: MaxAttributeAggregatorExecutor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
/**
 * The initialization method for FunctionExecutor
 *
 * @param attributeExpressionExecutors are the executors of each attributes in the function
 * @param processingMode               query processing mode
 * @param outputExpectsExpiredEvents   is expired events sent as output
 * @param configReader                 this hold the {@link MaxAttributeAggregatorExecutor} configuration reader.
 * @param siddhiQueryContext           Siddhi query runtime context
 */
@Override
protected StateFactory<MaxAggregatorState> init(ExpressionExecutor[] attributeExpressionExecutors,
                                                ProcessingMode processingMode,
                                                boolean outputExpectsExpiredEvents,
                                                ConfigReader configReader,
                                                SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 1) {
        throw new OperationNotSupportedException("Max aggregator has to have exactly 1 parameter, currently " +
                attributeExpressionExecutors.length + " parameters provided");
    }
    boolean trackFutureStates = false;
    if (processingMode == ProcessingMode.SLIDE || outputExpectsExpiredEvents) {
        trackFutureStates = true;
    }
    returnType = attributeExpressionExecutors[0].getReturnType();
    boolean finalTrackFutureStates = trackFutureStates;
    return () -> {
        switch (returnType) {
            case FLOAT:
                return new MaxAttributeAggregatorStateFloat(finalTrackFutureStates);
            case INT:
                return new MaxAttributeAggregatorStateInt(finalTrackFutureStates);
            case LONG:
                return new MaxAttributeAggregatorStateLong(finalTrackFutureStates);
            case DOUBLE:
                return new MaxAttributeAggregatorStateDouble(finalTrackFutureStates);
            default:
                throw new OperationNotSupportedException("Max not supported for " + returnType);
        }
    };
}
 
Example #19
Source File: UpdateOrInsertReducer.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public List<Object[]> reduceEventsForInsert(List<Object[]> failedRecords,
                                            Map<String, ExpressionExecutor> inMemorySetExecutors) {
    ComplexEventChunk<StreamEvent> toInsertEventChunk = new ComplexEventChunk<>();
    StateEvent joinEvent = stateEventFactory.newInstance();
    for (Object[] data : failedRecords) {
        StreamEvent failedEvent = streamEventFactory.newInstance();
        failedEvent.setOutputData(data);
        joinEvent.setEvent(streamEventIndex, failedEvent);
        boolean updated = false;
        toInsertEventChunk.reset();
        while (toInsertEventChunk.hasNext()) {
            StreamEvent toInsertEvent = toInsertEventChunk.next();
            joinEvent.setEvent(storeEventIndex, toInsertEvent);
            if ((Boolean) inMemoryCompiledCondition.execute(joinEvent)) {
                for (Map.Entry<String, ExpressionExecutor> entry :
                        inMemorySetExecutors.entrySet()) {
                    toInsertEvent.setOutputData(entry.getValue().execute(failedEvent),
                            attributeMap.get(entry.getKey()));
                }
                updated = true;
            }
        }
        if (!updated) {
            toInsertEventChunk.add(failedEvent);
        }
    }
    List<Object[]> toInsertRecords = new LinkedList<>();
    toInsertEventChunk.reset();
    while (toInsertEventChunk.hasNext()) {
        StreamEvent streamEvent = toInsertEventChunk.next();
        toInsertRecords.add(streamEvent.getOutputData());
    }
    return toInsertRecords;
}
 
Example #20
Source File: AbstractRecordTable.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public StreamEvent find(CompiledCondition compiledCondition, StateEvent matchingEvent)
        throws ConnectionUnavailableException {
    RecordStoreCompiledCondition recordStoreCompiledCondition =
            ((RecordStoreCompiledCondition) compiledCondition);

    Map<String, Object> findConditionParameterMap = new HashMap<>();
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap
            .entrySet()) {
        findConditionParameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }

    Iterator<Object[]> records;
    if (recordTableHandler != null) {
        records = recordTableHandler.find(matchingEvent.getTimestamp(), findConditionParameterMap,
                recordStoreCompiledCondition.compiledCondition);
    } else {
        records = find(findConditionParameterMap, recordStoreCompiledCondition.compiledCondition);
    }
    ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>();
    if (records != null) {
        while (records.hasNext()) {
            Object[] record = records.next();
            StreamEvent streamEvent = storeEventPool.newInstance();
            System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
            streamEventComplexEventChunk.add(streamEvent);
        }
    }
    return streamEventComplexEventChunk.getFirst();
}
 
Example #21
Source File: AbstractRecordTable.java    From siddhi with Apache License 2.0 5 votes vote down vote up
RecordStoreCompiledCondition(Map<String, ExpressionExecutor> variableExpressionExecutorMap,
                             CompiledCondition compiledCondition,
                             SiddhiQueryContext siddhiQueryContext) {
    this.variableExpressionExecutorMap = variableExpressionExecutorMap;
    this.compiledCondition = compiledCondition;
    this.siddhiQueryContext = siddhiQueryContext;
}
 
Example #22
Source File: AggregateWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            StreamEventClonerHolder streamEventClonerHolder, boolean outputExpectsExpiredEvents,
                            boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
    // nothing to be done
    return null;
}
 
Example #23
Source File: AttributeCollectWithDistinctAggregator.java    From eagle with Apache License 2.0 5 votes vote down vote up
/**
 * The initialization method for AttributeAggregatorExecutor
 *
 * @param attributeExpressionExecutors are the executors of each attributes in the function
 * @param processingMode               query processing mode
 * @param outputExpectsExpiredEvents   is expired events sent as output
 * @param configReader                 this hold the {@link AttributeCollectAggregator} configuration reader.
 * @param siddhiQueryContext           Siddhi query runtime context
 */
@Override
protected StateFactory<AggregatorState> init(ExpressionExecutor[] attributeExpressionExecutors,
                                             ProcessingMode processingMode,
                                             boolean outputExpectsExpiredEvents,
                                             ConfigReader configReader,
                                             SiddhiQueryContext siddhiQueryContext) {
    // TODO: Support max of elements?
    return AggregatorState::new;
}
 
Example #24
Source File: EventTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
    public void testConditionExpressionExecutors() {
//        StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
// .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);

        VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute
                ("price", Attribute.Type.FLOAT), 0, 0);
        priceVariableExpressionExecutor.setPosition(new int[]{0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants
                .OUTPUT_DATA_INDEX, 1});

        VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute
                ("volume", Attribute.Type.INT), 0, 0);
        volumeVariableExpressionExecutor.setPosition(new int[]{0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants
                .OUTPUT_DATA_INDEX, 2});

        ExpressionExecutor compareLessThanExecutor = new LessThanCompareConditionExpressionExecutorFloatFloat(new
                ConstantExpressionExecutor(10f, Attribute.Type.FLOAT), priceVariableExpressionExecutor);
        ExpressionExecutor compareGreaterThanExecutor = new GreaterThanCompareConditionExpressionExecutorIntInt(new
                ConstantExpressionExecutor(10, Attribute.Type.INT), volumeVariableExpressionExecutor);
        ExpressionExecutor andExecutor = new AndConditionExpressionExecutor(compareLessThanExecutor,
                compareGreaterThanExecutor);

        int count = 0;
        for (int i = 0; i < 3; i++) {
            StreamEvent event = new StreamEvent(0, 0, 3);
            event.setOutputData(new Object[]{"WSO2", i * 11f, 5});
            if ((Boolean) andExecutor.execute(event)) {
                count++;
            }
        }

        AssertJUnit.assertEquals("Two events should pass through executor", 2, count);
    }
 
Example #25
Source File: SortWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
        lengthToKeep = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor)
                attributeExpressionExecutors[0]).getValue()));
    } else {
        throw new UnsupportedOperationException("The first parameter should be an integer");
    }
    parameterInfo = new ArrayList<Object[]>();
    eventComparator = new EventComparator();
    for (int i = 1, parametersLength = attributeExpressionExecutors.length; i < parametersLength; i++) {
        if (!(attributeExpressionExecutors[i] instanceof VariableExpressionExecutor)) {
            throw new UnsupportedOperationException("Required a variable, but found a string parameter");
        } else {
            ExpressionExecutor variableExpressionExecutor = attributeExpressionExecutors[i];
            int order;
            String nextParameter;
            if (i + 1 < parametersLength && attributeExpressionExecutors[i + 1].getReturnType() == Attribute.Type
                    .STRING) {
                nextParameter = (String) ((ConstantExpressionExecutor) attributeExpressionExecutors[i + 1])
                        .getValue();
                if (nextParameter.equalsIgnoreCase(DESC)) {
                    order = -1;
                    i++;
                } else if (nextParameter.equalsIgnoreCase(ASC)) {
                    order = 1;
                    i++;
                } else {
                    throw new UnsupportedOperationException("Parameter string literals should only be \"asc\" or " +
                            "\"desc\"");
                }
            } else {
                order = 1; //assigning the default order: "asc"
            }
            parameterInfo.add(new Object[]{variableExpressionExecutor, order});
        }
    }
    return () -> new WindowState();
}
 
Example #26
Source File: EventChunkOperator.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk,
                                               Object storeEvents,
                                               InMemoryCompiledUpdateSet compiledUpdateSet,
                                               AddingStreamEventExtractor addingStreamEventExtractor) {
    ComplexEventChunk<StreamEvent> storeEventChunk = (ComplexEventChunk<StreamEvent>) storeEvents;
    updatingOrAddingEventChunk.reset();
    ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>
            ();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
        try {
            boolean updated = false;
            storeEventChunk.reset();
            while (storeEventChunk.hasNext()) {
                StreamEvent storeEvent = storeEventChunk.next();
                overwritingOrAddingEvent.setEvent(storeEventPosition, storeEvent);
                if ((Boolean) expressionExecutor.execute(overwritingOrAddingEvent)) {
                    for (Map.Entry<Integer, ExpressionExecutor> entry :
                            compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                        storeEvent.setOutputData(entry.getValue().
                                execute(overwritingOrAddingEvent), entry.getKey());
                    }
                    updated = true;
                }
            }
            if (!updated) {
                updatingOrAddingEventChunk.remove();
                failedEventChunk.add(overwritingOrAddingEvent);
            }
        } finally {
            overwritingOrAddingEvent.setEvent(storeEventPosition, null);
        }
    }
    return failedEventChunk;
}
 
Example #27
Source File: LengthBatchWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            StreamEventClonerHolder streamEventClonerHolder, boolean outputExpectsExpiredEvents,
                            boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    this.siddhiQueryContext = siddhiQueryContext;
    if (attributeExpressionExecutors.length >= 1) {
        if (!(attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor)) {
            throw new SiddhiAppValidationException("TimeBatch window's window.time (1st) parameter " +
                    "'window.length' should be a constant but found a dynamic parameter " +
                    attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
        length = (Integer) (((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue());
    }
    if (attributeExpressionExecutors.length == 2) {
        if (!(attributeExpressionExecutors[1] instanceof ConstantExpressionExecutor)) {
            throw new SiddhiAppValidationException("TimeBatch window's window.time (2nd) parameter " +
                    "'stream.current.event' should be a constant but found a dynamic parameter " +
                    attributeExpressionExecutors[1].getClass().getCanonicalName());
        }
        isStreamCurrentEvents = (Boolean) (((ConstantExpressionExecutor)
                attributeExpressionExecutors[1]).getValue());
    }
    if (attributeExpressionExecutors.length > 2) {
        throw new SiddhiAppValidationException("LengthBatch window should have one parameter (<int> " +
                "window.length) or two parameters (<int> window.length, <bool> stream.current.event), " +
                "but found " + attributeExpressionExecutors.length + " input parameters.");
    }
    return () -> new WindowState(streamEventClonerHolder, isStreamCurrentEvents,
            outputExpectsExpiredEvents, findToBeExecuted);
}
 
Example #28
Source File: ExternalTimeWindowProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory<WindowState> init(ExpressionExecutor[] attributeExpressionExecutors,
                                         ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length == 2) {
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
            timeToKeep = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor)
                    attributeExpressionExecutors[1]).getValue()));
        } else {
            timeToKeep = Long.parseLong(String.valueOf(((ConstantExpressionExecutor)
                    attributeExpressionExecutors[1]).getValue()));
        }
        if (!(attributeExpressionExecutors[0] instanceof VariableExpressionExecutor)) {
            throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timeStamp should be a" +
                    " type long stream attribute but found " + attributeExpressionExecutors[0].getClass());
        }
        timeStampVariableExpressionExecutor = ((VariableExpressionExecutor) attributeExpressionExecutors[0]);
        if (timeStampVariableExpressionExecutor.getReturnType() != Attribute.Type.LONG) {
            throw new SiddhiAppValidationException("ExternalTime window's 1st parameter timeStamp should be " +
                    "type long, but found " + timeStampVariableExpressionExecutor.getReturnType());
        }
    } else {
        throw new SiddhiAppValidationException("ExternalTime window should only have two parameter (<long> " +
                "timeStamp, <int|long|time> windowTime), but found " + attributeExpressionExecutors.length + " " +
                "input attributes");
    }
    return () -> new WindowState();
}
 
Example #29
Source File: FilterProcessor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public FilterProcessor(ExpressionExecutor conditionExecutor) {
    if (Attribute.Type.BOOL.equals(conditionExecutor.getReturnType())) {
        this.conditionExecutor = conditionExecutor;
    } else {
        throw new OperationNotSupportedException("Return type of " + conditionExecutor.toString() + " should be " +
                "of type BOOL. " +
                "Actual type: " + conditionExecutor.getReturnType().toString());
    }
}
 
Example #30
Source File: InstanceOfIntegerFunctionExecutor.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader,
                            SiddhiQueryContext siddhiQueryContext) {
    if (attributeExpressionExecutors.length != 1) {
        throw new SiddhiAppValidationException("Invalid no of arguments passed to instanceOfInteger() " +
                "function, required only 1, but found " + attributeExpressionExecutors.length);
    }
    return null;
}