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

ResponseJSON<T> defines incorrect type for "totals" value #274

Closed
sanyogitaranade opened this issue May 23, 2024 · 1 comment · Fixed by #280
Closed

ResponseJSON<T> defines incorrect type for "totals" value #274

sanyogitaranade opened this issue May 23, 2024 · 1 comment · Fixed by #280
Labels
bug Something isn't working

Comments

@sanyogitaranade
Copy link

sanyogitaranade commented May 23, 2024

Describe the bug

ResponseJSON is defined as

export interface ResponseJSON<T = unknown> {
    data: Array<T>;
    query_id?: string;
    totals?: Record<string, number>;
...
}

But, during our testing we observed that totals values can be "string/boolean" (possibly other data types) too. Here is one such response fragment.

{
  "meta": [
    {
      "name": "totalCount",
      "type": "UInt64"
    },
    {
      "name": "seqID",
      "type": "UInt32"
    },
    {
      "name": "eventHref",
      "type": "String"
    },
    {
      "name": "ip",
      "type": "String"
    },
    {
      "name": "userID",
      "type": "String"
    },
    {
      "name": "userName",
      "type": "String"
    },
    {
      "name": "userEmail",
      "type": "String"
    },
    {
      "name": "userIsAnonymous",
      "type": "Nullable(Bool)"
    },
  ],
  "data": [
    {
      "totalCount": "1",
      "seqID": 6,
      "eventHref": "href1",
      "ip": "::1",
      "userID": "1",
      "userName": "Jane Doe",
      "userEmail": "",
      "userIsAnonymous": false,
    }
  ],
  "totals": {
    "totalCount": "1",
    "seqID": 6,
    "eventHref": "href1",
    "ip": "::1",
    "userID": "1",
    "userName": "Jane Doe",
    "userEmail": "",
    "userIsAnonymous": false,
  },
  "rows": 1,
  "rows_before_limit_at_least": 1,
  "statistics": {
    "elapsed": 0.1502299,
    "rows_read": 69487,
    "bytes_read": 6324936
  }
}

Expected behaviour

  1. Instead of totals being Record<string, number>, it should match the shape of data i.e. the type should be
    data: Array<T>;
    query_id?: string;
    totals?: T;

Code example

      const { stream, query_id } = await this.client.exec({
        query: finalQuery,
      });

      const rs = new ResultSet<'JSON'>(stream, 'JSON', query_id);
      const decoded = await rs.json<Result>();

Error log

Configuration

Environment

  • Client version: 1.0.2
  • Language version: JS/TS
  • OS: Mac

ClickHouse server

  • ClickHouse Server version: 23.8.8.20-lts
  • ClickHouse Server non-default settings, if any:
  • CREATE TABLE statements for tables involved:
  • Sample data for all these tables, use clickhouse-obfuscator if necessary
@sanyogitaranade sanyogitaranade added the bug Something isn't working label May 23, 2024
@slvrtrn
Copy link
Contributor

slvrtrn commented Jun 6, 2024

Fixed in 1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants