Apache Ignite Documentation

GridGain Developer Hub - Apache Ignitetm

Welcome to the Apache Ignite developer hub run by GridGain. Here you'll find comprehensive guides and documentation to help you start working with Apache Ignite as quickly as possible, as well as support if you get stuck.

 

GridGain also provides Community Edition which is a distribution of Apache Ignite made available by GridGain. It is the fastest and easiest way to get started with Apache Ignite. The Community Edition is generally more stable than the Apache Ignite release available from the Apache Ignite website and may contain extra bug fixes and features that have not made it yet into the release on the Apache website.

 

Let's jump right in!

 

Documentation     Ask a Question     Download

 

Javadoc     Scaladoc     Examples

Sliding Windows

Configure sliding windows into streaming data.

Sliding windows are configured as Ignite cache eviction policies, and can be time-based, size-based, or batch-based. You can configure one sliding-window per cache. However, you can easily define more than one cache if you need different sliding windows for the same data.

Time-Based Sliding Windows

Time-based windows are configured using JCache-compliant ExpiryPolicy. You can have streamed events expire based on create time, last-access time, or update time.

Here is how you can configure a 5-second sliding window based on creation time in Ignite.

CacheConfiguration<Integer, Long> cfg = new CacheConfiguration<>("myStreamCache");

// Sliding window of 5 seconds based on creation time.
cfg.setExpiryPolicyFactory(FactoryBuilder.factoryOf(
  new CreatedExpiryPolicy(new Duration(SECONDS, 5))));

FIFO Sliding Window

FIFO (first-in-first-out) sliding windows are configured via FifoEvictionPolicy in Ignite caches. This policy is size-based. Stream tuples are inserted into the window until cache size reaches its maximum limit. Then the oldest tuples start getting evicted automatically.

Here is how you can configure a FIFO sliding window holding 1,000,000 of stream tuples.

CacheConfiguration<Integer, Long> cfg = new CacheConfiguration<>("myStreamCache");

// FIFO window holding 1,000,000 entries.
cfg.setEvictionPolicyFactory(new FifoEvictionPolicy(1_000_000));

LRU Sliding Window

LRU (least-recently-used) sliding windows are configured via LruEvictionPolicy in Ignite caches. This policy is size-based. Stream tuples are inserted into the window until cache size reaches its maximum limit. Then the least recently accessed tuples start getting evicted automatically.

Here is how you can configure LRU sliding window holding 1,000,000 of most recently accessed data.

CacheConfiguration<Integer, Long> cfg = new CacheConfiguration<>("myStreamCache");

// LRU window holding 1,000,000 entries.
cfg.setEvictionPolicyFactory(new LruEvictionPolicy(1_000_000));

Querying Sliding Windows

Sliding windows can be queried in the same way as any other Ignite caches, using Predicate-based, SQL, or TEXT queries.

Here is an example of how a cache holding a sliding window of financial instruments streamed into the system can be queried using SQL queries.

First we need to create indexes based on the queried fields. In this case we are indexing the fields for Instrument class and the String keys.

CacheConfiguration<String, Instrument> cfg = new CacheConfiguration<>("instCache");

// Index some fields for querying portfolio positions.
cfg.setIndexedTypes(String.class, Instrument.class);

// Get a handle on the cache (create it if necessary).
IgniteCache<String, Instrument> instCache = ignite.getOrCreateCache(cfg);

Let's query top 3 best performing financial instruments. We do it via ordering by (latest - open) price and selecting top 3.

// Select top 3 best performing instruments.
SqlFieldsQuery top3qry = new SqlFieldsQuery(
  "select symbol, (latest - open) from Instrument order by (latest - open) desc limit 3");

// List of rows. Every row is represented as a List as well.
List<List<?>> top3 = instCache.query(top3qry).getAll();

Let's query total profit across all financial instruments. We do it by adding up all (latest - open) values across all instruments.

// Select total profit across all financial instruments.
SqlFieldsQuery profitQry = new SqlFieldsQuery("select sum(latest - open) from Instrument");

List<List<?>> profit = instCache.query(profitQry).getAll();

System.out.printf("Total profit: %.2f%n", row.get(0));

Sliding Windows


Configure sliding windows into streaming data.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.