Skip to content
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

feat(spanner/spannertest): add support for bool parameter types #2674

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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