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

TD_TIME_RANGEについて

0
Posted at

https://support.treasuredata.com/hc/en-us/articles/360001450828-Supported-Presto-and-TD-Functions
prestoエンジンでサポートされているTD関数について。(部分意訳・要約)

TD_TIME_RANGEとは

データを取ってくる時間の範囲を指定するもの

利用背景

大量データ前提のDBに対して時間範囲を指定しないと、クエリの実行に時間がかかる
そのため、時間範囲を指定し易い関数を提供している

構文

TD_TIME_RANGE(int/long unix_timestamp, # 基準となる日時
              int/long/string start_time, # 範囲開始日(時)
              int/long/string end_time[, string default_timezone = 'UTC']) # 範囲終了日(時) (オプションでタイムゾーンを任意で指定できる)

SELECT ... WHERE TD_TIME_RANGE(time, '2019-01-01 PDT')                 # OK
SELECT ... WHERE TD_TIME_RANGE(time, '2019-01-01', '2019-01-02','PDT') # OK
SELECT ... WHERE TD_TIME_RANGE(time, NULL, '2019-01-01', 'PDT')        # OK
SELECT ... WHERE TD_TIME_RANGE(time, '2019-01-01', NULL, 'PDT')        # OK
SELECT ... WHERE TD_TIME_RANGE(time, '2019-01-01', 'PDT')              # NG
 

ポイント

  • 日時の指定は時刻の省略はできる('YYYY-MM-DD' or 'YYYY-MM-DD hh:flag_mm:ss')
  • 第4引数のtimezoneが効くのは、start_timeとend_timeがtimezoneを持たない値の場合のみ

雑感

なんか変な国旗出てる
一番使用されそうな関数
TreasureDataはデータをtimeカラムに指定してある時間に対して、1時間単位で保存領域を分けて保存しているようなので指定すればそれだけ早く取れる

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?