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

Temporaily patch converters to fix support for LowCardinality strings #857

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

adamyeats
Copy link
Contributor

@adamyeats adamyeats commented Jun 7, 2024

This is a temporary fix for #833. At the moment, the sqlutil package in the Plugin SDK does not correctly handle the LowCardinality data types. I thought we'd fixed this in #814, but it turns out that the GetConverter() function is not actually called by anything within the SDK or our code as expected.

Until we can patch this upstream, I've added two extra converters for now, that can be removed when we can introduce more generic handling of these types.

@adamyeats adamyeats self-assigned this Jun 7, 2024
@adamyeats adamyeats requested a review from a team as a code owner June 7, 2024 18:06
@adamyeats adamyeats added type/bug Something isn't working go Pull requests that update Go code labels Jun 7, 2024
Copy link

github-actions bot commented Jun 7, 2024

Use the following command to run this PR with Docker at http://localhost:3000:

docker run --rm -p 3000:3000 grafana/plugin-builds:5d28c1db231ecc3019eacae2cb7055dc6f5010d3pre

@adamyeats adamyeats force-pushed the low-cardinality-strings-temp-fix branch 2 times, most recently from 0a93073 to 90cf1e2 Compare June 11, 2024 12:23
@SpencerTorres
Copy link
Collaborator

I think LowCardinality is mainly used with strings so this should be fine for now. Maybe we can just strip this modifier before calling GetConverter? I don't think it affects the type scanning/reflection once it gets to the client, so if we strip it, it should be effectively the same as String.

@adamyeats
Copy link
Contributor Author

@SpencerTorres

Maybe we can just strip this modifier before calling GetConverter? I don't think it affects the type scanning/reflection once it gets to the client, so if we strip it, it should be effectively the same as String.

That is more or less how the original fix worked, however the GetConverter() function is not actually called by anything (maybe it's just a test helper function? not sure), so we needed to just add a new converter for the time being. As you mention above, we figured that as only strings are supported by LowCardinality out-of-the-box, that we'd be fine with just covering these cases for now.

Unfortunately, this is blocked on some failing tests in CI at the moment, but the test failures are intermittent and do not seem to occur locally, making this quite a tricky one to debug. We'll have more info ASAP, but for now I'm going to move this back to draft.

@adamyeats adamyeats marked this pull request as draft June 14, 2024 15:53
aangelisc
aangelisc previously approved these changes Jul 4, 2024
Copy link
Collaborator

@SpencerTorres SpencerTorres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have thoroughly poked through the plugin and sqlds code, and this is clearly the easiest fix for now. We have users who need LowCardinality(Nullable(String)) so we need to get this merged ASAP.

In the future, I would like to see more flexibility with Converter type in sqlds. Ultimately what we need is a way to strip LowCardinality( + ) from the type string BEFORE it goes to sqlds. This could possibly be done in clickhouse-go, or maybe by making a porxy interface for clickhouse-go's SQL driver, but this is all so complicated. The easiest solution is to add these converters. Perhaps automatically.

It wouldn't hurt to dynamically build the array of converters and add a copy of each converter that is wrapped in LowCardinality. Low Cardinality does not affect clients, only how the data is stored on the server.

A temporary workaround is remove LowCardinality via CAST() in the user's SQL.

TL;DR: This is good, we need this fix ASAP. Not sure what CI issues are failing but let me know if I can help.

@adamyeats adamyeats force-pushed the low-cardinality-strings-temp-fix branch from 90cf1e2 to 48b50a2 Compare July 9, 2024 10:52
@adamyeats adamyeats force-pushed the low-cardinality-strings-temp-fix branch from 48b50a2 to e8c030e Compare July 9, 2024 11:56
@adamyeats adamyeats marked this pull request as ready for review July 9, 2024 13:02
@adamyeats adamyeats requested a review from aangelisc July 9, 2024 13:04
Copy link
Collaborator

@SpencerTorres SpencerTorres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Hopefully we can get a better sqlds API for fixing this, but this works for now. Most LowCardinality types are String.

aangelisc
aangelisc previously approved these changes Jul 9, 2024
Copy link
Contributor

@aangelisc aangelisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - just one nit in the comments!

@adamyeats adamyeats force-pushed the low-cardinality-strings-temp-fix branch from e8c030e to 5d28c1d Compare July 9, 2024 13:55
@adamyeats adamyeats merged commit 2eabdb0 into main Jul 9, 2024
17 checks passed
@adamyeats adamyeats deleted the low-cardinality-strings-temp-fix branch July 9, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend datasource/ClickHouse effort/medium go Pull requests that update Go code type/bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants