Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - jdbc driver throw exception when count() is used with JSONEachRow #726

Closed
jonathanyuechun opened this issue Sep 20, 2021 · 6 comments · Fixed by #736 or #747
Closed

[BUG] - jdbc driver throw exception when count() is used with JSONEachRow #726

jonathanyuechun opened this issue Sep 20, 2021 · 6 comments · Fixed by #736 or #747

Comments

@jonathanyuechun
Copy link

jonathanyuechun commented Sep 20, 2021

Valid SQL statement with clickhouse-client:

dev.server.io :) select count() from tutorial.visits_v1 format JSONEachRow

SELECT count()
FROM tutorial.visits_v1
FORMAT JSONEachRow

Query id: afa202e1-54cb-4c64-a628-f8d0711c71dc

{"count()":"1680609"}
↑ Progress: 1.00 rows, 4.10 KB (160.98 rows/s., 660.65 KB/s
1 rows in set. Elapsed: 0.006 sec. 
                 select count() from tutorial.visits_v1 format JSONEachRow

Snippet:

  public static void main(String... args) throws SQLException {
    String url = "jdbc:clickhouse://localhost:8123/tutorial";
    ClickHouseProperties properties = new ClickHouseProperties();
    // set connection options - see more defined in ClickHouseConnectionSettings
    properties.setClientName("Agent #1");
    // set default request options - more in ClickHouseQueryParam
    properties.setSessionId("default-session-id");
    ClickHouseDataSource dataSource = new ClickHouseDataSource(url, properties);

    String sql = "select count() from visits_v1 format JSONEachRow";
    Map<ClickHouseQueryParam, String> additionalDBParams = new HashMap<>();
    // set request options, which will override the default ones in ClickHouseProperties
    additionalDBParams.put(ClickHouseQueryParam.SESSION_ID, "new-session-id");
    List<String> datas = new ArrayList<>();
    try (ClickHouseConnection conn = dataSource.getConnection();
        ClickHouseStatement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql, additionalDBParams)) {
      while (rs.next()) {
        datas.add(rs.getString(1));
      }
    }
    System.out.println(datas.size());
  }

throws:

Exception in thread "main" ru.yandex.clickhouse.except.ClickHouseUnknownException: ClickHouse exception, code: 1002, host: localhost, port: 8123; ClickHouse response without column types
	at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.getException(ClickHouseExceptionSpecifier.java:92)
	at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:56)
	at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:25)
	at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:351)
	at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:324)
	at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:319)
	at org.thales.punch.server.services.api.TestMe.main(TestMe.java:35)
Caused by: java.lang.IllegalArgumentException: ClickHouse response without column types
	at ru.yandex.clickhouse.response.ClickHouseResultSet.<init>(ClickHouseResultSet.java:107)
	at ru.yandex.clickhouse.ClickHouseStatementImpl.createResultSet(ClickHouseStatementImpl.java:1121)
	at ru.yandex.clickhouse.ClickHouseStatementImpl.updateResult(ClickHouseStatementImpl.java:224)
	at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:344)
	... 3 more
@zhicwu zhicwu added this to the 0.3.2 Release milestone Sep 20, 2021
@zhicwu
Copy link
Contributor

zhicwu commented Sep 20, 2021

Similar issue as #725. For text format without header, we should use something like results Nullable(String) as default.

@jonathanyuechun
Copy link
Author

@zhicwu Thanks for the quick reply. May i know the date the next release is scheduled for ?

@zhicwu
Copy link
Contributor

zhicwu commented Sep 22, 2021

@zhicwu Thanks for the quick reply. May i know the date the next release is scheduled for ?

I'm aiming a release in early Oct, during holidays in China :)

@zhicwu zhicwu added the module-jdbc JDBC driver label Oct 6, 2021
@zhicwu zhicwu linked a pull request Oct 7, 2021 that will close this issue
@jonathanyuechun
Copy link
Author

@zhicwu Hi does the merged of : #736 fixed this issue ?

@zhicwu
Copy link
Contributor

zhicwu commented Oct 21, 2021

@zhicwu Hi does the merged of : #736 fixed this issue ?

The PR is a brand new Java client along with implementation built on top of gRPC. It's related but not really a "fix" to the issue. I still need some more time to apply the changes to JDBC driver.

In case you want to try the experimental staff on develop branch:

  1. enable gRPC on server
    https:/ClickHouse/ClickHouse/blob/d3df1c02bca5483eca30df3d9d362607139e3ce5/programs/server/config.xml#L203-L204

  2. use new client

ClickHouseNode server = ClickHouseNode.of("localhost", ClickHouseProtocol.GRPC, 9100, "tutorial");
// important to close both client and response if you won't reuse them later
try (ClickHouseClient client = ClickHouseClient.newInstance(server.getProtocol());
    ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.JSONEachRow)
      .query("select count() from visits_v1").execute().get()) {
    for (ClickHouseRecord r : resp.records()) {
      System.out.println(r.getValue(0).asLong());
    }
    // or simply:
    // System.out.println(resp.firstRecord().getValue(0).asLong());
}

@zhicwu zhicwu linked a pull request Nov 28, 2021 that will close this issue
18 tasks
@zhicwu
Copy link
Contributor

zhicwu commented Nov 28, 2021

In addition to Java client, it works in new JDBC driver as well.

select count() from system.query_log format JSONEachRow
--
results
{"count()":"6768"}

select count() from system.query_log format Markdown
--
results
| count() |
|-:|
| 6772 |

@zhicwu zhicwu closed this as completed Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants