A new dataset type, script dataset, is provided for computing reports. This allows you to further compute and process data in a dataset to provide data source support for reports. The following describes the script dataset.
What is a script dataset?
A dataset type of a set computing report. You can edit the computing script in the script data set (the script follows the Set Computing syntax) to complete data computing and processing, the processed result set provides data source support for the report, so that the report tool can obtain the data source re-computing capability.
In the script dataset editor, you cannot add or delete columns or perform visual debugging like in the dataset editor. Therefore, the script dataset is suitable for computation scripts that are relatively simple.
How to use a script dataset?
The script dataset is similar to the SQL dataset, except that the input in the script dataset is not an SQL statement, but a step-by-step computing script. The following two examples show how to use it.
Instance 1
Report description
After ranking based on the total score of the students, the students are divided into two classes according to the snake distribution. The first class is ,... Class 2 is grade 2, 3, 6, 7 ,... Name. The list of students in this class is queried based on the class parameters. Follow these steps.
Report Data Source
Create a report and set report Parameters
Create a report in The Report designer and set the class parameters:
Create a script Dataset
Select "script dataset" in the dataset type. In the script dataset editing window, enter the computing script step by step to complete data sorting, filtering, and other calculations.
A1: Use the demo of the current data source of the report to execute an SQL statement to query the list of all students and their scores;The dataset can be connected to different data sources (non-current report data sources) for data query. You can use connect ("DB") to establish a data source connection and then query data based on the connection;
A2: sort by student scores in descending order;
A3: Add ranking fields for sorted records;
A4: Use the. Step () function to obtain the subset. Here, the members of each class are dynamically obtained based on the Report parameter class;The computing script dataset can directly use the parameters defined in the report, which is more concise, such as the class in this example (this is different from the SQL dataset );
A5: return result set of the report.
Set a report expression
Finally, edit the report expression in the report template to complete report creation.
Preview The report. Enter 1 and 2 for the class parameters to obtain the list of students in the first and second classes, as shown below:
In this example, the computation of the script dataset is difficult to implement, whether using the report expression or SQL. After the SQL statement generates a number through the subquery, it uses the MOD (NO, 4) = 1 or mod (NO, 4) = 0) can be completed, and. the step () function can easily retrieve the subset (in fact, the ranking field added in the script has no practical purpose, just to facilitate viewing the results), which is very simple.
In addition to operating the database, the script dataset can also calculate the number of data directly from the file. See instance 2 below.
Instance 2
Report description
Student test scores are stored in the transcript (score.txt). You need to query the scores of all students based on the class parameters and summarize the total scores by student group.
The file content is as follows:
Class studentid subject score ID name gender age
Class One 1 English 84 1 Emily F 17
Class One 1 math 77 1 Emily F 17
Class One 1 PE 69 1 Emily F 17
Class One 2 English 81 2 Elizabeth F 16
Class One 2 math 80 2 Elizabeth F 16
Class One 2 PE 97 2 Elizabeth F 16
Class One 3 English 75 3 Sean M 17
Class One 3 math 86 3 Sean M 17
Class One 3 PE 67 3 Sean M 17
Class One 4 English 96 4 Lauren F 15
Parameters for creating a report
Set script Dataset
A1: create a file cursor Based on the file path;
A2: Use CS. Select () to filter data and return the record cursor;
A3: the cursor is grouped and summarized by students to obtain the total score;
A4: return result set for the report using result.
Set a report expression
It is very easy to use a script dataset to read files and filter and summarize files.
Functions of a script Dataset
The preceding two examples show the main functions of the script Dataset:
1. unconventional computing
The script dataset is suitable for some Unconventional Operations (such as instance 1). These operations are neither applicable to the report end nor to the database. If the external dataset (stored procedure or Java program) is too complicated to develop the report, it is a good choice to use the script dataset of the report.
2. Support for diverse data sources
Similar to reading text files in instance 2, script datasets enable centralized computing reports to support diverse data sources without relying on third-party programs. In addition to txt, script datasets can also support data sources such as xls, hadoop, and nosql.
In addition, the script dataset uses a dedicated computing stage to avoid computation in the report and reduce hidden cells, thus improving the overall performance of the report.
Script dataset of the computing report