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

client-V2 com.clickhouse.client.api.metrics.Metric.getLong() #1900

Open
lelewolf opened this issue Nov 4, 2024 · 3 comments
Open

client-V2 com.clickhouse.client.api.metrics.Metric.getLong() #1900

lelewolf opened this issue Nov 4, 2024 · 3 comments

Comments

@lelewolf
Copy link

lelewolf commented Nov 4, 2024

Describe the bug

After executing an SQL query, attempting to retrieve ServerMetrics.ELAPSED_TIME or ServerMetrics.RESULT_ROWS from OperationMetrics results in a NullPointerException. This error indicates that metrics.getMetric() is returning null, likely because the OperationMetrics instance did not record the relevant metrics correctly.

Steps to reproduce

  1. Configure the ClickHouse client and run the following code.
  2. Call the executeSQL method, passing in an SQL query and queryId.
  3. Observe the logs to see if the error message appears: Cannot invoke "com.clickhouse.client.api.metrics.Metric.getLong()" because the return value of "com.clickhouse.client.api.metrics.OperationMetrics.getMetric(com.clickhouse.client.api.metrics.ServerMetrics)" is null.

Expected behaviour

Code example

public QueryResult executeSQL(String sql, String queryId) throws Exception {
    QuerySettings settings = createQuerySettings(queryId);
    log.info("开始执行查询,queryId:{},sql:{},settings:{}", queryId, sql,
        JSON.toJSONString(settings));
    try {
      QueryResponse response = executeSQLQuery(sql, settings);
      OperationMetrics metrics = response.getMetrics();
      metrics.operationComplete();
      log.info("SQL 查询执行时间: {} 毫秒, 查询查询结果条数: {}", metrics.getMetric(ServerMetrics.ELAPSED_TIME), metrics.getMetric(ServerMetrics.RESULT_ROWS));
      log.info("SQL 查询结果: {}", JSON.toJSONString(metrics));
      return buildQueryResult(jsonResult,metrics);
    } catch (InterruptedException | ExecutionException e) {
      log.error("SQL执行失败: {}", sql, e);
      throw new SQLException("Error executing SQL: " + sql, e);
    }
  }

Error log

Cannot invoke "com.clickhouse.client.api.metrics.Metric.getLong()" because the return value of "com.clickhouse.client.api.metrics.OperationMetrics.getMetric(com.clickhouse.client.api.metrics.ServerMetrics)" is null

Configuration

Environment

  • Client version: client-v2 0.7.1
  • Language version: java
  • OS: mac

ClickHouse server

  • ClickHouse Server version:23.3.2.1
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary
@lelewolf lelewolf added the bug label Nov 4, 2024
@chernser chernser added this to the Priority Backlog milestone Nov 4, 2024
@chernser
Copy link
Contributor

chernser commented Nov 4, 2024

@lelewolf Thank you for reporting! We will look into it.

@chernser
Copy link
Contributor

chernser commented Nov 6, 2024

Good day, @lelewolf !

I've not reproduced the issue. Here is my PR with test #1914
Few things to mention:

  • user code should not call "completeOperation()" for metrics that have got from a response object - client has done it already.
  • what is implementation of executeSQLQuery in your code? Is it doing something with metrics?

Thanks!

@chernser chernser removed this from the 0.7.1-patch milestone Nov 6, 2024
@isfang
Copy link

isfang commented Nov 26, 2024

I also encountered this issue, here is the screenshot。

It seems that the [ELAPSED_TIME("server.elapsedTime");] value was not returned. maybe the elapsedTime value needs to be parsed from the [client.opDuration] section? @chernser

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants