# Query Rewriting for Incremental Continuous Query Evaluation in HIFUN
## 3 Preliminaries--The HIFUN Query Language  
In this section, we describe briefly the conceptual model of the HIFUN language. For further details on the HIFUN language, the interested reader is referred to some relevant papers [30; 31].  
The basic notion used in defining HIFUN is that of an \(attribute\) of a dataset. In HIFUN, each attribute is seen as a function of the dataset for some domain of values. For example, if the dataset \(D\) is a set of tweets, then the attribute \"character count\" (denoted as \(cc\)) is seen as a function \(cc:D\to Count\), such that, for each tweet \(t\), \(cc(t)\) is the number of characters in \(t\).  
Next we provide an example that we will use throughout the paper. Consider a distribution center (e.g., Walmart) which delivers products of various types in a number of branches, and suppose that \(D\) is the set of all delivery invoices collected over a year. Each delivery invoice has an identifier (e.g., an integer) and shows the date of delivery, the branch in which the delivery took place, the type of product delivered (e.g., CocLight) and the quantity (i.e., the number of units delivered of that type of product). There is a separate invoice for each type of product delivered; and the data on all invoices during the year are stored in a data warehouse for analysis purposes. The information provided by each invoice would most likely be represented as a record with the following fields: invoice number, date, branch, product and quantity. In the HIFUN approach, this information is seen as a set of four functions, namely, \(d\), \(b\), \(p\) and \(q\), as shown in Figure 1, where \(D\) stands for the set of all invoice numbers and the arrows represent attributes of \(D\). Following this view, given an invoice number, the function \(d\) returns a date, the function \(b\) a branch, the function \(p\) a product type and the function \(q\) a quantity (i.e., the number of units of that product type).  
Assume now that we want to know the total quantity delivered to each branch (during the year); call this query \(Q\). Its evaluation needs the extensions of only two among the four functions, namely, \(b\) and \(q\). Figure 2a shows a toy example, where the dataset \(D\) consists of seven invoices, numbered 1 to 7. It also shows the values of the functions \(b\) and \(q\), for example, \(b(1)=Br_{1}\), \(b(2)=Br_{1}\), \(b(3)=Br_{2}\) and so on; and \(q(1)=200\), \(q(2)=100\), \(q(3)=200\) and so on.  
In order to find the answer to query \(Q\), for each branch \(Br_{i}\), we proceed in three steps as follows:  
1. Grouping. Group together all invoices \(j\) of \(D\) such that \(b(j)=Br_{i}\).
2. Measuring. Apply q to each invoice \(j\) of the \(Br_{i}\)-group to find the corresponding quantity \(q(j)\).
3. Aggregation. Sum up the \(q(j)^{\prime}\)s thus obtained to get a single value \(u_{i}\).  
This process creates a function \(ans_{Q}\) associating each branch \(Br_{i}\) with a value \(u_{i}\), as shown in Figure 2b. We view the ordered triple \(Q=(b,q,sum)\) as a query, the function \(ans_{Q}\) as the answer to \(Q\) and the computations described above as the query evaluation process. The function \(b\) that appears first in the triple \((b,q,sum)\) and is used in the grouping step is called the grouping function; the function \(q\) that appears second in the triple is called the measuring function; and the function \(sum\) that appears third in the triple is called the reduction operation (or the aggregate operation).