# Industry 4.0 towards Forestry 4.0: Fire Detection Use Case +
## 5 Methodology
### Dynamic Query Window-Based Selector for Stream Rate Change
#### 5.3.2 The Proposed Dynamic Window-Based Selector  
The dynamic window-based selector is proposed to dynamically select the proper window configuration for a stream query based on the change of stream rates concerning the relation of stream attributes, workload requirements, and infrastructure specification. A typical scenario of running stream query could be deploying the input query with an initial window configuration. The stream query engine is initially configured the querying window concerning the identified inputs including stream attributes, workload requirements, and resources capacity. Then, the behaviour of stream rates is monitored, which leads to a new deployment of window-based query configuration. The proposed prototype contains three phases, including (1) input identification, (2) window selection and (3) query deployment. Each phase can be described as follows (see Figure 12). **Inputs identification phase**  
The relevant inputs are identified in this phase, including the stream attributes, the query workload requirements, and the infrastructure specifications. The stream attributes represent the stream's schema (i.e., stream structure) and the historical stream statistics (i.e., historical data collected during the stream ingestion in the past). The stream structure could be drifted when the data schema changes at the source, such as adding, deleting, and modifying the type of fields. We opted the stream structure as a fixed schema to keep the problem of stream rate change tractable regarding our work. Three workload requirements are considered; latency, accuracy and data enrichment. The latency maintains when an event is observed and when the results corresponding to that event are generated. So, the latency depends on window size, which means that the small window size leads to low latency materialized output. In contrast, the large window size has long latency due to late output materialization. The data accuracy refers to the data quality (i.e., data values are correctly stored). According to this work's scope, the inconsistencies of data can be caused by the stream rate change. Due to the granularity of the stream rate, the data could arrive out-of-order, affecting the data processing and the accuracy of the output. Consequently, a correct stream query window configuration can adapt with stream change to keep the output stream accurate over various stream rates. Intuitively, the generated output stream rate increases monotonically with the increase in the input stream rates. Thus, the output stream rate should be enriched in case of a high input stream rate. As reported by the study in subsection 5.2.3 [5], not all query window configurations over high stream rates lead to enriching resulted stream. Therefore, picking the proper query window configuration to meet the data enrichment requirement is very important, and it should be considered whenever a stream query is deployed. Figure 12: The prototype of a dynamic window-based selector for stream query running over fluctuated stream rate consisting of three phases: (1) input identification; (2) window selection processing and (3) query deployment. Declaring the infrastructure specifications (i.e., CPU, memory and network bandwidth) is essential for decision-making processes in query stream processing. A prior knowledge of the available resources can help the query stream engine select the appropriate query configurations and avoid resource limitation problems in the case of unpredictable stream rates. **Window selection phase**  
The window selection phase contains three components i.e., stream monitor, knowledgebase and dynamic window configuration algorithm. Stream monitor includes monitoring systems to observe different input stream characteristics, including its rate, schema and other relevant information. The stream monitor builds statistics on the go for live stream jobs being executed by the query engine.