Skip to content

Commit

Permalink
feat(spanner/spannertest): add support for bool parameter types (#2674)
Browse files Browse the repository at this point in the history
I tested this against my own codebase as well and it resolved the issue for both my code as well as the integration tests. Previously this would fail with:

```
spanner: code = "Unknown", desc = "rpc error: code = Unknown desc = unsupported well-known type value kind *structpb.Value_BoolValue"
```
  • Loading branch information
sporkmonger committed Sep 8, 2020
1 parent 92af398 commit 24f633b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spanner/spannertest/db_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ func compareVals(x, y interface{}) int {
}

var (
boolType = spansql.Type{Base: spansql.Bool}
int64Type = spansql.Type{Base: spansql.Int64}
float64Type = spansql.Type{Base: spansql.Float64}
stringType = spansql.Type{Base: spansql.String}
Expand All @@ -664,6 +665,8 @@ var (
func (ec evalContext) colInfo(e spansql.Expr) (colInfo, error) {
// TODO: more types
switch e := e.(type) {
case spansql.BoolLiteral:
return colInfo{Type: boolType}, nil
case spansql.IntegerLiteral:
return colInfo{Type: int64Type}, nil
case spansql.StringLiteral:
Expand Down
8 changes: 8 additions & 0 deletions spanner/spannertest/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ func TestTableData(t *testing.T) {
{"Sam"},
},
},
{
`SELECT MAX(Name) FROM Staff WHERE Cool = @p1 LIMIT 1`,
queryParams{"p1": boolParam(true)},
[][]interface{}{
{"Teal'c"},
},
},
{
`SELECT MIN(Name) FROM Staff`,
nil,
Expand Down Expand Up @@ -881,6 +888,7 @@ func floatV(f float64) *structpb.Value { return &structpb.Value{K
func boolV(b bool) *structpb.Value { return &structpb.Value{Kind: &structpb.Value_BoolValue{b}} }
func nullV() *structpb.Value { return &structpb.Value{Kind: &structpb.Value_NullValue{}} }

func boolParam(b bool) queryParam { return queryParam{Value: b, Type: boolType} }
func stringParam(s string) queryParam { return queryParam{Value: s, Type: stringType} }
func intParam(i int64) queryParam { return queryParam{Value: i, Type: int64Type} }
func floatParam(f float64) queryParam { return queryParam{Value: f, Type: float64Type} }
Expand Down
2 changes: 2 additions & 0 deletions spanner/spannertest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ func parseQueryParam(v *structpb.Value, typ *spannerpb.Type) (queryParam, error)
return queryParam{}, fmt.Errorf("unsupported well-known type value kind %T", v)
case *structpb.Value_NullValue:
return queryParam{Value: nil}, nil // TODO: set a type?
case *structpb.Value_BoolValue:
return queryParam{Value: v.BoolValue, Type: boolType}, nil
case *structpb.Value_NumberValue:
return queryParam{Value: v.NumberValue, Type: float64Type}, nil
case *structpb.Value_StringValue:
Expand Down

0 comments on commit 24f633b

Please sign in to comment.