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

batch insert questions #123

Closed
mysunnyshine opened this issue Nov 8, 2019 · 6 comments
Closed

batch insert questions #123

mysunnyshine opened this issue Nov 8, 2019 · 6 comments

Comments

@mysunnyshine
Copy link

I write the Batch Function for testing batch.
However, the values are not expected. I expect the value [0 1 2 1 2 3], but [1 2 3 1 2 3]
image
image

@dahankzter
Copy link
Contributor

Can you attach a runnable program exhibiting this?

@mysunnyshine
Copy link
Author

mysunnyshine commented Nov 8, 2019

@dahankzter

func BenchmarkBatchSet(b *testing.B) {
var batchCols = []string{"id", "first_name", "last_name"}
session := CreateSession(b)
defer session.Close()
msetNum := 2
if err := ExecStmt(session, benchPersonSchema); err != nil {
b.Fatal(err)
}
bt := qb.Batch();
for i := 0; i < msetNum; i++ {
bt.Add(qb.Insert("gocqlx_test.bench_person").Columns(batchCols...))
}
stmt, names := bt.ToCql()
q := gocqlx.Query(session.Query(stmt), names)
for i := 0; i < msetNum; i++ {
q.BindStruct(&benchPerson{
ID: i,
FirstName: strconv.Itoa(i + 1),
LastName: strconv.Itoa(i + 2),
})
}
fmt.Println("query = ", q.Query)
defer q.Release()
b.ResetTimer()
if e1 := q.Exec(); e1 != nil {
b.Fatal(e1)
}
}

@dahankzter
Copy link
Contributor

So let me see if I get this straight. You want to execute the same query several times in a batch with different values for each query in the batch.
Correct?

Since Batch is effectively treats many queries masked as a single query what bind does is that it applies the same bound values for each query in the batch. Every Bind rebinds the values to the new values and applies them to the entire batch.
This behavior is consistent with how Bind works for non-batch queries.

I guess arguments could be made for changing the behavior but I have no idea how complicated an implementation would be and changing the API is probably not a good idea so some other method would be needed in that case.

@mysunnyshine
Copy link
Author

So let me see if I get this straight. You want to execute the same query several times in a batch with different values for each query in the batch.
Correct?

Since Batch is effectively treats many queries masked as a single query what bind does is that it applies the same bound values for each query in the batch. Every Bind rebinds the values to the new values and applies them to the entire batch.
This behavior is consistent with how Bind works for non-batch queries.

I guess arguments could be made for changing the behavior but I have no idea how complicated an implementation would be and changing the API is probably not a good idea so some other method would be needed in that case.

Simply, I just want to test the batch command like mget or mset in redis.
Could you please give me some example?

@mysunnyshine
Copy link
Author

solved it by this:
image

@mmatczuk
Copy link
Contributor

mmatczuk commented Nov 9, 2019

Duplicate of #110

@mmatczuk mmatczuk marked this as a duplicate of #110 Nov 9, 2019
@mmatczuk mmatczuk closed this as completed Nov 9, 2019
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

No branches or pull requests

3 participants