use of org.wso2.siddhi.core.executor.ExpressionExecutor 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.core.executor.ExpressionExecutor in project siddhi by wso2.
the class InMemoryTable method compileUpdateSet.
@Override
public CompiledUpdateSet compileUpdateSet(UpdateSet updateSet, MatchingMetaInfoHolder matchingMetaInfoHolder, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) {
Map<Integer, ExpressionExecutor> expressionExecutorMap = new HashMap<>();
for (UpdateSet.SetAttribute setAttribute : updateSet.getSetAttributeList()) {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(setAttribute.getAssignmentExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
int attributePosition = tableDefinition.getAttributePosition(setAttribute.getTableVariable().getAttributeName());
expressionExecutorMap.put(attributePosition, expressionExecutor);
}
return new InMemoryCompiledUpdateSet(expressionExecutorMap);
}
use of org.wso2.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.
the class AbstractQueryableRecordTable method query.
@Override
public StreamEvent query(StateEvent matchingEvent, CompiledCondition compiledCondition, CompiledSelection compiledSelection) throws ConnectionUnavailableException {
RecordStoreCompiledSelection recordStoreCompiledSelection = ((RecordStoreCompiledSelection) compiledSelection);
RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
Map<String, Object> parameterMap = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
}
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledSelection.variableExpressionExecutorMap.entrySet()) {
parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
}
Iterator<Object[]> records;
if (recordTableHandler != null) {
records = recordTableHandler.query(matchingEvent.getTimestamp(), parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
} else {
records = query(parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
}
ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>(true);
if (records != null) {
while (records.hasNext()) {
Object[] record = records.next();
StreamEvent streamEvent = storeEventPool.borrowEvent();
System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
streamEventComplexEventChunk.add(streamEvent);
}
}
return streamEventComplexEventChunk.getFirst();
}
use of org.wso2.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.
the class AbstractRecordTable method compileUpdateSet.
public CompiledUpdateSet compileUpdateSet(UpdateSet updateSet, MatchingMetaInfoHolder matchingMetaInfoHolder, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) {
RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = new RecordTableCompiledUpdateSet();
Map<String, ExpressionExecutor> parentExecutorMap = new HashMap<>();
for (UpdateSet.SetAttribute setAttribute : updateSet.getSetAttributeList()) {
ExpressionBuilder expressionBuilder = new ExpressionBuilder(setAttribute.getAssignmentExpression(), matchingMetaInfoHolder, siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
CompiledExpression compiledExpression = compileSetAttribute(expressionBuilder);
recordTableCompiledUpdateSet.put(setAttribute.getTableVariable().getAttributeName(), compiledExpression);
Map<String, ExpressionExecutor> expressionExecutorMap = expressionBuilder.getVariableExpressionExecutorMap();
parentExecutorMap.putAll(expressionExecutorMap);
}
recordTableCompiledUpdateSet.setExpressionExecutorMap(parentExecutorMap);
return recordTableCompiledUpdateSet;
}
use of org.wso2.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.
the class AbstractRecordTable method update.
@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet) throws ConnectionUnavailableException {
RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
updatingEventChunk.reset();
long timestamp = 0L;
while (updatingEventChunk.hasNext()) {
StateEvent stateEvent = updatingEventChunk.next();
Map<String, Object> variableMap = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
}
updateConditionParameterMaps.add(variableMap);
Map<String, Object> variableMapForUpdateSet = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordTableCompiledUpdateSet.getExpressionExecutorMap().entrySet()) {
variableMapForUpdateSet.put(entry.getKey(), entry.getValue().execute(stateEvent));
}
updateSetParameterMaps.add(variableMapForUpdateSet);
timestamp = stateEvent.getTimestamp();
}
if (recordTableHandler != null) {
recordTableHandler.update(timestamp, recordStoreCompiledCondition.compiledCondition, updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps);
} else {
update(recordStoreCompiledCondition.compiledCondition, updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps);
}
}
Aggregations