Pulsar SQL Get Started

It is super easy to get started on querying data in Pulsar.

Requirements

  • Pulsar distribution
  • Pulsar built-in connectors
  1. ./bin/pulsar standalone

Next, start a Pulsar SQL worker:

  1. ./bin/pulsar sql-worker run

After both the Pulsar standalone cluster and the SQL worker are done initializing, run the SQL CLI:

  1. ./bin/pulsar sql

You can now start typing some SQL commands:

  1. presto> show catalogs;
  2. Catalog
  3. ---------
  4. pulsar
  5. system
  6. (2 rows)
  7. Query 20180829_211752_00004_7qpwh, FINISHED, 1 node
  8. Splits: 19 total, 19 done (100.00%)
  9. 0:00 [0 rows, 0B] [0 rows/s, 0B/s]
  10. presto> show schemas in pulsar;
  11. Schema
  12. -----------------------
  13. information_schema
  14. public/default
  15. public/functions
  16. sample/standalone/ns1
  17. (4 rows)
  18. Query 20180829_211818_00005_7qpwh, FINISHED, 1 node
  19. Splits: 19 total, 19 done (100.00%)
  20. 0:00 [4 rows, 89B] [21 rows/s, 471B/s]
  21. presto> show tables in pulsar."public/default";
  22. Table
  23. -------
  24. (0 rows)
  25. Query 20180829_211839_00006_7qpwh, FINISHED, 1 node
  26. Splits: 19 total, 19 done (100.00%)
  27. 0:00 [0 rows, 0B] [0 rows/s, 0B/s]

Currently, there is no data in Pulsar that we can query. Lets start the built-in connector DataGeneratorSource to ingest some mock data for us to query:

  1. ./bin/pulsar-admin sources create --name generator --destinationTopicName generator_test --source-type data-generator

Afterwards, the will be a topic with can query in the namespace "public/default":

  1. presto> show tables in pulsar."public/default";
  2. Table
  3. ----------------
  4. generator_test
  5. (1 row)
  6. Query 20180829_213202_00000_csyeu, FINISHED, 1 node
  7. Splits: 19 total, 19 done (100.00%)
  8. 0:02 [1 rows, 38B] [0 rows/s, 17B/s]

We can now query the data within the topic "generator_test":

  1. presto> select * from pulsar."public/default".generator_test;
  2. firstname | middlename | lastname | email | username | password | telephonenumber | age | companyemail | nationalidentitycardnumber |
  3. -------------+-------------+-------------+----------------------------------+--------------+----------+-----------------+-----+-----------------------------------------------+----------------------------+
  4. Genesis | Katherine | Wiley | genesis.wiley@gmail.com | genesisw | y9D2dtU3 | 959-197-1860 | 71 | genesis.wiley@interdemconsulting.eu | 880-58-9247 |
  5. Brayden | | Stanton | brayden.stanton@yahoo.com | braydens | ZnjmhXik | 220-027-867 | 81 | brayden.stanton@supermemo.eu | 604-60-7069 |
  6. Benjamin | Julian | Velasquez | benjamin.velasquez@yahoo.com | benjaminv | 8Bc7m3eb | 298-377-0062 | 21 | benjamin.velasquez@hostesltd.biz | 213-32-5882 |
  7. Michael | Thomas | Donovan | donovan@mail.com | michaeld | OqBm9MLs | 078-134-4685 | 55 | michael.donovan@memortech.eu | 443-30-3442 |
  8. Brooklyn | Avery | Roach | brooklynroach@yahoo.com | broach | IxtBLafO | 387-786-2998 | 68 | brooklyn.roach@warst.biz | 085-88-3973 |
  9. Skylar | | Bradshaw | skylarbradshaw@yahoo.com | skylarb | p6eC6cKy | 210-872-608 | 96 | skylar.bradshaw@flyhigh.eu | 453-46-0334 |
  10. .
  11. .
  12. .

Now, you have some mock data to query and play around with!

If you want to try to ingest some of your own data to play around with, you can write a simple producer to write custom defined data to Pulsar.

For example:

  1. public class Test {
  2. public static class Foo {
  3. private int field1 = 1;
  4. private String field2;
  5. private long field3;
  6. }
  7. public static void main(String[] args) throws Exception {
  8. PulsarClient pulsarClient = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
  9. Producer<Foo> producer = pulsarClient.newProducer(AvroSchema.of(Foo.class)).topic("test_topic").create();
  10. for (int i = 0; i < 1000; i++) {
  11. Foo foo = new Foo();
  12. foo.setField1(i);
  13. foo.setField2("foo" + i);
  14. foo.setField3(System.currentTimeMillis());
  15. producer.newMessage().value(foo).send();
  16. }
  17. producer.close();
  18. pulsarClient.close();
  19. }
  20. }

Afterwards, you should be able query the data you just wrote.