It is super easy to get started on querying data in Pulsar.
要求
首先,启动Pulsar独立集群:
./bin/pulsar standalone
下一步,启动一个Pulsar SQL worker:
./bin/pulsar sql-worker run
在Pulsar独立集群和SQL worker完成初始化之后,运行SQL CLI:
./bin/pulsar sql
您现在可以开始输入一些SQL命令:
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%)
0:00 [4 rows, 89B] [21 rows/s, 471B/s]
presto> show tables in pulsar."public/default";
Table
-------
(0 rows)
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]
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:
./bin/pulsar-admin source create --name generator --destinationTopicName generator_test --source-type data-generator
然后,将有一个可以在”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]
我们现在可以查询主题“generator_test”中的数据:
presto> select * from pulsar."public/default".generator_test;
firstname | middlename | lastname | email | username | password | telephonenumber | age | companyemail | nationalidentitycardnumber |
-------------+-------------+-------------+----------------------------------+--------------+----------+-----------------+-----+-----------------------------------------------+----------------------------+
Genesis | Katherine | Wiley | genesis.wiley@gmail.com | genesisw | y9D2dtU3 | 959-197-1860 | 71 | genesis.wiley@interdemconsulting.eu | 880-58-9247 |
Brayden | | Stanton | brayden.stanton@yahoo.com | braydens | ZnjmhXik | 220-027-867 | 81 | brayden.stanton@supermemo.eu | 604-60-7069 |
Benjamin | Julian | Velasquez | benjamin.velasquez@yahoo.com | benjaminv | 8Bc7m3eb | 298-377-0062 | 21 | benjamin.velasquez@hostesltd.biz | 213-32-5882 |
Michael | Thomas | Donovan | donovan@mail.com | michaeld | OqBm9MLs | 078-134-4685 | 55 | michael.donovan@memortech.eu | 443-30-3442 |
Brooklyn | Avery | Roach | brooklynroach@yahoo.com | broach | IxtBLafO | 387-786-2998 | 68 | brooklyn.roach@warst.biz | 085-88-3973 |
Skylar | | Bradshaw | skylarbradshaw@yahoo.com | skylarb | p6eC6cKy | 210-872-608 | 96 | skylar.bradshaw@flyhigh.eu | 453-46-0334 |
.
.
.
现在,您有一些模拟数据可供查询和使用!
如果您想尝试获取一些自己的数据,可以编写一个简单的生产者将自定义数据写入Pulsar。
例如:
public class Test {
public static class Foo {
private int field1 = 1;
private String field2;
private long 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();
}
}
接下来,你应该能够查询到刚写入的数据。
当前内容版权归 Apache Pulsar 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Apache Pulsar .