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 で JSON_EXTRACT_PATH_TEXT 関数が通るようにする

Posted at

Redshiftベースのクエリー資産をBigQueryで活かしたいが、書き換えを最小限にしたい。
Redshiftの JSON_EXTRACT_PATH_TEXT に近いのは JSON_VALUE であったが第2引数をどうしても自動処理できなかった。
仕方ないので1階層だけ拾えればよかったので JavaScript UDF で対処した。


CREATE TEMPORARY FUNCTION JSON_EXTRACT_PATH_TEXT(json_string STRING, path_elem STRING, null_if_invalid BOOLEAN)
RETURNS STRING
LANGUAGE js
as """
  return JSON.parse(json_string)[path_elem];
""";

JSON_EXTRACT_PATH_TEXT を完全再現するには最大7つの引数を受け取る(ANY TYPE として STRINGでもBOOLでも受け付ける)ようにして、分岐を書かないとイケないのでそこまではしなかった。
こんな感じでRedshift固有の関数をUDFで揃えていけば移行が捗るか?

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?