0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[BigQuery]failed with error INVALID_ARGUMENT: Bad int64 value

Posted at

毎日スケジュールしている、BigQuery集計クエリでエラーが発生した

failed with error INVALID_ARGUMENT: Bad int64 value: NULL

int64へのCASTで失敗している。
対象コードは以下

CREATE TEMPORARY FUNCTION
  getValue()
    ...
    return value ? value : 'NULL';
  }

CAST(getValue() AS INT64) AS user_id FROM ~~~

getValue で valueを取り出すが、無理だった場合に 'NULL' を返す仕様。

文字列の 'NULL' は、 INT64 にCASTできないためエラーになっている。

SELECT CAST(NULL, AS INT64) FROM ~~~
-> 通る

SELECT CAST('NULL', AS INT64) FROM ~~~
-> エラー
-> Could not cast literal "NULL" to type INT64

文字列ではないNULLに変えてあげればOKだと思い変更したが、エラー。

CREATE TEMPORARY FUNCTION
  getValue()
    ...
    return value ? value : NULL;
  }
-> Uncaught ReferenceError: NULL is not defined

TEMPORARY FUNCTION は、Javascriptで動いている。
Javascriptでは、 NULL は変数名とみなして null でヌルの挙動をする

スクリーンショット 2020-05-27 19.39.00.png

最終的に以下で修正。再集計完了。

CREATE TEMPORARY FUNCTION
  getValue()
    ...
    return value ? value : null;
  }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?