Two days ago we met a weird error when running a select through BigQuery Python API:

Error : google.api_core.exceptions.BadRequest: 400 Bad int64 value: BA1D

I checked the select SQL but it doesn’t contain any type like “int64”.

After “binary search” in the SQL code, I finally found out that the SQL is actually querying a “view” and the code of this view is like:

SELECT
  cast(col1, int64) AS COL1,
  cast(col2, int64) AS COL2,
FROM
  table1

The correct solution is to change “cast” to “safe_cast”.

Here is the lesson for me: some errors may occur not only in the direct SQL code but in some indirect views…