Query data with Pulsar SQL
- Install Pulsar.
- Install Pulsar .
To query data in Pulsar with Pulsar SQL, complete the following steps.
- Start a Pulsar standalone cluster.
- Start a Pulsar SQL worker.
./bin/pulsar sql-worker run
- After initializing Pulsar standalone cluster and the SQL worker, run SQL CLI.
- Test with SQL commands.
presto> show catalogs;
Catalog
---------
pulsar
system
(2 rows)
Query 20180829_211752_00004_7qpwh, FINISHED, 1 node
Splits: 19 total, 19 done (100.00%)
0:00 [0 rows, 0B] [0 rows/s, 0B/s]
presto> show schemas in pulsar;
Schema
-----------------------
information_schema
public/default
public/functions
sample/standalone/ns1
(4 rows)
Query 20180829_211818_00005_7qpwh, FINISHED, 1 node
Splits: 19 total, 19 done (100.00%)
presto> show tables in pulsar."public/default";
Table
-------
Query 20180829_211839_00006_7qpwh, FINISHED, 1 node
Splits: 19 total, 19 done (100.00%)
0:00 [0 rows, 0B] [0 rows/s, 0B/s]
- Start the built-in connector DataGeneratorSource and ingest some mock data.
And then you can query a topic in the namespace “public/default”.
presto> show tables in pulsar."public/default";
Table
----------------
generator_test
(1 row)
Query 20180829_213202_00000_csyeu, FINISHED, 1 node
Splits: 19 total, 19 done (100.00%)
0:02 [1 rows, 38B] [0 rows/s, 17B/s]
You can query the mock data.
public class TestProducer {
public static class Foo {
private int field1 = 1;
private String field2;
private long field3;
public Foo() {
}
public int getField1() {
return field1;
}
public void setField1(int field1) {
this.field1 = field1;
public String getField2() {
return field2;
}
public void setField2(String field2) {
this.field2 = field2;
}
public long getField3() {
return field3;
}
public void setField3(long field3) {
this.field3 = field3;
}
}
public static void main(String[] args) throws Exception {
PulsarClient pulsarClient = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
Producer<Foo> producer = pulsarClient.newProducer(AvroSchema.of(Foo.class)).topic("test_topic").create();
for (int i = 0; i < 1000; i++) {
Foo foo = new Foo();
foo.setField1(i);
foo.setField2("foo" + i);
foo.setField3(System.currentTimeMillis());
producer.newMessage().value(foo).send();
}
producer.close();
pulsarClient.close();