LoginSignup
0
0

More than 5 years have passed since last update.

PrestoとHiveのクエリだけでリストを作ってみる

Posted at

概要

クエリを書いている際、実際のテーブルは存在しないが、仮のてリストを作ってJOINしたい場合などあったので、調べた内容をメモしておく。
※TreasureDataで実行している話なので、HIVEのバージョンがもっと上なら・・・などについては触れないことにする

Prestoで作ってみる

WITH rates AS (
  SELECT * FROM (
    VALUES
      ('2018-01', 0.92, 0.195),
      ('2018-02', 0.92, 0.195),
      ('2018-03', 0.92, 0.195),
      ('2018-04', 0.92, 0.195),
      ('2018-05', 0.92, 0.195),
      ('2018-06', 0.92, 0.195),
      ('2018-07', 0.92, 0.195),
      ('2018-08', 0.92, 0.195),
      ('2018-09', 0.92, 0.195),
      ('2018-10', 0.92, 0.195),
      ('2018-11', 0.92, 0.195),
      ('2018-12', 0.92, 0.195),
      ('2019-01', 0.92, 0.195),
      ('2019-02', 0.92, 0.195),
      ('2019-03', 0.92, 0.195)
  ) AS t (month, tweek, rate)
)
SELECT * FROM rates;

Hiveで作ってみる

HIVEで、「VALUES」が使えなかったので、どうにもならず普通にSELECTで書いてみる・・・
とりあえず、実行はできたが非常に微妙・・・何かいいやり方他にないのかな・・・

WITH rates AS (
  SELECT * FROM (
    SELECT '2018-01' as month, '0.92' as tweak, '0.195' as rate
    UNION ALL
    SELECT '2018-02' as month, '0.92' as tweak, '0.195' as rate
  ) AS t1
)
SELECT * FROM rates;
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