elasticsearch-sql 增加 jdbc支持

增加该功能,纯粹是在关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();
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值