Apache Ignite is a distributed in-memory computing platform that enables the processing and storage of large volumes of data in memory to achieve high performance and scalability.
In this article, we will explore how to configure a connection to Apache Ignite in FastReport .NET. You will learn the necessary steps to connect the plugin via code and the report designer. By following our recommendations, you will be able to effectively use Apache Ignite as a data source for your reports in FastReport .NET.
The implemented plugin for connecting to Apache Ignite is a lightweight solution based on the Ignite.NET Thin Client.
Ignite offers two ways to logically represent data: key-value caches and SQL tables (schemas). Despite the differences, these representations are equivalent and can reflect the same data.
In Ignite, an SQL table and a key-value cache are two equivalent ways of representing the same internal data structure. Access to the data can be obtained through the key-value API, SQL operators, or both methods.
A cache is a collection of key-value pairs, accessed through the key-value API. An SQL table in Ignite is similar to tables in traditional database management systems, but with some additional constraints. For example, each SQL table must have a primary key.
A table with a primary key can be represented as a key-value cache, where the primary key column acts as the key, and the other columns in the table are the fields of the object (value).
The main difference between these two data representations lies in the method of accessing them. With a key-value cache, you can work with objects using supported programming languages. SQL tables, on the other hand, support standard SQL syntax, which can be beneficial, for example, when migrating data from an existing database.
To use the plugin, you must first build the project located at: ..\Extras\Core\FastReport.Data\FastReport.Data.Ignite
. After that, the plugin needs to be registered. This can be done in two ways.
Method 1. Using Code.
Copy the following code and paste it into your project. This needs to be done only once when starting the application.
FastReport.Utils.RegisteredObjects.AddConnection(typeof(IgniteDataConnection));
Method 2. Using the Report Designer.
To connect the connector in the designer, go to the "File|Settings..." menu in the Ribbon interface (or "View|Settings..." in the standard interface). In the opened window, select the "Plugins" tab and add the built .dll of the plugin as shown below.
After adding the plugin, it is necessary to restart the FastReport .NET designer.
To create a connection to Apache Ignite, go to the "Data" menu and select "Add Data Source."
In the opened window, click on the "New Connection" button, then from the dropdown list of connection types, select the option " Apache Ignite Connection." In the window that appears, specify the address(es) of the nodes, as well as the username and password (if required).
If the connection is successful, the next step will display a list of tables (caches) contained in the nodes specified in the previous step:
The plugin supports working with caches that are created both as key-value pairs and as SQL tables.
The method of creating and configuring a cache in Apache Ignite directly impacts the composition of fields and the representation of data types. Depending on the chosen method (for example, using classes with the [QuerySqlField] attributes, programmatic definition via QueryEntity, or working with dynamic data), the result may vary. This concerns both the list of available fields and their data types.
The following code examples will use snippets from the official Apache Ignite functionality examples. These examples can be downloaded from this link in the BINARY RELEASES section: https://ignite.apache.org/download.cgi.
Let’s open the downloaded archive and navigate to the following folder:
..\apache-ignite-2.17.0-bin\platforms\dotnet\examples\Thin
From these examples, we will use the custom class Organization, which represents the data model of an organization. This class contains the following properties:
The complete code for the class can be found in the folder:
..\apache-ignite-2.17.0-bin\platforms\dotnet\examples\Shared\Models
QueryEntity is an Apache Ignite component that allows you to programmatically define the data structure (schema) for a cache and manually specify the fields along with their types.
For caches with metadata (QueryEntity), operations for retrieving the list of fields and their data types are supported. Custom data types are handled in the following manner:
For example, if the cache is created during the setup as follows:
var organizationCache = ignite.GetOrCreateCache<int, Organization>( new CacheClientConfiguration("dotnet_cache_query_organization", new QueryEntity(typeof(int), typeof(Organization))));
Then, when connecting to an already prepared instance of Apache Ignite in FastReport, the list of fields will include only those fields from the Organization class that are marked with the [QuerySqlField] attribute.
However, when viewing the data, all fields from the cache will be displayed:
If the cache is created during the setup without using QueryEntity, then the data types of all fields will be defined as string. Example code:
ICacheClient<int, Organization> cache = ignite.GetCache<int, Organization>("dotnet_cache_put_get");
In the list of fields, all available fields will be displayed, regardless of the presence of the [QuerySqlField] attribute. This is the second method of creating a cache.
Finally, let's consider the third method of working with caches. Here is an example of creating and populating a cache as an SQL table:
cache.Query(new SqlFieldsQuery( "CREATE TABLE IF NOT EXISTS city (id LONG PRIMARY KEY, name VARCHAR)
WITH \"template=replicated\"")).GetAll(); const string addCity = "INSERT INTO city (id, name) VALUES (?, ?)"; cache.Query(new SqlFieldsQuery(addCity, 1L, "Forest Hill")); cache.Query(new SqlFieldsQuery(addCity, 2L, "Denver")); cache.Query(new SqlFieldsQuery(addCity, 3L, "St. Petersburg"));
For such caches, the metadata (QueryEntity) contains information about the data types for each field.
In an Apache Ignite cache, data may be stored without explicitly defined field names. For example:
var cache = ignite.GetOrCreateCache<int, object>("put-get-example"); int key = 1; var val = new Address("1545 Jackson Street", 94612); cache.Put(key, val); int key1 = 2; var val1 = 942.28956; cache.Put(key1, val1); int key2 = 3; var val2 = "test String"; cache.Put(key2, val2);
When connecting to an instance of Apache Ignite in FastReport (with the code from the example above), you will see the following result.
In this example:
For fields that lack a name, unique identifiers are generated.
We’ve covered how to set up a connection to Apache Ignite in FastReport .NET. By following the steps outlined, you’ll be able to integrate these systems and take full advantage of Apache Ignite as a data source for your reports.
Apache Ignite provides fast data access and processing, while FastReport .NET enables the creation of powerful reports. Their integration opens up new opportunities for data analysis and visualization.
We hope this article has been helpful and will assist you in effectively using Apache Ignite in your projects with FastReport .NET.