Skip to content

Commit

Permalink
fix: spansql: fix invalid CAST tests
Browse files Browse the repository at this point in the history
A misreading of the spanner docs lead to tests that indicated that
casting `AS ENUM` or `AS PROTO` was valid syntax (despite not specifying
_which_ protobuf enum or message type to cast to). Replace these cases
with ones that validate casting to specific enum/message types.

Thanks to @apstndb for calling this out on googleapis#10945.
  • Loading branch information
dfinkel committed Dec 12, 2024
1 parent 1744aca commit fcbf256
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spanner/spansql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ func TestParseExpr(t *testing.T) {
// Functions
{`STARTS_WITH(Bar, 'B')`, Func{Name: "STARTS_WITH", Args: []Expr{ID("Bar"), StringLiteral("B")}}},
{`CAST(Bar AS STRING)`, Func{Name: "CAST", Args: []Expr{TypedExpr{Expr: ID("Bar"), Type: Type{Base: String}}}}},
{`CAST(Bar AS ENUM)`, Func{Name: "CAST", Args: []Expr{TypedExpr{Expr: ID("Bar"), Type: Type{Base: Enum}}}}},
{`CAST(Bar AS PROTO)`, Func{Name: "CAST", Args: []Expr{TypedExpr{Expr: ID("Bar"), Type: Type{Base: Proto}}}}},
{`CAST(Bar AS fizzle.bit)`, Func{Name: "CAST", Args: []Expr{TypedExpr{Expr: ID("Bar"), Type: Type{Base: Proto, ProtoRef: "fizzle.bit"}}}}},
{`CAST(Bar AS fizzle.bit.baz)`, Func{Name: "CAST", Args: []Expr{TypedExpr{Expr: ID("Bar"), Type: Type{Base: Proto, ProtoRef: "fizzle.bit.baz"}}}}},
{`SAFE_CAST(Bar AS INT64)`, Func{Name: "SAFE_CAST", Args: []Expr{TypedExpr{Expr: ID("Bar"), Type: Type{Base: Int64}}}}},
{`EXTRACT(DATE FROM TIMESTAMP AT TIME ZONE "America/Los_Angeles")`, Func{Name: "EXTRACT", Args: []Expr{ExtractExpr{Part: "DATE", Type: Type{Base: Date}, Expr: AtTimeZoneExpr{Expr: ID("TIMESTAMP"), Zone: "America/Los_Angeles", Type: Type{Base: Timestamp}}}}}},
{`EXTRACT(DAY FROM DATE)`, Func{Name: "EXTRACT", Args: []Expr{ExtractExpr{Part: "DAY", Expr: ID("DATE"), Type: Type{Base: Int64}}}}},
Expand Down

0 comments on commit fcbf256

Please sign in to comment.