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

Fix non-canonical UUID #117

Merged
merged 1 commit into from
Mar 25, 2024
Merged

Conversation

PauloMiranda98
Copy link
Contributor

@PauloMiranda98 PauloMiranda98 commented Feb 18, 2024

This PR aims to fix non-canonical UUID. The Clickhouse accepts only 8-4-4-4-12 representation of uuid.

Before (master branch):

irb(main):001:0> Model.where(id: 'invalid')
D, [2024-03-23T21:47:16.862694 #29099] DEBUG -- :   Clickhouse Model Load (2.6ms)  SELECT models.* FROM models WHERE models.id = NULL /* loading for pp */ LIMIT 11
=> []                                                                                          
irb(main):002:0> Model.where(id: 'abcd0123456789efdeadbeef01011010')
D, [2024-03-23T21:47:23.081674 #29099] DEBUG -- :   Clickhouse Model Load (3.4ms)  SELECT models.* FROM models WHERE models.id = 'abcd0123456789efdeadbeef01011010' /* loading for pp */ LIMIT 11
=> [#<Model:0x00007fab2ac94140 id: "abcd0123-4567-89ef-dead-beef01011010", byte_string: "">]   
irb(main):003:0> Model.where(id: 'abcd-0123-4567-89ef-dead-beef-0101-1010').first
D, [2024-03-23T21:47:31.434351 #29099] DEBUG -- :   Clickhouse Model Load (2.8ms)  SELECT models.* FROM models WHERE models.id = 'abcd-0123-4567-89ef-dead-beef-0101-1010' ORDER BY models.id ASC LIMIT 1
/home/paulo/ProjetosGithub/clickhouse-activerecord/lib/active_record/connection_adapters/clickhouse/schema_statements.rb:150:in `process_response': Response code: 400: (ActiveRecord::ActiveRecordError)
Code: 53. DB::Exception: Cannot convert string abcd-0123-4567-89ef-dead-beef-0101-1010 to type UUID: while executing 'FUNCTION equals(id : 0, 'abcd-0123-4567-89ef-dead-beef-0101-1010' : 2) -> equals(id, 'abcd-0123-4567-89ef-dead-beef-0101-1010') UInt8 : 3'. (TYPE_MISMATCH) (version 22.8.21.38 (official build))    

After (fix-non-canonical-uuid branch):

irb(main):001:0> Model.where(id: 'invalid')
D, [2024-03-23T21:42:32.408068 #27018] DEBUG -- :   Clickhouse Model Load (2.6ms)  SELECT models.* FROM models WHERE models.id = NULL /* loading for pp */ LIMIT 11
=> []                                                      
irb(main):002:0> Model.where(id: 'abcd0123456789efdeadbeef01011010')
D, [2024-03-23T21:43:02.179635 #27018] DEBUG -- :   Clickhouse Model Load (3.4ms)  SELECT models.* FROM models WHERE models.id = 'abcd0123-4567-89ef-dead-beef01011010' /* loading for pp */ LIMIT 11
=> [#<Model:0x00007f64c54bfc40 id: "abcd0123-4567-89ef-dead-beef01011010", byte_string: "">]
irb(main):003:0> Model.where(id: 'abcd-0123-4567-89ef-dead-beef-0101-1010').first
D, [2024-03-23T21:45:45.011951 #28468] DEBUG -- :   Clickhouse Model Load (4.0ms)  SELECT models.* FROM models WHERE models.id = 'abcd0123-4567-89ef-dead-beef01011010' ORDER BY models.id ASC LIMIT 1
=> #<Model:0x00007fdf93bd1fd0 id: "abcd0123-4567-89ef-dead-beef01011010", byte_string: "">                                                             

This implementation uses same idea of postgresql adapter: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rb

@PauloMiranda98 PauloMiranda98 force-pushed the fix-non-canonical-uuid branch from f7da463 to 015fb6c Compare March 24, 2024 00:34
@PauloMiranda98
Copy link
Contributor Author

What do you think of this change? @PNixx

@PNixx PNixx merged commit d98c938 into PNixx:master Mar 25, 2024
6 checks passed
dmitrytrager added a commit to mayak-bz/clickhouse-activerecord that referenced this pull request May 20, 2024
* upstream: (39 commits)
  fix schema dumper for buffer table
  create table similar to other table
  published 1.0.7 - fix db tasks
  published 1.0.6
  dump indexes to schema
  rebuild and clear indexes
  add support indexes
  Hotfix/rails71 change column (PNixx#132)
  Support functions (PNixx#120)
  Fix precision loss due to JSON float parsing (PNixx#129)
  fix non-canonical uuid (PNixx#117)
  refactoring
  add github workflows, fix spec delete and update, fix injection internal and schema classes for rails 7
  add spec for pr PNixx#123
  Fix wrong method arguments (PNixx#123)
  Fix schema_migrations insert failing (PNixx#122)
  Add support for binary string (PNixx#116)
  add spec for do_execute method before merge PNixx#116
  fix `insert_all` array column
  refactoring connection config
  ...
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