Skip to content

Commit

Permalink
Support for metadata id in the Prepared responses
Browse files Browse the repository at this point in the history
  • Loading branch information
worryg0d committed Jul 18, 2024
1 parent 974fa12 commit 860880b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 4 additions & 3 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,9 +1394,10 @@ func (c *Conn) executeQuery(ctx context.Context, qry *Query) *Iter {
params.skipMeta = !(c.session.cfg.DisableSkipMetadata || qry.disableSkipMetadata)

frame = &writeExecuteFrame{
preparedID: info.id,
params: params,
customPayload: qry.customPayload,
preparedID: info.id,
params: params,
customPayload: qry.customPayload,
preparedMetadataID: info.request.id,
}

// Set "keyspace" and "table" property in the query if it is present in preparedMetadata
Expand Down
19 changes: 17 additions & 2 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@ type preparedMetadata struct {
keyspace string

table string

// proto v5+
id []byte
}

func (r preparedMetadata) String() string {
Expand All @@ -952,6 +955,10 @@ func (f *framer) parsePreparedMetadata() preparedMetadata {
// TODO: deduplicate this from parseMetadata
meta := preparedMetadata{}

if f.proto > protoVersion4 {
meta.id = copyBytes(f.readShortBytes())
}

meta.flags = f.readInt()
meta.colCount = f.readInt()
if meta.colCount < 0 {
Expand Down Expand Up @@ -1604,23 +1611,31 @@ type writeExecuteFrame struct {

// v4+
customPayload map[string][]byte

// v5+
preparedMetadataID []byte
}

func (e *writeExecuteFrame) String() string {
return fmt.Sprintf("[execute id=% X params=%v]", e.preparedID, &e.params)
}

func (e *writeExecuteFrame) buildFrame(fr *framer, streamID int) error {
return fr.writeExecuteFrame(streamID, e.preparedID, &e.params, &e.customPayload)
return fr.writeExecuteFrame(streamID, e.preparedID, e.preparedMetadataID, &e.params, &e.customPayload)
}

func (f *framer) writeExecuteFrame(streamID int, preparedID []byte, params *queryParams, customPayload *map[string][]byte) error {
func (f *framer) writeExecuteFrame(streamID int, preparedID, preparedMetadataID []byte, params *queryParams, customPayload *map[string][]byte) error {
if len(*customPayload) > 0 {
f.payload()
}
f.writeHeader(f.flags, opExecute, streamID)
f.writeCustomPayload(customPayload)
f.writeShortBytes(preparedID)

if f.proto > protoVersion4 {
f.writeShortBytes(preparedMetadataID)
}

if f.proto > protoVersion1 {
f.writeQueryParams(params)
} else {
Expand Down

0 comments on commit 860880b

Please sign in to comment.