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

Fixes some oddities dealing with ClickHouse #278

Merged
merged 1 commit into from
Sep 30, 2021

Conversation

bnaecker
Copy link
Collaborator

This commit fixes two bugs dealing with ClickHouse, and adds regressions
for them.

The first is about deserialization of structs which have a &str field.
serde_json is generally fine about zero-copy, except if the string
requires escaping. In that case, it can no longer deserialize the data
into a &str, since it must take ownership and manipulate the returned
buffer. This requires replacing &'a str with Cow<'a, str> in the DB
model types, specifically for the timeseries key fields. See
serde-rs/serde#1413 for more details. Note
that we also parse all string datum from the DB as String directly,
rather than as &str, again to avoid this (and because we'll be
converting it to an owned representation soon anyway).

The second bug is handling a ClickHouse oddity. By default, 64-bit
integer types are returned as quoted strings. As in, "1" instead of
1. This is apparently to support JavaScript's JSON implementation, but
in any case it's not the behavior we expect or want. There is thankfully
a setting to turn this off, which the database client object now sets
when it makes requests returning JSON data. See
ClickHouse/ClickHouse#2375 for more details.

@bnaecker bnaecker requested review from davepacheco and removed request for davepacheco September 30, 2021 04:28
@bnaecker bnaecker force-pushed the fix/clickhouse-client-oddities branch 2 times, most recently from 75de035 to 3a7fadd Compare September 30, 2021 16:19
oximeter/oximeter/src/db/model.rs Outdated Show resolved Hide resolved
This commit fixes two bugs dealing with ClickHouse, and adds regressions
for them.

The first is about deserialization of structs which have a `&str` field.
`serde_json` is generally fine about zero-copy, except if the string
requires escaping. In that case, it can no longer deserialize the data
into a `&str`, since it must take ownership and manipulate the returned
buffer. There are a few ways around this, but this commit opts for the
simplest -- using a owned `String` instead of a `&str`. The string is
immediately moved into a `Measurement`, which takes ownership anyway, so
this is the most straightfoward choice. See
serde-rs/serde#1413 for more details. Note
that we also parse all string datum from the DB as `String` directly,
rather than as `&str`, again to avoid this.

The second bug is handling a ClickHouse oddity. By default, 64-bit
integer types are returned as _quoted_ strings. As in, `"1"` instead of
`1`. This is apparently to support JavaScript's JSON implementation, but
in any case it's not the behavior we expect or want. There is thankfully
a setting to turn this off, which the database client object now sets
when it makes requests returning JSON data. See
ClickHouse/ClickHouse#2375 for more details.
@bnaecker bnaecker force-pushed the fix/clickhouse-client-oddities branch from 3a7fadd to 21d753d Compare September 30, 2021 16:36
@bnaecker bnaecker merged commit dba9527 into main Sep 30, 2021
@bnaecker bnaecker deleted the fix/clickhouse-client-oddities branch September 30, 2021 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants