use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class ErrorHandlerUtils method constructAddErrorRecordString.
public static String constructAddErrorRecordString(ComplexEventChunk<StreamEvent> eventChunk, boolean isObjectColumnPresent, TableDefinition tableDefinition, Exception e) {
JsonObject payloadJson = new JsonObject();
payloadJson.addProperty("isEditable", !(isObjectColumnPresent || e instanceof ConnectionUnavailableException));
JsonArray attributes = new JsonArray();
JsonArray records = new JsonArray();
for (Attribute attribute : tableDefinition.getAttributeList()) {
JsonObject attributeJson = new JsonObject();
attributeJson.add("name", new JsonPrimitive(attribute.getName()));
attributeJson.add("type", new JsonPrimitive(String.valueOf(attribute.getType())));
attributes.add(attributeJson);
}
payloadJson.add("attributes", attributes);
while (eventChunk.hasNext()) {
StreamEvent streamEvent = eventChunk.next();
JsonArray record = new JsonArray();
for (Object item : streamEvent.getOutputData()) {
if (item == null) {
record.add(JsonNull.INSTANCE);
} else {
record.add(String.valueOf(item));
}
}
records.add(record);
}
payloadJson.add("records", records);
return payloadJson.toString();
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class TestStoreContainingInMemoryTable method update.
@Override
protected void update(CompiledCondition updateCondition, List<Map<String, Object>> updateConditionParameterMaps, Map<String, CompiledExpression> updateSetExpressions, List<Map<String, Object>> updateSetParameterMaps) throws ConnectionUnavailableException {
MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
TableDefinition matchingTableDefinition = TableDefinition.id("");
for (Attribute attribute : inMemoryTable.getTableDefinition().getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
}
tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, inMemoryTable.getTableDefinition(), 0);
UpdateSet updateSet = new UpdateSet();
for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
}
CompiledUpdateSet compiledUpdateSet = inMemoryTable.compileUpdateSet(updateSet, matchingMetaInfoHolder, null, tableMap, null);
inMemoryTable.update(convForUpdate(updateSetParameterMaps), updateCondition, compiledUpdateSet);
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class TestStoreContainingInMemoryTable method updateOrAdd.
@Override
protected void updateOrAdd(CompiledCondition updateCondition, List<Map<String, Object>> updateConditionParameterMaps, Map<String, CompiledExpression> updateSetExpressions, List<Map<String, Object>> updateSetParameterMaps, List<Object[]> addingRecords) throws ConnectionUnavailableException {
MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
TableDefinition matchingTableDefinition = TableDefinition.id("");
for (Attribute attribute : inMemoryTable.getTableDefinition().getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
}
tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, inMemoryTable.getTableDefinition(), 0);
UpdateSet updateSet = new UpdateSet();
for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
}
CompiledUpdateSet compiledUpdateSet = inMemoryTable.compileUpdateSet(updateSet, matchingMetaInfoHolder, null, tableMap, null);
inMemoryTable.updateOrAdd(convForUpdate(updateSetParameterMaps), updateCondition, compiledUpdateSet, new AddingStreamEventExtractor(matchingMetaInfoHolder.getMatchingStreamEventIndex()));
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class TestStoreContainingInMemoryTable method compileSelection.
@Override
protected CompiledSelection compileSelection(List<SelectAttributeBuilder> selectAttributeBuilders, List<ExpressionBuilder> groupByExpressionBuilder, ExpressionBuilder havingExpressionBuilder, List<OrderByAttributeBuilder> orderByAttributeBuilders, Long limit, Long offset) {
selectAttributeBuilders.forEach((selectAttributeBuilder -> {
TestStoreConditionVisitor testStoreConditionVisitor = new TestStoreConditionVisitor("");
selectAttributeBuilder.getExpressionBuilder().build(testStoreConditionVisitor);
if (testStoreConditionVisitor.getStreamVarCount() > 0) {
throw new SiddhiAppCreationException("testStoreContainingInMemoryTable does not support " + "lookup with stream variables");
}
}));
CompiledSelectionWithCache compiledSelectionWithCache;
MetaStateEvent metaStateEvent = matchingMetaInfoHolderForTestOnDemandQuery.getMetaStateEvent().clone();
ReturnStream returnStream = new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS);
int metaPosition = SiddhiConstants.UNKNOWN_STATE;
List<VariableExpressionExecutor> variableExpressionExecutorsForQuerySelector = new ArrayList<>();
if (metaStateEvent.getOutputDataAttributes().size() == 0) {
// MetaStateEvent metaStateEventWithOutputData = new MetaStateEvent(metaStateEvent.getStreamEventCount());
for (Attribute outputAttribute : metaStateEvent.getMetaStreamEvents()[0].getOnAfterWindowData()) {
metaStateEvent.getMetaStreamEvents()[0].addOutputData(outputAttribute);
}
}
if (metaStateEvent.getOutputDataAttributes().size() > 0) {
while (metaStateEvent.getMetaStreamEvent(0).getOutputData().size() > 0) {
metaStateEvent.getMetaStreamEvent(0).getOutputData().remove(0);
}
}
QuerySelector querySelector = SelectorParser.parse(selectorForTestOnDemandQuery, returnStream, metaStateEvent, tableMap, variableExpressionExecutorsForQuerySelector, metaPosition, ProcessingMode.BATCH, false, siddhiQueryContextForTestOnDemandQuery);
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutorsForQuerySelector);
querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(metaStateEvent));
compiledSelectionWithCache = new CompiledSelectionWithCache(null, querySelector, metaStateEvent, 0, null);
return compiledSelectionWithCache;
}
use of io.siddhi.query.api.definition.Attribute in project siddhi by wso2.
the class TestStoreForCacheMiss method convForDelete.
private ComplexEventChunk<StreamEvent> convForDelete(List<Map<String, Object>> deleteConditionParameterMaps) {
List<Object[]> objectList = new LinkedList<>();
for (Map<String, Object> parameterMap : deleteConditionParameterMaps) {
List<Object> outputData = new ArrayList<>();
List<Attribute> attributeList = inMemoryTable.getTableDefinition().getAttributeList();
for (int i = 0; i < attributeList.size(); i++) {
if (parameterMap.get(attributeList.get(i).getName()) != null) {
outputData.add(parameterMap.get(attributeList.get(i).getName()));
} else {
outputData.add(null);
}
}
objectList.add(outputData.toArray());
}
ComplexEventChunk<StreamEvent> complexEventChunk = new ComplexEventChunk<>();
for (Object[] record : objectList) {
StreamEvent event = new StreamEvent(0, 0, record.length);
// StateEvent stateEvent = new StateEvent(2, record.length);
event.setOutputData(record);
// stateEvent.addEvent(0, event);
complexEventChunk.add(event);
}
return complexEventChunk;
}
Aggregations