认证

基于Apache Kylin认证RESTFUL服务。支持的参数:
  • user : 用户名
  • password : 密码
  • ssl: true或false。 默认为flas;如果为true,所有的服务调用都会使用https。

连接url格式:

  1. jdbc:kylin://<hostname>:<port>/<kylin_project_name>
  • 如果“ssl”为true,“port”应该是Kylin server的HTTPS端口。
  • 如果“port”未被指定,driver会使用默认的端口:HTTP 80,HTTPS 443。
  • 必须指定“kylin_project_name”并且用户需要确保它在Kylin server上存在。

1. 使用Statement查询

  1. Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
  2. Properties info = new Properties();
  3. info.put("user", "ADMIN");
  4. info.put("password", "KYLIN");
  5. Connection conn = driver.connect("jdbc:kylin://localhost:7070/kylin_project_name", info);
  6. Statement state = conn.createStatement();
  7. ResultSet resultSet = state.executeQuery("select * from test_table");
  8. while (resultSet.next()) {
  9. assertEquals("foo", resultSet.getString(1));
  10. assertEquals("bar", resultSet.getString(2));
  11. assertEquals("tool", resultSet.getString(3));
  12. }

2. 使用PreparedStatementv查询

支持的PreparedStatement参数:
  • setString
  • setInt
  • setShort
  • setLong
  • setFloat
  • setDouble
  • setBoolean
  • setByte
  • setDate
  • setTime
  • setTimestamp
  1. Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
  2. Properties info = new Properties();
  3. info.put("user", "ADMIN");
  4. info.put("password", "KYLIN");
  5. Connection conn = driver.connect("jdbc:kylin://localhost:7070/kylin_project_name", info);
  6. PreparedStatement state = conn.prepareStatement("select * from test_table where id=?");
  7. state.setInt(1, 10);
  8. ResultSet resultSet = state.executeQuery();
  9. while (resultSet.next()) {
  10. assertEquals("foo", resultSet.getString(1));
  11. assertEquals("bar", resultSet.getString(2));
  12. assertEquals("tool", resultSet.getString(3));
  13. }

3. 获取查询结果元数据

Kylin jdbc driver支持元数据列表方法:
通过sql模式过滤器(比如 %)列出catalog、schema、table和column。

  1. Driver driver = (Driver) Class.forName("org.apache.kylin.jdbc.Driver").newInstance();
  2. Properties info = new Properties();
  3. info.put("user", "ADMIN");
  4. info.put("password", "KYLIN");
  5. Connection conn = driver.connect("jdbc:kylin://localhost:7070/kylin_project_name", info);
  6. Statement state = conn.createStatement();
  7. ResultSet resultSet = state.executeQuery("select * from test_table");
  8. ResultSet tables = conn.getMetaData().getTables(null, null, "dummy", null);
  9. while (tables.next()) {
  10. for (int i = 0; i < 10; i++) {
  11. assertEquals("dummy", tables.getString(i + 1));
  12. }
  13. }