2
1

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 5 years have passed since last update.

LookMLの日付項目の注意点について

Last updated at Posted at 2019-08-28

自動生成されたLookMLそのままではエラーになるパターンがありましたので、メモ残しておきます。

発生したこと

・テーブルからLookMLを自動生成した場合、テーブルの日付項目名がDate だとSQL発行時にエラーが出てしまう。
・利用DB: bigquery

 1  dimension_group: Date {  ### テーブルの項目名がDateになっている
 2    type: time
 3    timeframes: [
 4      raw,
 5      date,
 6      week,
 7      month,
 8      quarter,
 9      year
10    ]
11    convert_tz: no
12    datatype: date
13    sql: ${TABLE}.[Date] ;;  ### ここの[Date]というところはbigqueryでエラーになる
14  }

上記のLookMLの特徴として、
・1行目 : **dimension_group: Date(テーブル項目名がDate)**になっている
・5行目 : timeframes にも date という同名が存在する
・13行目: sqlのところで Dateが [Date]に自動変換 されている。
     →bigqueryだと[]を使うことができないようで、以下のようにエラーが発生。
日付項目の罠1.PNG

対策方法

 1  dimension_group: Date {  
 2    type: time
 3    timeframes: [
 4      raw,
 5      date,
 6      week,
 7      month,
 8      quarter,
 9      year
10    ]
11    convert_tz: no
12    datatype: date
13    sql: ${TABLE}.Date ;;  ### []を外してlookMLを保存する
14  }

日付項目の罠2.PNG

まとめ

・bigqueryを利用しており、テーブルの日付項目が Date とか week 等になっている場合は LookMLの自動生成コードを修正する必要がある
・bigquery以外であればクエリの項目名に[]があっても処理できるパターンもあるかもですので、その場合は対応不要と思われます。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?