private void checkDuplicateDefinition(AbstractDefinition definition) { TableDefinition existingTableDefinition = tableDefinitionMap.get(definition.getId()); if (existingTableDefinition != null && (!existingTableDefinition.equals(definition) || definition instanceof StreamDefinition)) { throw new DuplicateDefinitionException("Table Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingTableDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex()); StreamDefinition existingStreamDefinition = streamDefinitionMap.get(definition.getId()); if (existingStreamDefinition != null && (!existingStreamDefinition.equals(definition) || definition instanceof TableDefinition)) { throw new DuplicateDefinitionException("Stream Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingStreamDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex()); WindowDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId()); if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) { throw new DuplicateDefinitionException("Stream Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex()); AggregationDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId()); if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) { throw new DuplicateDefinitionException("Aggregate Definition with same Aggregate Id '" + definition.getId() + "' already exist : " + existingAggregationDefinition + ", hence cannot add " + definition,
/** * Construct Stream Definition query string for a given Siddhi Stream Definition * * @param siddhiStreamDefinition * @return */ public static String getDefinitionString(org.wso2.siddhi.query.api.definition.AbstractDefinition siddhiStreamDefinition) { StringBuilder builder = new StringBuilder(); builder.append(EventProcessorConstants.DEFINE_STREAM); builder.append(siddhiStreamDefinition.getId()); builder.append(EventProcessorConstants.OPENING_BRACKETS); for (Attribute attribute : siddhiStreamDefinition.getAttributeList()) { builder.append(attribute.getName() + EventProcessorConstants.SPACE + attribute.getType().toString().toLowerCase() + EventProcessorConstants.COMMA); } builder.deleteCharAt(builder.length() - 2); //remove last comma builder.append(EventProcessorConstants.CLOSING_BRACKETS); return builder.toString(); }
private void initMetaStateEvent() { this.outputAttrs = matchingMetaStateHolder.getMatchingStreamDefinition().getAttributeList(); for (MetaStreamEvent metaStreamEvent : matchingMetaStateHolder.getMetaStateEvent().getMetaStreamEvents()) { String referenceId = metaStreamEvent.getInputReferenceId(); AbstractDefinition abstractDefinition = metaStreamEvent.getLastInputDefinition(); if (!abstractDefinition.getId().trim().equals("")) { if (abstractDefinition instanceof TableDefinition) { this.eventTableRefs.add(abstractDefinition.getId()); if (referenceId != null) { this.eventTableRefs.add(referenceId); } } } } if (tableDefinition instanceof TableDefinition) { this.eventTableRefs.add(tableDefinition.getId()); } }
private void checkDuplicateDefinition(AbstractDefinition definition) { TableDefinition existingTableDefinition = tableDefinitionMap.get(definition.getId()); if (existingTableDefinition != null && (!existingTableDefinition.equals(definition) || definition instanceof StreamDefinition)) { throw new DuplicateDefinitionException("Table Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingTableDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex()); StreamDefinition existingStreamDefinition = streamDefinitionMap.get(definition.getId()); if (existingStreamDefinition != null && (!existingStreamDefinition.equals(definition) || definition instanceof TableDefinition)) { throw new DuplicateDefinitionException("Stream Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingStreamDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex()); WindowDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId()); if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) { throw new DuplicateDefinitionException("Stream Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex()); AggregationDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId()); if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) { throw new DuplicateDefinitionException("Aggregate Definition with same Aggregate Id '" + definition.getId() + "' already exist : " + existingAggregationDefinition + ", hence cannot add " + definition,
public List<StreamDefinition> getSiddhiStreams(String executionPlan) { SiddhiManager siddhiManager = EventProcessorValueHolder.getSiddhiManager(); EventProcessorHelper.loadDataSourceConfiguration(siddhiManager); ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(executionPlan); Collection<AbstractDefinition> streamDefinitions = executionPlanRuntime.getStreamDefinitionMap().values(); List<StreamDefinition> databridgeStreamDefinitions = new ArrayList<StreamDefinition>(streamDefinitions.size()); for (AbstractDefinition siddhiStreamDef : streamDefinitions) { StreamConfiguration streamConfig = new StreamConfiguration(siddhiStreamDef.getId()); StreamDefinition databridgeStreamDef = EventProcessorUtil.convertToDatabridgeStreamDefinition( (org.wso2.siddhi.query.api.definition.StreamDefinition) siddhiStreamDef, streamConfig); databridgeStreamDefinitions.add(databridgeStreamDef); } executionPlanRuntime.shutdown(); return databridgeStreamDefinitions; }
streamMapId.add(ab.getId()); attributeList.add(ab.getAttributeList());
public static StreamDefinition convertFromSiddiDefinition(AbstractDefinition siddhiDefinition) { StreamDefinition streamDefinition = new StreamDefinition(); streamDefinition.setStreamId(siddhiDefinition.getId()); List<StreamColumn> columns = new ArrayList<>(siddhiDefinition.getAttributeNameArray().length); for (Attribute attribute : siddhiDefinition.getAttributeList()) { StreamColumn column = new StreamColumn(); column.setType(convertFromSiddhiAttributeType(attribute.getType())); column.setName(attribute.getName()); columns.add(column); } streamDefinition.setColumns(columns); streamDefinition.setTimeseries(true); streamDefinition.setDescription("Auto-generated stream schema from siddhi for " + siddhiDefinition.getId()); return streamDefinition; } }
private static boolean isTableIndexVariable(MatchingMetaStateHolder matchingMetaStateHolder, Expression expression, String indexAttribute) { if (expression instanceof Variable) { Variable variable = (Variable) expression; if (variable.getStreamId() != null) { MetaStreamEvent tableStreamEvent = matchingMetaStateHolder.getMetaStateEvent().getMetaStreamEvent(matchingMetaStateHolder.getCandidateEventIndex()); if (tableStreamEvent != null) { if ((tableStreamEvent.getInputReferenceId() != null && variable.getStreamId().equals(tableStreamEvent.getInputReferenceId())) || (tableStreamEvent.getLastInputDefinition().getId().equals(variable.getStreamId()))) { if (Arrays.asList(tableStreamEvent.getLastInputDefinition().getAttributeNameArray()).contains(indexAttribute)) { return true; } } } else { if (matchingMetaStateHolder.getCandsidateDefinition().getId().equals(variable.getStreamId())) { return true; } } } } return false; }
String referenceId = metaStreamEvent.getInputReferenceId(); AbstractDefinition abstractDefinition = metaStreamEvent.getLastInputDefinition(); if (!abstractDefinition.getId().trim().equals("")) { if (abstractDefinition instanceof TableDefinition) { isTableStreamMap.put(abstractDefinition.getId(), true); if (referenceId != null) { isTableStreamMap.put(referenceId, true); isTableStreamMap.put(abstractDefinition.getId(), false); if (referenceId != null) { isTableStreamMap.put(referenceId, false);