Quickstart with Docker

Requirement

Start HStream requires an operating system kernel version greater than at least Linux 4.14

Installation

Install docker

Note

If you have already installed docker, you can skip this step.

See Install Docker Engine, and install it for your operating system. Please carefully check that you meet all prerequisites.

Confirm that the Docker daemon is running:

  1. docker version

Tips

On Linux, Docker needs root privileges. You can also run Docker as a non-root user, see Post-installation steps for Linux.

Pull docker images

  1. docker pull hstreamdb/hstream

Start a local standalone HStream-Server in Docker

Warning

Do NOT use this configuration in your production environment!

Create a directory for storing db datas

  1. mkdir /dbdata

Tips

If you are a non-root user, that you can not create directory under the root, you can also create it anywhere as you can, but you need to pass the absolute data path to docker volume arguments.

Start HStream Storage

  1. docker run -td --rm --name some-hstream-store -v /dbdata:/data/store --network host hstreamdb/hstream ld-dev-cluster --root /data/store --use-tcp

Start HStreamDB Server

  1. docker run -it --rm --name some-hstream-server -v /dbdata:/data/store --network host hstreamdb/hstream hstream-server --port 6570 --store-config /data/store/logdevice.conf

Start HStreamDB’s interactive SQL CLI

  1. docker run -it --rm --name some-hstream-cli -v /dbdata:/data/store --network host hstreamdb/hstream hstream-client --port 6570

If everything works fine, you will enter an interactive CLI and see help information like

  1. / / / / ___/_ __/ __ \/ ____/ | / |/ /
  2. / /_/ /\__ \ / / / /_/ / __/ / /| | / /|_/ /
  3. / __ /___/ // / / _, _/ /___/ ___ |/ / / /
  4. /_/ /_//____//_/ /_/ |_/_____/_/ |_/_/ /_/
  5. Command
  6. :h To show these help info
  7. :q To exit command line interface
  8. :help [sql_operation] To show full usage of sql statement
  9. SQL STATEMENTS:
  10. To create a simplest stream:
  11. CREATE STREAM stream_name;
  12. To create a query select all fields from a stream:
  13. SELECT * FROM stream_name EMIT CHANGES;
  14. To insert values to a stream:
  15. INSERT INTO stream_name (field1, field2) VALUES (1, 2);
  16. >

Create a stream

What we are going to do first is create a stream by CREATE STREAM query.

  1. CREATE STREAM demo;

Run a continuous query over the stream

Now we can run a continuous query over the stream we just created by SELECT query.

The query will output all records from the demo stream whose humidity is above 70 percent.

  1. SELECT * FROM demo WHERE humidity > 70 EMIT CHANGES;

It seems that nothing happened. But do not worry because there is no data in the stream now. Next, we will fill the stream with some data so the query can produce output we want.

Start another CLI session

Start another CLI session, this CLI will be used for inserting data into the stream.

  1. docker exec -it some-hstream-cli hstream-client --port 6570

Insert data into the stream

Run each of the given INSERT query in the new CLI session and keep an eye on the CLI session created in (2).

  1. INSERT INTO demo (temperature, humidity) VALUES (22, 80);
  2. INSERT INTO demo (temperature, humidity) VALUES (15, 20);
  3. INSERT INTO demo (temperature, humidity) VALUES (31, 76);
  4. INSERT INTO demo (temperature, humidity) VALUES ( 5, 45);
  5. INSERT INTO demo (temperature, humidity) VALUES (27, 82);
  6. INSERT INTO demo (temperature, humidity) VALUES (28, 86);

If everything works fine, the continuous query will output matching records in real time:

  1. {"temperature":22,"humidity":80}
  2. {"temperature":31,"humidity":76}
  3. {"temperature":27,"humidity":82}
  4. {"temperature":28,"humidity":86}