Stream Processing with SQL

This page shows how to processing stream data in HStreamDB with SQL using Java SDK.

Prerequisites

Make sure you have HStreamDB running and accessible.

Execute Real-time Query on Stream

You can execute a real-time query on stream using the HStreamClient.streamQuery() method:

  1. final String TEST_STREAM = "test_stream";
  2. Publisher<HRecord> publisher = client.streamQuery(
  3. "select * from " + TEST_STREAM +
  4. " where temperature > 30 emit changes;"
  5. );
  6. Observer<HRecord> observer = new Observer<HRecord>() {
  7. @Override
  8. public void onNext(HRecord hrecord) {
  9. System.out.println(hrecord);
  10. }
  11. @Override
  12. public void onError(Throwable t) {
  13. throw new RuntimeException(t);
  14. }
  15. @Override
  16. public void onCompleted() {
  17. }
  18. };
  19. publisher.subscribe(observer);

The HStreamClient.streamQuery() method return a Publisher object, and you need to provide an Observer object that contains your logic for processing the results returned by the query.