ClickHouse / clickhouse-jdbc-bridge

A JDBC proxy from ClickHouse to external databases
Apache License 2.0
167 stars 60 forks source link

NullPointerException when executing a query with a JOIN to PostgreSQL. #176

Open ruslanen opened 1 year ago

ruslanen commented 1 year ago

Hi. I use clickhouse-jdbc-bridge with postgresql driver. Recently I have tried to execute query with JOIN, but found an error NullPointerException here.

It is easy to repeat a problem:

  1. Create tables in PostgreSQL:
    
    create table brands (
    brandname text not null,
    key bigint not null
    );
    insert into brands values ('Contoso',1), ('Adventure Works', 2), ('Litware', 3);

create table facts ( salesamount numeric, key bigint not null ); insert into facts values (100,1), (200, 2), (300, 4);

2. Execute query in ClickHouse:

select * from jdbc( 'jdbc:postgresql://localhost:5432/postgres?user=postgres&password=postgres', 'postgres', 'select brandname, brands.key as "bk", salesamount, facts.key as "fk" from brands full join facts on brands.key = facts.key;');

3. You will get an error:

May 18, 2023 10:38:33 AM com.clickhouse.jdbcbridge.core.NamedDataSource executeQuery INFO: Executing query(schema=[postgres]): select brandname, brands.key as "bk", salesamount, facts.key as "fk" from brands full join facts on brands.key = facts.key; May 18, 2023 10:38:33 AM com.clickhouse.jdbcbridge.JdbcBridgeVerticle errorHandler SEVERE: Failed to respond java.lang.NullPointerException at java.base/java.util.Objects.requireNonNull(Objects.java:208) at com.clickhouse.jdbcbridge.core.ByteBuffer.writeString(ByteBuffer.java:644) at com.clickhouse.jdbcbridge.impl.JdbcDataSource$ResultSetReader.read(JdbcDataSource.java:258) at com.clickhouse.jdbcbridge.core.DataTableReader.process(DataTableReader.java:176) at com.clickhouse.jdbcbridge.impl.JdbcDataSource.writeQueryResult(JdbcDataSource.java:720) at com.clickhouse.jdbcbridge.core.NamedDataSource.executeQuery(NamedDataSource.java:552) at com.clickhouse.jdbcbridge.JdbcBridgeVerticle.handleQuery(JdbcBridgeVerticle.java:488) at io.vertx.ext.web.impl.BlockingHandlerDecorator.lambda$handle$0(BlockingHandlerDecorator.java:48) at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:313) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:832)



clickhouse-jdbc-bridge relies on the fact that there will be no NULLs, but they are (because of JOIN behavior).

Some info:
- clickhouse-jdbc-bridge: master branch (9ecc9c50f087b980c577948d01bd7e58a45459fa)
- postgresql-42.3.4.jar.
ruslanen commented 1 year ago

@zhicwu Hello. There has been no activity in the repo for a very long time. Is it still supported?