-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
#195 - Add Support for Clickhouse #219
#195 - Add Support for Clickhouse #219
Conversation
aea3624
to
00a08fe
Compare
Pull Request Test Coverage Report for Build 10066191359Details
💛 - Coveralls |
Thank you very much for your contribution! Can you check if the |
Sure thing @System-Glitch! And I haven't been able to get the clickhouse dialect to work in |
As you prefer. If you're not willing to do it, this can be done in another issue later on. |
Let me take another shot at it, I'll follow up if I'm not able to get anywhere |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for the transform function with clickhouse please?
I'm sorry to request so many changes, properly supporting clickhouse for this validator is trickier than I expected.
validation/unique.go
Outdated
"(?,?)", | ||
transformedValue, i)) | ||
if paramZeroType == "" { | ||
paramZeroType = clickhouseTypes[reflect.TypeOf(transformedValue)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done once outside the loop. It would be cleaner in my opinion:
var zeroVal T
paramType, ok := clickhouseTypes[reflect.TypeOf(zeroVal)]
You should check if the value is supported, otherwise add an error to the validation context if no Transform
function is provided.
transformedValue
is a gorm.Expr
so your reflect call here will never work if you provide a transform function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if the value is not supported within the clickhouseTypes
map, but there is a Transform function provided, will we be able to determine what paramType
should be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transform is an option for special cases. For example for Postgres it allows to do the following:
UniqueArray("table", "column", func(val int64) clause.Expr {
return gorm.Expr("?::bigint", val)
})
UniqueArray("table", "column", func(val string) clause.Expr {
return gorm.Expr("LOWER(?)", val)
})
So in the case of clickhouse, this would allow developers to cast raw values into special types that we don't support directly.
@System-Glitch No worries! Thank you for all these diligent reviews. Pushed up a few changes, please let me know if this is what you had in mind. I might not be understanding you on the role of the Transformer -- is there a way we can use the Transformer to derive the Clickhouse types we need to indicate, even if the input's Go type has no match? |
var zeroVal T | ||
paramType, ok := clickhouseTypes[reflect.TypeOf(zeroVal)] | ||
if !ok && v.Transform == nil { | ||
return v.db, errors.New("Value type not supported in Clickhouse types, must provide Transform function ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 This is exactly what I had in mind. I may tweak the error message a bit after this is merged.
Thanks @System-Glitch, looks like it needs one more run before I can merge. |
Add support for Clickhouse driver using GORM
Lookup Go Types to find correct Clickhouse Data Types
963d9f4
to
c8d8ff0
Compare
Merged. Thank you very much! 🎉 |
References
Issue(s):#195
Description
Add support for Clickhouse driver using GORM