public String getStreamDefinitionExpression(StreamDefinition streamDefinition) { List<String> columns = new ArrayList<>(); Preconditions.checkNotNull(streamDefinition, "StreamDefinition is null"); for (Attribute attribute : streamDefinition.getAttributeList()) { columns.add(String.format("%s %s", attribute.getName(), attribute.getType().toString().toLowerCase())); } return String.format(DEFINE_STREAM_TEMPLATE, streamDefinition.getId(), StringUtils.join(columns, ",")); }
public SiddhiApp defineTrigger(TriggerDefinition triggerDefinition) { if (triggerDefinition == null) { throw new SiddhiAppValidationException("Trigger Definition should not be null"); } else if (triggerDefinition.getId() == null) { throw new SiddhiAppValidationException("Trigger Id should not be null for Trigger Definition", triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex()); } StreamDefinition streamDefinition = StreamDefinition.id(triggerDefinition.getId()).attribute(SiddhiConstants .TRIGGERED_TIME, Attribute.Type.LONG); streamDefinition.setQueryContextStartIndex(triggerDefinition.getQueryContextStartIndex()); streamDefinition.setQueryContextEndIndex(triggerDefinition.getQueryContextEndIndex()); try { checkDuplicateDefinition(streamDefinition); } catch (DuplicateDefinitionException e) { throw new DuplicateDefinitionException("Trigger '" + triggerDefinition.getId() + "' cannot be defined as," + " " + e.getMessageWithOutContext(), e, triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex()); } if (triggerDefinitionMap.containsKey(triggerDefinition.getId())) { throw new DuplicateDefinitionException("Trigger Definition with same Id '" + triggerDefinition.getId() + "' already exist '" + triggerDefinitionMap.get( triggerDefinition.getId()) + "', hence cannot add '" + triggerDefinition + "'", triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex()); } this.triggerDefinitionMap.put(triggerDefinition.getId(), triggerDefinition); this.streamDefinitionMap.put(streamDefinition.getId(), streamDefinition); return this; }
@Override public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) { // Declaring all incoming streams as output streams because this spouts role is to pass through all the incoming events as tuples. for (StreamDefinition siddhiStreamDefinition : incomingStreamDefinitions) { List<String> attributeList = new ArrayList<>(Arrays.asList(siddhiStreamDefinition.getAttributeNameArray())); attributeList.add(0, "_timestamp"); Fields fields = new Fields(attributeList); outputFieldsDeclarer.declareStream(siddhiStreamDefinition.getId(), fields); incomingStreamIDs.add(siddhiStreamDefinition.getId()); log.info(logPrefix + "Declaring output fields for stream : " + siddhiStreamDefinition.getId()); } }
public SiddhiApp defineStream(StreamDefinition streamDefinition) { if (streamDefinition == null) { throw new SiddhiAppValidationException("Stream Definition should not be null"); } else if (streamDefinition.getId() == null) { throw new SiddhiAppValidationException("Stream Id should not be null for Stream Definition", streamDefinition.getQueryContextStartIndex(), streamDefinition.getQueryContextEndIndex()); } checkDuplicateDefinition(streamDefinition); this.streamDefinitionMap.put(streamDefinition.getId(), streamDefinition); return this; }
public void registerOutputStreamListener(StreamDefinition siddhiStreamDefinition, SiddhiOutputStreamListener outputStreamListener) { log.info(logPrefix + "Registering output stream listener for Siddhi stream : " + siddhiStreamDefinition.getId()); streamNameToOutputStreamListenerMap.put(siddhiStreamDefinition.getId(), outputStreamListener); tcpEventServer.addStreamDefinition(siddhiStreamDefinition); }
public static boolean columnAlreadyExistsInStream(String columnName, StreamDefinition streamMetaData) { for (Attribute column : streamMetaData.getAttributeList()) { if (column.getName().equalsIgnoreCase(columnName)) { return true; } } return false; }
List<AttributeMapping> attributeMappingList, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.streamID = streamDefinition.getId(); this.attributeMappingList = attributeMappingList; this.attributeConverter = new AttributeConverter(); this.streamDefinition = streamDefinition; this.attributeList = streamDefinition.getAttributeList(); this.attributeTypeMap = new HashMap<>(attributeList.size()); this.attributePositionMap = new HashMap<>(attributeList.size()); for (Attribute attribute : attributeList) { attributeTypeMap.put(attribute.getName(), attribute.getType()); attributePositionMap.put(attribute.getName(), streamDefinition.getAttributePosition(attribute.getName())); for (Element el : streamDefinition.getAnnotations().get(0).getAnnotations().get(0).getElements()) { if (el.getKey().contains(REGULAR_EXPRESSION_GROUP)) { regexGroupMap.put(el.getKey() if (streamDefinition.getAttributeList().size() < attributeMappingList.size()) { throw new SiddhiAppValidationException("Stream: '" + streamDefinition.getId() + "' has " + streamDefinition.getAttributeList().size() + " attributes, but " + attributeMappingList.size() + " attribute mappings found. Each attribute should have one and only one mapping" + " in " + "the stream " + streamID + " of siddhi text input mapper.");
/** * Generates StreamConfig object, with given Siddhi StreamDefinition * * @param streamDefinition Siddhi StreamDefinition object * @return StreamConfig object */ public StreamConfig generateStreamConfig(StreamDefinition streamDefinition) { List<String> annotationConfigs = new ArrayList<>(); List<Annotation> annotationListObjects = new ArrayList<>(); List<String> streamElementAnnotationNames = new ArrayList<>(Arrays.asList("SOURCE", "SINK", "STORE")); AnnotationConfigGenerator annotationConfigGenerator = new AnnotationConfigGenerator(); for (Annotation annotation : streamDefinition.getAnnotations()) { if (!streamElementAnnotationNames.contains(annotation.getName().toUpperCase())) { // Since these annotations represent the stream itself annotationListObjects.add(annotation); annotationConfigs.add(annotationConfigGenerator.generateAnnotationConfig(annotation)); } } AttributeConfigListGenerator attributeConfigListGenerator = new AttributeConfigListGenerator(); StreamConfig streamConfig = new StreamConfig(streamDefinition.getId(), streamDefinition.getId(), attributeConfigListGenerator.generateAttributeConfigList(streamDefinition.getAttributeList()), annotationConfigs, annotationListObjects); preserveCodeSegmentsOf(annotationConfigGenerator, attributeConfigListGenerator); preserveAndBindCodeSegment(streamDefinition, streamConfig); return streamConfig; } }
this.streamDefinition = streamDefinition; this.attributeMappingList = attributeMappingList; attributeList = streamDefinition.getAttributeList(); attributeTypeMap = new HashMap<>(attributeList.size()); attributePositionMap = new HashMap<>(attributeList.size()); for (Attribute attribute : attributeList) { attributeTypeMap.put(attribute.getName(), attribute.getType()); attributePositionMap.put(attribute.getName(), streamDefinition.getAttributePosition(attribute.getName())); if (streamDefinition.getAttributeList().size() < attributeMappingList.size()) { throw new SiddhiAppValidationException("Stream: '" + streamDefinition.getId() + "' has " + streamDefinition.getAttributeList().size() + " attributes, but " + attributeMappingList.size() + " attribute mappings found. Each attribute should have one and only one mapping.");
String streamId = null; if (sourceOrSink instanceof Source) { streamId = ((Source) sourceOrSink).getStreamDefinition().getId(); streamDefinitionAnnotations = ((Source) sourceOrSink).getStreamDefinition().getAnnotations(); } else if (sourceOrSink instanceof Sink) { streamId = ((Sink) sourceOrSink).getStreamDefinition().getId(); streamDefinitionAnnotations = ((Sink) sourceOrSink).getStreamDefinition().getAnnotations();
String siddhiAttributeName; int attributeCount = 0; int siddhiStreamAttributeCount = siddhiStreamDefinition.getAttributeList().size(); int streamSize = (streamDefinition.getMetaData() == null ? 0 : streamDefinition.getMetaData().size()) + (streamDefinition.getCorrelationData() == null ? 0 : streamDefinition.getCorrelationData().size()) + (streamDefinition.getPayloadData() == null ? 0 : streamDefinition.getPayloadData().size()); Element ArbitraryElement = AnnotationHelper.getAnnotationElement(EventProcessorConstants.ANNOTATION_IMPORT, EventProcessorConstants.ANNOTATION_INCLUDE_ARBITRARY, siddhiStreamDefinition.getAnnotations()); if (ArbitraryElement == null) { ArbitraryElement = AnnotationHelper.getAnnotationElement(EventProcessorConstants.ANNOTATION_EXPORT, EventProcessorConstants.ANNOTATION_INCLUDE_ARBITRARY, siddhiStreamDefinition.getAnnotations()); if (!siddhiStreamDefinition.getAttributeList().get(siddhiStreamAttributeCount - 1).getName() .equals(EventProcessorConstants.ARBITRARY_MAP)) { for (Attribute attribute : streamDefinition.getMetaData()) { siddhiAttributeName = EventProcessorConstants.META_PREFIX + attribute.getName(); org.wso2.siddhi.query.api.definition.Attribute.Type type = siddhiStreamDefinition.getAttributeType( siddhiAttributeName); if (siddhiStreamDefinition.getAttributePosition(siddhiAttributeName) != attributeCount++) { throw new ExecutionPlanDependencyValidationException(streamName + EventProcessorConstants.STREAM_SEPARATOR + streamVersion, "Stream " + streamName + for (Attribute attribute : streamDefinition.getCorrelationData()) { siddhiAttributeName = EventProcessorConstants.CORRELATION_PREFIX + attribute.getName(); org.wso2.siddhi.query.api.definition.Attribute.Type type = siddhiStreamDefinition.getAttributeType( siddhiAttributeName);
if (payloadTemplateBuilderMap != null && isValidateEntry.get()) { for (int i = 0; i < headerOfData.length; i++) { dataOfEvent[i] = event.getData(streamDefinition.getAttributePosition( headerOfData[i].toString())); log.error( "[ERROR] Fail to print the data in csv format from Siddhi event in the stream '" + streamDefinition.getId() + "' of siddhi CSV output mapper.", e);
public static Object[] getOrderedValues(StreamDefinition streamMetaData, List<ColumnNameTypeValue> columns) throws AttributeNotExistException { Object[] orderedValues = new Object[streamMetaData.getAttributeList().size()]; for (ColumnNameTypeValue column : columns) { // if attribute does not exist, a AttributeNotExistException // exception will be thrown // XXX change this. create a conversor engine to treat data types. if (column.getValue() instanceof String) { orderedValues[streamMetaData.getAttributePosition(column.getColumn())] = decodeSiddhiValue( (String) column.getValue(), streamMetaData.getAttributeType(column.getColumn())); } else if (column.getValue() instanceof Double) { orderedValues[streamMetaData.getAttributePosition(column.getColumn())] = decodeSiddhiValue( (Double) column.getValue(), streamMetaData.getAttributeType(column.getColumn())); } else { orderedValues[streamMetaData.getAttributePosition(column.getColumn())] = column.getValue(); } } return orderedValues; }
@Override public void init(StreamDefinition streamDefinition, OptionHolder optionHolder, List<AttributeMapping> attributeMappingList, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.streamDefinition = streamDefinition; this.streamAttributes = this.streamDefinition.getAttributeList(); this.streamAttributesSize = this.streamDefinition.getAttributeList().size(); this.failOnMissingAttribute = Boolean.parseBoolean(optionHolder. validateAndGetStaticValue(FAIL_ON_MISSING_ATTRIBUTE_IDENTIFIER, "true")); this.factory = new JsonFactory(); if (attributeMappingList != null && attributeMappingList.size() > 0) { this.mappingPositions = new MappingPositionData[attributeMappingList.size()]; isCustomMappingEnabled = true; enclosingElement = optionHolder.validateAndGetStaticValue(ENCLOSING_ELEMENT_IDENTIFIER, DEFAULT_ENCLOSING_ELEMENT); for (int i = 0; i < attributeMappingList.size(); i++) { AttributeMapping attributeMapping = attributeMappingList.get(i); String attributeName = attributeMapping.getName(); int position = this.streamDefinition.getAttributePosition(attributeName); this.mappingPositions[i] = new MappingPositionData(position, attributeMapping.getMapping()); } } else { this.mappingPositions = new MappingPositionData[streamAttributesSize]; for (int i = 0; i < streamAttributesSize; i++) { this.mappingPositions[i] = new MappingPositionData(i, DEFAULT_JSON_MAPPING_PREFIX + this .streamDefinition.getAttributeList().get(i).getName()); } } }
public String addQuery(String streamName, String queryString) { String queryId = siddhiManager.addQuery(queryString); streamStatusDao.addQuery(streamName, queryId, queryString); for (StreamDefinition streamDefinition : siddhiManager.getStreamDefinitions()) { // XXX refactor to obtain exactly siddhi inferred streams. streamStatusDao.createInferredStream(streamDefinition.getStreamId(), castToColumnNameTypeValue(streamDefinition.getAttributeList())); } return queryId; }
protected void init(StreamDefinition streamDefinition, OptionHolder optionHolder, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.siddhiAppContext = siddhiAppContext; uriOption = optionHolder.validateAndGetOption(Constants.FILE_URI); String append = optionHolder.validateAndGetStaticValue(Constants.APPEND, Constants.TRUE); properties = new HashMap<>(); properties.put(Constants.ACTION, Constants.WRITE); if (Constants.TRUE.equalsIgnoreCase(append)) { properties.put(Constants.APPEND, append); } String mapType = streamDefinition.getAnnotations().get(0).getAnnotations().get(0).getElements().get(0) .getValue(); addEventSeparator = optionHolder.isOptionExists(Constants.ADD_EVENT_SEPARATOR) ? Boolean.parseBoolean(optionHolder.validateAndGetStaticValue(Constants.ADD_EVENT_SEPARATOR)) : !mapType.equalsIgnoreCase("csv"); }
public void createStream(String streamName, List<ColumnNameTypeValue> columns) { StreamDefinition newStream = QueryFactory.createStreamDefinition().name(streamName); if (columns!=null) { for (ColumnNameTypeValue column : columns) { newStream.attribute(column.getColumn(), getSiddhiType(column.getType())); } } siddhiManager.defineStream(newStream); streamStatusDao.create(streamName, columns); }
public StreamDefinition getStreamDefinition(String streamId) { StreamDefinition streamDefinition = StreamDefinition.id(streamId); for (int i = 0; i < getFieldNames().length; i++) { streamDefinition.attribute(getFieldNames()[i], SiddhiTypeFactory.getAttributeType(getFieldTypes()[i])); } return streamDefinition; }
StreamDefinition streamDefinition = StreamDefinition.id(source.streamId); populateQueryContext(streamDefinition, ctx); List<SiddhiQLParser.Attribute_nameContext> attribute_names = ctx.attribute_name(); SiddhiQLParser.Attribute_nameContext attributeNameContext = attribute_names.get(i); SiddhiQLParser.Attribute_typeContext attributeTypeContext = attribute_types.get(i); streamDefinition.attribute((String) visit(attributeNameContext), (Attribute.Type) visit (attributeTypeContext)); streamDefinition.annotation((Annotation) visit(annotationContext));
@Override public void init(StreamDefinition streamDefinition, OptionHolder optionHolder, Map<String, TemplateBuilder> templateBuilder, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { attributeNameArray = streamDefinition.getAttributeNameArray(); }