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

#195 - Add Support for Clickhouse #219

Merged

Conversation

AidanKenney
Copy link
Contributor

References

Issue(s):#195

Description

Add support for Clickhouse driver using GORM

@AidanKenney AidanKenney force-pushed the issue-195-add-clickhouse-dialect branch 2 times, most recently from aea3624 to 00a08fe Compare July 15, 2024 19:09
@System-Glitch System-Glitch self-requested a review July 16, 2024 07:44
@coveralls
Copy link

coveralls commented Jul 16, 2024

Pull Request Test Coverage Report for Build 10066191359

Details

  • 37 of 45 (82.22%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 97.36%

Changes Missing Coverage Covered Lines Changed/Added Lines %
database/dialect/clickhouse/clickhouse.go 0 3 0.0%
validation/unique.go 37 42 88.1%
Totals Coverage Status
Change from base Build 10061155490: -0.1%
Covered Lines: 6233
Relevant Lines: 6402

💛 - Coveralls

@System-Glitch
Copy link
Member

System-Glitch commented Jul 16, 2024

Thank you very much for your contribution! Can you check if the Exists/Unique validator works with clickhouse please?
I don't think it will because of the VALUES syntax. It's not a problem for now, another issue will be created if needed.

@System-Glitch System-Glitch added the feature request Request for new feature implementation label Jul 16, 2024
@AidanKenney
Copy link
Contributor Author

Sure thing @System-Glitch! And I haven't been able to get the clickhouse dialect to work in unique_test.go yet, I think the tests will need a bit of refactoring for it to work. Do you want me to try to get that working before moving ahead with this?

@System-Glitch
Copy link
Member

Sure thing @System-Glitch! And I haven't been able to get the clickhouse dialect to work in unique_test.go yet, I think the tests will need a bit of refactoring for it to work. Do you want me to try to get that working before moving ahead with this?

As you prefer. If you're not willing to do it, this can be done in another issue later on.

@AidanKenney
Copy link
Contributor Author

Let me take another shot at it, I'll follow up if I'm not able to get anywhere

validation/unique_test.go Outdated Show resolved Hide resolved
Copy link
Member

@System-Glitch System-Glitch left a 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 Show resolved Hide resolved
validation/unique.go Outdated Show resolved Hide resolved
validation/unique.go Outdated Show resolved Hide resolved
"(?,?)",
transformedValue, i))
if paramZeroType == "" {
paramZeroType = clickhouseTypes[reflect.TypeOf(transformedValue)]
Copy link
Member

@System-Glitch System-Glitch Jul 21, 2024

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@AidanKenney
Copy link
Contributor Author

@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?

validation/unique.go Outdated Show resolved Hide resolved
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 ")
Copy link
Member

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.

validation/unique.go Outdated Show resolved Hide resolved
@AidanKenney
Copy link
Contributor Author

Thanks @System-Glitch, looks like it needs one more run before I can merge.

@AidanKenney AidanKenney force-pushed the issue-195-add-clickhouse-dialect branch from 963d9f4 to c8d8ff0 Compare July 23, 2024 20:50
@System-Glitch System-Glitch merged commit 742227f into go-goyave:master Jul 24, 2024
4 checks passed
@System-Glitch
Copy link
Member

Merged. Thank you very much! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new feature implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants