GithubHelp home page GithubHelp logo

batch insert questions about gocqlx HOT 6 CLOSED

scylladb avatar scylladb commented on May 24, 2024
batch insert questions

from gocqlx.

Comments (6)

dahankzter avatar dahankzter commented on May 24, 2024

Can you attach a runnable program exhibiting this?

from gocqlx.

mysunnyshine avatar mysunnyshine commented on May 24, 2024

@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)
}
}

from gocqlx.

dahankzter avatar dahankzter commented on May 24, 2024

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.

from gocqlx.

mysunnyshine avatar mysunnyshine commented on May 24, 2024

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?

from gocqlx.

mysunnyshine avatar mysunnyshine commented on May 24, 2024

solved it by this:
image

from gocqlx.

mmatczuk avatar mmatczuk commented on May 24, 2024

Duplicate of #110

from gocqlx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.