Interface ContinuousQueryWatermark

All Superinterfaces:
Serializable
All Known Implementing Classes:
ContinuousQueryPhysicalTimeWatermark, ContinuousQueryTransactionWatermark

public interface ContinuousQueryWatermark extends Serializable
Continuous query watermark. Represents a starting point for a continuous query.
  • Method Details

    • ofInstant

      static ContinuousQueryWatermark ofInstant(Instant startTime)
      Creates a new watermark based on specified time (wall clock).

      The specified timestamp should not be older than now() - LowWatermarkConfiguration.dataAvailabilityTime(), or the query will fail with an exception.

      For example, to query 5 seconds in the past, use Instant.now().minusSeconds(5).

      Parameters:
      startTime - Start time.
      Returns:
      Watermark.
    • afterTransaction

      static ContinuousQueryWatermark afterTransaction(Transaction tx)
      Creates a new watermark based on a read-only transaction.

      This watermark provides a way to get a consistent view of all the existing data in the table and subscribe to any future updates. It guarantees that we either see a given row state as part of the initial query using the transaction, or as a continuous query event.

      Example usage:

      
       Table table = ignite().tables().table("my-tbl");
      
       // Start a read-only transaction to get the initial state of the table.
       var txOpts = new TransactionOptions().readOnly(true);
       Transaction tx = ignite().transactions().begin(txOpts);
      
       Cursor<Tuple> initialQuery = table.recordView().query(tx, null);
       initialQuery.forEachRemaining(System.out::println);
       tx.commit();
      
       // Start a continuous query with a transaction watermark to get all updates since the initial query.
       var wm = ContinuousQueryWatermark.afterTransaction(tx);
       var cqOpts = ContinuousQueryOptions.builder().watermark(wm).build();
       table.recordView().queryContinuously(new MySubscriber<Tuple>(), cqOpts);
       
      Parameters:
      tx - Transaction.
      Returns:
      Watermark.