-
Notifications
You must be signed in to change notification settings - Fork 642
Support of keyspace field for BATCH message
#1778
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also do the test when one of queries also overrides the keyspace.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I see from the proto 5 spec we can not override the keyspace for the specific query in the Batch, only for the Batch itself.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that my comment might not be understandable. You can simulate hardcoding keyspace in CQL string itself. But, yeah it is not a very useful test indeed. |
||
| 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] { | ||
|
||
| t.Fatalf("expected id %v, got %v", ids[i], id) | ||
| } | ||
|
|
||
| if text != texts[i] { | ||
| t.Fatalf("expected text %v, got %v", texts[i], text) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
||
| } | ||
|
|
||
| stmts := make(map[string]string, len(batch.Entries)) | ||
|
|
||
| for i := 0; i < n; i++ { | ||
|
|
||
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.
You should create table in different keyspace, and then do
b.keyspace = "foo". Querysession.Query("SELECT * FROM batch_keyspace")should also override the default keyspace.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 has been addressed in #1822.