Quickstart with Docker

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/logdevice
  2. 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

Start local logdevice cluster

  1. docker run -td --rm --name some-hstream-store -v dbdata:/data/store --network host hstreamdb/logdevice 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 -l /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. Start HStream-Cli!
  2. Command
  3. :h help command
  4. :q quit cli
  5. show queries list all queries
  6. terminate query <taskid> terminate query by id
  7. terminate query all terminate all queries
  8. <sql> run sql
  9. >

Create a stream

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

The FORMAT parameter after WITH specifies the format of data in the stream. Note that only "JSON" format is supported now.

  1. CREATE STREAM demo WITH (FORMAT = "JSON");

Copy and paste this query into the interactive CLI session, and press enter to execute the statement. If everything works fine, you will get something like

  1. Right
  2. ( CreateTopic
  3. { taskid = 0
  4. , tasksql = "CREATE STREAM demo WITH (FORMAT = "JSON");"
  5. , taskStream = "demo"
  6. , taskState = Finished
  7. , createTime = 2021 - 02 - 04 09 : 07 : 25.639197201 UTC
  8. }
  9. )

which means the query is successfully executed.

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}