Skip to content

Map legacy FLOAT columns to FLOAT64 - #524

Open
kfirco-torq wants to merge 1 commit into
goccy:mainfrom
kfirco-torq:legacy-float-as-float64
Open

kfirco-torq wants to merge 1 commit into
goccy:mainfrom
kfirco-torq:legacy-float-as-float64

Conversation

@kfirco-torq

Copy link
Copy Markdown

Problem

FLOAT is BigQuery's legacy name for FLOAT64. The REST API, the Go client's bigquery.FloatFieldType, and most other client libraries send it for float columns. types.Type.TypeKind mapped FLOAT to GoogleSQL's 32-bit FLOAT, so a table created with a FLOAT column got a 32-bit column, and any FLOAT64 value assigned to it failed:

schema := bigquery.Schema{{Name: "score", Type: bigquery.FloatFieldType}}
// ... create the table, then:
q := client.Query("UPDATE dataset1.scores SET score = @s WHERE TRUE")
q.Parameters = []bigquery.QueryParameter{{Name: "s", Value: 0.3}}
// failed to analyze: Value of type DOUBLE cannot be assigned to score, which has type FLOAT

Literals still worked, because GoogleSQL coerces a literal to the column's type.

Fix

Map FLOAT to DOUBLE, the same as FLOAT64. The reverse mapping and the reported schema type are unchanged.

Tests

TestLegacyFloatColumnIsFloat64 (server/legacy_float_test.go) creates a table through the Go client with a top-level FLOAT column and a FLOAT field inside a RECORD. It assigns a FLOAT64 parameter to both and reads 0.3 back exactly. The test fails on main and passes with this change.

go test ./... passes, except for test/e2e TestClientConformance/ruby. That test fails the same way on main on my machine (ArgumentError: wrong number of arguments, a local Ruby/gem version issue) and has nothing to do with this change.

BigQuery's legacy FLOAT type name (what the REST API and most client
libraries send for a float column) is FLOAT64. Type.TypeKind mapped it
to GoogleSQL's 32-bit FLOAT, so a table created with a FLOAT column got
a 32-bit column, and assigning any FLOAT64 expression to it failed to
analyze:

  Value of type DOUBLE cannot be assigned to score, which has type FLOAT

Map FLOAT to DOUBLE, like FLOAT64. The reverse mapping is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant