ITPub博客

首页 > IT基础架构 > > elasticsearch-sql 增加 jdbc支持

elasticsearch-sql 增加 jdbc支持

作者:飘絮絮絮丶 时间:2022-01-05 17:10:31 0 删除 编辑

增加该功能,纯粹是在关issue的时候看到了第一个issue,参看 Is there any plan for JDBC drivers?。

大家讨论的时候,提供了两个选择,一个是apache calcite, 另外一个是利用 alibaba 的jdbc 连接池 druid。最后我选择了使用druid 来完成。为啥不用第一个的原因如下:

I have tried calcite to add this feature to es-sql. It's proved to be unsuitable. calcite kind like spark datasource API which provide scanTable,filterTabe,translateTable which means you cannot access original sql(Raw SQL) but some expressions . Also, this means join ,group by action are all done in calcite which really impact performance .

PS: 该功能还只是Demo阶段,很多功能还不完备。等稳定后会合并到原项目中。目前经过几轮PR,

elasticsearch-sql 已经支持比较复杂的SQL语法了。

安装步骤

代码示例

public class JDBCTests {
@Test
public void testJDBC() throws Exception {
Properties properties = new Properties();
properties.put("url", "jdbc:elasticsearch://127.0.0.1:9300/twitter2");
DruidDataSource dds = (DruidDataSource) ElasticSearchDruidDataSourceFactory.createDataSource(properties);
dds.setInitialSize(1);
Connection connection = dds.getConnection();
PreparedStatement ps = connection.prepareStatement("SELECT split(trim(concat_ws('dd',newtype,num_d)),'dd')[0] as nt from twitter2");
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()) {
System.out.println(resultSet.getString("nt"));
}

ps.close();
connection.close();
dds.close();
}

}


作者:祝威廉
链接:https://www.jianshu.com/p/3784f55a68ca
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946831/viewspace-3150997/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-09

  • 博文量
    2646
  • 访问量
    42274