-
Notifications
You must be signed in to change notification settings - Fork 123
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
Adding batch wrapper on query builder #239
Conversation
In case you are not interested in adding this to the library, let us know. Then we'll keep it internally. (which would be harder because of missing access to private |
@mmatczuk: Any update for us? What do you think about this MR? |
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.
Just had another closer look at the MR.
- We should try to get rid of changes to
go.mod
. - Also wondering about the commit history. Would be nice to have a clean rebase on top of
scylladb/gocqlx:master
.
go.mod
Outdated
github.com/google/go-cmp v0.5.4 | ||
github.com/maraino/go-mock v0.0.0-20180321183845-4c74c434cd3a |
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.
If possible also this extra dependency: github.com/maraino/go-mock
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 dependency is added because I am using a the go-mock library to mock the session on unit tests
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.
If I get rid of it then I am not sure about the way to mock the session on unit tests.
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.
I removed the tests as they were not really testing anything anyway.
All parts that are used are tested in other unit tests already. We are not really adding something worth testing.
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.
LGTM
@tzach can you have a look? (this is the PR I mentioned on P99 Conference) |
Can you squash your commits to one and add a test please. |
Thx for taking a look @mmatczuk! Can you give us a pointer on how to test this? We had some tests but they basically mocked everything away not really testing anything in the end. So I removed them. Also note, that we are only using existing functionality that has been tested already. |
Hey @mmatczuk, we have rebased and squashed the commits 🙂 |
Ok would be nice to add some docs so that the users know what it does and why. |
@mmatczuk Sry for the wait. I added some tests now. Also realized the execution functions for batching needed an overwrite to complete the user experience. Let me know if there is anything else to change 🙂 |
@tzach: can you plan this in to be checked? |
@avelanarius can you please advise? |
@tzach Happy new year 🥳! Can I draw your attention to this once more? Currently we are using this change with a I'll give this another 2 to 3 weeks and then I'm going to use our clone permanently, changing it's project path so we can import it from our clone without a replace statement. |
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.
added a nit
@tzach: on the last scylla conference you said, that PRs are always welcome. Seeing all the PRs here waiting for months without any attention paints a very different picture. 😞 😞 |
You are right and we should strive to do a better job here - we are slowly going over the backlog and trying to get stuff in. We wish to keep high quality bar so trying not to blindly merge stuff without fully reviewing the changes. That takes time and resources. |
batchx.go
Outdated
} | ||
|
||
// NewBatch creates a new batch operation using defaults defined in the cluster. | ||
func (s *Session) NewBatch(typ gocql.BatchType) *Batch { |
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.
func (s *Session) NewBatch(typ gocql.BatchType) *Batch { | |
func (s *Session) NewBatch(bt gocql.BatchType) *Batch { |
batchx.go
Outdated
// BindStruct binds query named parameters to values from arg using mapper. If | ||
// value cannot be found error is reported. | ||
func (b *Batch) BindStruct(qry *Queryx, arg interface{}) error { | ||
arglist, err := qry.bindStructArgs(arg, nil) |
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.
arglist, err := qry.bindStructArgs(arg, nil) | |
args, err := qry.bindStructArgs(arg, nil) |
batchx.go
Outdated
// BindStruct binds query named parameters to values from arg using mapper. If | ||
// value cannot be found error is reported. |
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.
// BindStruct binds query named parameters to values from arg using mapper. If | |
// value cannot be found error is reported. | |
// BindStruct binds query named parameters to values from arg using a mapper. | |
// If value cannot be found an error is reported. |
batchx.go
Outdated
} | ||
|
||
// ExecuteBatch executes a batch operation and returns nil if successful | ||
// otherwise an error is returned describing the failure. |
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.
// otherwise an error is returned describing the failure. | |
// otherwise an error describing the failure. |
batchx_test.go
Outdated
// Running examples locally: | ||
// make run-scylla | ||
// make run-examples |
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.
remove it, it's not the right place to state it
// make run-scylla | ||
// make run-examples | ||
func TestBatch(t *testing.T) { | ||
cluster := gocqlxtest.CreateCluster() |
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.
t.Parallel() if possible
selectPlaylist := qb.Select("batch_test.playlists").Where(qb.Eq("id")).Query(session) | ||
|
||
t.Run("batch inserts", func(t *testing.T) { | ||
qrys := []batchQry{ |
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.
t.Parallel() if possible
batchx_test.go
Outdated
|
||
b := session.NewBatch(gocql.LoggedBatch) | ||
for _, qry := range qrys { | ||
if r := b.BindStruct(qry.qry, qry.arg); r != nil { |
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.
if r := b.BindStruct(qry.qry, qry.arg); r != nil { | |
if err := b.BindStruct(qry.qry, qry.arg); err != nil { |
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.
applies in entire function
batchx_test.go
Outdated
t.Fatal("select song:", r) | ||
} | ||
if diff := cmp.Diff(gotSong, song); diff != "" { | ||
t.Error("song mismatch", diff) |
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.
t.Error("song mismatch", diff) | |
t.Errorf("expected %v song, got %v, diff: %q", song, gotSong, diff) |
batchx_test.go
Outdated
t.Fatal("select song:", r) | ||
} | ||
if diff := cmp.Diff(gotPlayList, playlist); diff != "" { | ||
t.Error("playList mismatch", diff) |
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.
ditto
Please squash commits into single one with descriptive commit message. Thanks |
@zimnx thx for the review. I applied the requested changes :) |
Note: adding EDIT: adjusted to use |
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.
last two nits, thanks
example_test.go
Outdated
if err != nil { | ||
t.Fatal("create table:", err) | ||
} | ||
|
||
playlistMetadata := table.Metadata{ | ||
Name: "examples.playlists", | ||
Name: keyspace + ".playlists", |
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.
let's be consistent and use fmt.Sprintf here
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.
right, missed those :)
example_test.go
Outdated
Columns: []string{"id", "title", "album", "artist", "song_id"}, | ||
PartKey: []string{"id"}, | ||
SortKey: []string{"title", "album", "artist", "song_id"}, | ||
} | ||
playlistTable := table.New(playlistMetadata) | ||
|
||
// Insert song using query builder. | ||
insertSong := qb.Insert("examples.songs"). | ||
insertSong := qb.Insert(keyspace+".songs"). |
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.
let's be consistent and use fmt.Sprintf here
@zimnx Thanks! Adjusted 😄 |
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.
lgtm, thanks!
Hello,
In the following PR we are adding a Batch wrapper on gocqlx library for binding the object instead of using named columns.
Please have a look and let me know for any questions.
Thanks !