Skip to content

Commit

Permalink
clean up querypb marshall/unmarshall of result
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Dec 20, 2024
1 parent a32c012 commit 12aceda
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 43 deletions.
2 changes: 1 addition & 1 deletion go/sqltypes/proto3.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func Proto3ToResult(qr *querypb.QueryResult) *Result {
Fields: qr.Fields,
RowsAffected: qr.RowsAffected,
InsertID: qr.InsertId,
InsertIDChanged: qr.InsertIdChanged,
InsertIDChanged: qr.InsertIdChanged || qr.InsertId != 0,
Rows: proto3ToRows(qr.Fields, qr.Rows),
Info: qr.Info,
SessionStateChanges: qr.SessionStateChanges,
Expand Down
70 changes: 40 additions & 30 deletions go/sqltypes/proto3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ func TestResult(t *testing.T) {
Type: Float64,
}}
sqlResult := &Result{
Fields: fields,
InsertID: 1,
RowsAffected: 2,
Fields: fields,
InsertID: 1,
InsertIDChanged: true,
RowsAffected: 2,
Rows: [][]Value{{
TestValue(VarChar, "aa"),
TestValue(Int64, "1"),
Expand All @@ -53,9 +54,10 @@ func TestResult(t *testing.T) {
}},
}
p3Result := &querypb.QueryResult{
Fields: fields,
InsertId: 1,
RowsAffected: 2,
Fields: fields,
InsertId: 1,
InsertIdChanged: true,
RowsAffected: 2,
Rows: []*querypb.Row{{
Lengths: []int64{2, 1, 1},
Values: []byte("aa12"),
Expand Down Expand Up @@ -105,36 +107,40 @@ func TestResults(t *testing.T) {
Type: Float64,
}}
sqlResults := []Result{{
Fields: fields1,
InsertID: 1,
RowsAffected: 2,
Fields: fields1,
InsertID: 1,
InsertIDChanged: true,
RowsAffected: 2,
Rows: [][]Value{{
TestValue(VarChar, "aa"),
TestValue(Int64, "1"),
TestValue(Float64, "2"),
}},
}, {
Fields: fields2,
InsertID: 3,
RowsAffected: 4,
Fields: fields2,
InsertID: 3,
InsertIDChanged: true,
RowsAffected: 4,
Rows: [][]Value{{
TestValue(VarChar, "bb"),
TestValue(Int64, "3"),
TestValue(Float64, "4"),
}},
}}
p3Results := []*querypb.QueryResult{{
Fields: fields1,
InsertId: 1,
RowsAffected: 2,
Fields: fields1,
InsertId: 1,
InsertIdChanged: true,
RowsAffected: 2,
Rows: []*querypb.Row{{
Lengths: []int64{2, 1, 1},
Values: []byte("aa12"),
}},
}, {
Fields: fields2,
InsertId: 3,
RowsAffected: 4,
Fields: fields2,
InsertId: 3,
InsertIdChanged: true,
RowsAffected: 4,
Rows: []*querypb.Row{{
Lengths: []int64{2, 1, 1},
Values: []byte("bb34"),
Expand Down Expand Up @@ -176,9 +182,10 @@ func TestQueryReponses(t *testing.T) {
queryResponses := []QueryResponse{
{
QueryResult: &Result{
Fields: fields1,
InsertID: 1,
RowsAffected: 2,
Fields: fields1,
InsertID: 1,
InsertIDChanged: true,
RowsAffected: 2,
Rows: [][]Value{{
TestValue(VarChar, "aa"),
TestValue(Int64, "1"),
Expand All @@ -188,9 +195,10 @@ func TestQueryReponses(t *testing.T) {
QueryError: nil,
}, {
QueryResult: &Result{
Fields: fields2,
InsertID: 3,
RowsAffected: 4,
Fields: fields2,
InsertID: 3,
InsertIDChanged: true,
RowsAffected: 4,
Rows: [][]Value{{
TestValue(VarChar, "bb"),
TestValue(Int64, "3"),
Expand All @@ -208,9 +216,10 @@ func TestQueryReponses(t *testing.T) {
{
Error: nil,
Result: &querypb.QueryResult{
Fields: fields1,
InsertId: 1,
RowsAffected: 2,
Fields: fields1,
InsertId: 1,
InsertIdChanged: true,
RowsAffected: 2,
Rows: []*querypb.Row{{
Lengths: []int64{2, 1, 1},
Values: []byte("aa12"),
Expand All @@ -219,9 +228,10 @@ func TestQueryReponses(t *testing.T) {
}, {
Error: nil,
Result: &querypb.QueryResult{
Fields: fields2,
InsertId: 3,
RowsAffected: 4,
Fields: fields2,
InsertId: 3,
InsertIdChanged: true,
RowsAffected: 4,
Rows: []*querypb.Row{{
Lengths: []int64{2, 1, 1},
Values: []byte("bb34"),
Expand Down
30 changes: 18 additions & 12 deletions go/sqltypes/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func TestCopy(t *testing.T) {
}, {
Type: VarChar,
}},
InsertID: 1,
RowsAffected: 2,
InsertID: 1,
InsertIDChanged: true,
RowsAffected: 2,
Rows: [][]Value{
{TestValue(Int64, "1"), MakeTrusted(Null, nil)},
{TestValue(Int64, "2"), MakeTrusted(VarChar, nil)},
Expand All @@ -76,8 +77,9 @@ func TestTruncate(t *testing.T) {
}, {
Type: VarChar,
}},
InsertID: 1,
RowsAffected: 2,
InsertID: 1,
InsertIDChanged: true,
RowsAffected: 2,
Rows: [][]Value{
{TestValue(Int64, "1"), MakeTrusted(Null, nil)},
{TestValue(Int64, "2"), MakeTrusted(VarChar, nil)},
Expand All @@ -95,8 +97,9 @@ func TestTruncate(t *testing.T) {
Fields: []*querypb.Field{{
Type: Int64,
}},
InsertID: 1,
RowsAffected: 2,
InsertID: 1,
InsertIDChanged: true,
RowsAffected: 2,
Rows: [][]Value{
{TestValue(Int64, "1")},
{TestValue(Int64, "2")},
Expand Down Expand Up @@ -305,8 +308,9 @@ func TestAppendResult(t *testing.T) {
}, {
Type: VarChar,
}},
InsertID: 1,
RowsAffected: 2,
InsertIDChanged: true,
InsertID: 1,
RowsAffected: 2,
Rows: [][]Value{
{TestValue(Int64, "2"), MakeTrusted(VarChar, nil)},
{TestValue(Int64, "3"), TestValue(VarChar, "")},
Expand All @@ -319,8 +323,9 @@ func TestAppendResult(t *testing.T) {
}, {
Type: VarChar,
}},
InsertID: 3,
RowsAffected: 4,
InsertID: 3,
InsertIDChanged: true,
RowsAffected: 4,
Rows: [][]Value{
{TestValue(Int64, "1"), MakeTrusted(Null, nil)},
},
Expand All @@ -332,8 +337,9 @@ func TestAppendResult(t *testing.T) {
}, {
Type: VarChar,
}},
InsertID: 1,
RowsAffected: 6,
InsertID: 1,
InsertIDChanged: true,
RowsAffected: 6,
Rows: [][]Value{
{TestValue(Int64, "1"), MakeTrusted(Null, nil)},
{TestValue(Int64, "2"), MakeTrusted(VarChar, nil)},
Expand Down

0 comments on commit 12aceda

Please sign in to comment.