lukasz-antoniak commented on code in PR #1778:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1778#discussion_r1732821630


##########
cassandra_test.go:
##########
@@ -3288,3 +3288,46 @@ func TestQuery_NamedValues(t *testing.T) {
                t.Fatal(err)
        }
 }
+
+func TestBatchKeyspaceField(t *testing.T) {
+       session := createSession(t)
+       defer session.Close()
+
+       if session.cfg.ProtoVersion < protoVersion5 {
+               t.Skip("keyspace for BATCH message is not supported in protocol 
< 5")
+       }
+
+       err := createTable(session, "CREATE TABLE batch_keyspace(id int, value 
text, PRIMARY KEY (id))")

Review Comment:
   You should create table in different keyspace, and then do `b.keyspace = 
"foo"`. Query `session.Query("SELECT * FROM batch_keyspace")` should also 
override the default keyspace.



##########
cassandra_test.go:
##########
@@ -3288,3 +3288,46 @@ func TestQuery_NamedValues(t *testing.T) {
                t.Fatal(err)
        }
 }
+
+func TestBatchKeyspaceField(t *testing.T) {
+       session := createSession(t)
+       defer session.Close()
+
+       if session.cfg.ProtoVersion < protoVersion5 {
+               t.Skip("keyspace for BATCH message is not supported in protocol 
< 5")
+       }
+
+       err := createTable(session, "CREATE TABLE batch_keyspace(id int, value 
text, PRIMARY KEY (id))")
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       ids := []int{1, 2}
+       texts := []string{"val1", "val2"}
+
+       b := session.NewBatch(LoggedBatch)
+       b.Query("INSERT INTO batch_keyspace(id, value) VALUES (?, ?)", ids[0], 
texts[0])
+       b.Query("INSERT INTO batch_keyspace(id, value) VALUES (?, ?)", ids[1], 
texts[1])
+       err = session.ExecuteBatch(b)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       var (
+               id   int
+               text string
+       )
+
+       iter := session.Query("SELECT * FROM batch_keyspace").Iter()
+       defer iter.Close()
+
+       for i := 0; iter.Scan(&id, &text); i++ {
+               if id != ids[i] {

Review Comment:
   Maybe use `require.Equal(t, ...)`.



##########
cassandra_test.go:
##########
@@ -3288,3 +3288,46 @@ func TestQuery_NamedValues(t *testing.T) {
                t.Fatal(err)
        }
 }
+
+func TestBatchKeyspaceField(t *testing.T) {
+       session := createSession(t)
+       defer session.Close()
+
+       if session.cfg.ProtoVersion < protoVersion5 {
+               t.Skip("keyspace for BATCH message is not supported in protocol 
< 5")
+       }
+
+       err := createTable(session, "CREATE TABLE batch_keyspace(id int, value 
text, PRIMARY KEY (id))")
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       ids := []int{1, 2}
+       texts := []string{"val1", "val2"}
+
+       b := session.NewBatch(LoggedBatch)
+       b.Query("INSERT INTO batch_keyspace(id, value) VALUES (?, ?)", ids[0], 
texts[0])

Review Comment:
   I think we should also do the test when one of queries also overrides the 
keyspace.



##########
conn.go:
##########
@@ -1554,6 +1554,10 @@ func (c *Conn) executeBatch(ctx context.Context, batch 
*Batch) *Iter {
                customPayload:         batch.CustomPayload,
        }
 
+       if c.version > protoVersion4 {
+               req.keyspace = c.currentKeyspace

Review Comment:
   The purpose of introducing `keyspace` field in the protocol is not to copy 
default keyspace that we used when establishing connection, but to be able to 
override keyspace on per-statement basis. You need to specify keyspace from 
`Batch` type.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to