Skip to content

Instantly share code, notes, and snippets.

@aphlysia
Last active December 26, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aphlysia/7228710 to your computer and use it in GitHub Desktop.
Save aphlysia/7228710 to your computer and use it in GitHub Desktop.
hive note

hive の正規表現

'abc' rlike 'b'

true になる。これは java.util.regex.Matcher.find() を使っているから (rlike の実体は UDFRegExp。詳しくは FunctionRegistry.javaUDFRegExp.java を参照)。もし matches() だと全体が一致しないとマッチしない。

http://docs.oracle.com/javase/jp/7/api/java/util/regex/Matcher.html

join optimization

recipes

  • sqoop で hive に入れるとき
    • NULL を正しく扱うには --null-string "\\\\N" --null-non-string "" をつける

hive へ入る

コマンドラインで hive コマンドを入力。

$ hive

database の選択

どんなデータベースがあるかを見る

show databases;

hoge データベースを使用する

use hoge;

テーブル作成

create table hogedb.fugatable (
  x string,
  y int
)
row format delimited
  fields terminated by '\t'
  lines terminated by '\n'
;

ファイルから hive へデータを入れる

load data local inpath '/tmp/fuga.txt' overwrite into table hogedb.fugatable;

他のテーブルから select した結果を使って新しいテーブルを作成

create table hogedb.Atable as
select * from hogedb.fugatable where y = 1

現在使用しているデータベース内のテーブル一覧を表示

show tables;

その他

select した結果をファイルへ出力

コマンドプロンプトから実行

$ hive -e "select * from hogedb.fugatable where y = 1" > fuga_y1.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment