pinot查询数据

pinot查询主要从下面几个方式操作

1、从controller界面去查询

pinot查询数据_第1张图片

2、pinot脚本查询(因为查询需要通过broker,所以端口为broker的端口)

./pinot-admin.sh PostQuery -brokerPort 8000 -query "select count(*) from transcript"

3、curl命令进行查询

curl -X POST -d '{"pql":"select count(*) from baseballStats"}' http://localhost:8000/query

4、java的api进行查询

Pinot的clientAPI与JDBC类似,但由于Pinot的行为方式不同,所以存在一些差异。例如,具有多个聚合函数的查询将为每个聚合函数返回一个结果集,因为它们是并行计算的。

使用ConnectionFactory类的实用程序方法创建到Pinot的连接,以创建到给定Zookeeper URL、Java属性对象或要连接的代理地址列表的Pinot集群的连接。

Connection connection = ConnectionFactory.fromZookeeper
  ("some-zookeeper-server:2191/zookeeperPath");

Connection connection = ConnectionFactory.fromProperties("demo.properties");

Connection connection = ConnectionFactory.fromHostList
  ("some-server:1234", "some-other-server:1234", ...);

Connection.execute(java.lang.String)和Connection. executeasync (java.lang.String)连接方法将查询直接发送到Pinot集群。

ResultSetGroup resultSetGroup = connection.execute("select * from foo...");Future futureResultSetGroup = connection.executeAsync
  ("select * from foo...");

查询也可以使用PreparedStatement来转义查询参数:

("select * from foo where a = ?");statement.setString(1, "bar");
ResultSetGroup resultSetGroup = statement.execute();Future futureResultSetGroup = statement.executeAsync();

在选择查询的情况下,可以使用第一个ResultSet中的各种get方法获得结果,这些方法是通过getResultSet(int)方法获得的:

ResultSet resultSet = connection.execute
  ("select foo, bar from baz where quux = 'quuux'").getResultSet(0);

for (int i = 0; i < resultSet.getRowCount(); ++i) {
  System.out.println("foo: " + resultSet.getString(i, 0));
  System.out.println("bar: " + resultSet.getInt(i, 1));}

resultSet.close();

在聚合的情况下,每个聚合函数都在自己的ResultSet中:

ResultSetGroup resultSetGroup = connection.execute("select count(*) from foo");

ResultSet resultSet = resultSetGroup.getResultSet(0);System.out.println("Number of records: " + resultSet.getInt(0));resultSet.close();

可以有多个ResultSet,每个ResultSet可以包含按组键分组的多个结果。

ResultSetGroup resultSetGroup = connection.execute
    ("select min(foo), max(foo) from bar group by baz");

System.out.println("Number of result groups:" +
    resultSetGroup.getResultSetCount(); // 2, min(foo) and max(foo)

ResultSet minResultSet = resultSetGroup.getResultSet(0);for(int i = 0; i < minResultSet.length(); ++i) {
    System.out.println("Minimum foo for " + minResultSet.getGroupKeyString(i, 1) +
        ": " + minResultSet.getInt(i));}

ResultSet maxResultSet = resultSetGroup.getResultSet(1);for(int i = 0; i < maxResultSet.length(); ++i) {
    System.out.println("Maximum foo for " + maxResultSet.getGroupKeyString(i, 1) +
        ": " + maxResultSet.getInt(i));}

resultSet.close();

 

你可能感兴趣的:(pinot)