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

Add support for Map datatype #144

Merged
merged 5 commits into from
Aug 16, 2024
Merged

Conversation

danielwestendorf
Copy link
Contributor

@danielwestendorf danielwestendorf commented Jul 24, 2024

Clickhouse Datatype Docs

Adapted from this commit but adapted to be similar to the existing Array datatype implementation.

[Clickhouse Datatype Docs](https://clickhouse.com/docs/en/sql-reference/data-types/map)

Adapted from [this commit](0d9db1d) but adapted to be similar to the existing `Array` datatype implementation. The most significant change from the previous implementation and this one is that migrations are defined as such:

```diff
-- t.string "field_name", map: :string, null: false
++ t.string "field_name, map: true, null: false
```

This allows us to rely upon the other datatypes already defined as the `@subtype` by specifying the column type in normal rails style.
@danielwestendorf danielwestendorf requested a review from PNixx July 25, 2024 15:43
`Code: 26. DB::ParsingException: Cannot parse quoted string: expected opening quote ''', got '"': while converting '{"a":"b"}' to Map(String, String):  at row 0: While executing ValuesBlockInputFormat. (CANNOT_PARSE_QUOTED_STRING) (version 23.9.6.20 (official build))`

```ruby
value = {"a"=>"b"}
 '{' + value.map { |k, v| "#{quote(k)}: #{quote(v)}" }.join(', ') + '}'
=> "{'a': 'b'}"
JSON.generate(value, quirks_mode: true)
=> "{\"a\":\"b\"}"
```
@danielwestendorf
Copy link
Contributor Author

I think this PR needs to bake a bit more. I'm reverting to draft for now.

@danielwestendorf danielwestendorf marked this pull request as draft July 26, 2024 03:32
@danielwestendorf danielwestendorf marked this pull request as ready for review August 8, 2024 02:26
@danielwestendorf
Copy link
Contributor Author

This has been working well for us.

@PNixx PNixx merged commit ada3cd2 into PNixx:master Aug 16, 2024
6 checks passed
syabruk pushed a commit to machinio/clickhouse-activerecord that referenced this pull request Aug 19, 2024
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