Last active
June 6, 2019 16:25
-
-
Save maulvi/f39a47b712a8c991724a76cceaecb69b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Memuat data ke dalam Apache pig dari sistem file (HDFS / Lokal) menggunakan operator LOAD. | |
a = LOAD 'test_set_tweets.txt' AS (id:chararray, ts:chararray, tweet:chararray); | |
Fungsi FLATTEN(TOKENIZE ini digunakan untuk split string dan LOWER mengubah semua karakter dalam string menjadi huruf kecil. | |
b = foreach a generate tweet, FLATTEN(TOKENIZE(LOWER(tweet))) as tokens; | |
Fungsi yang digunakan memfilter string yang diawali dengan hashtag | |
c = filter b by tokens MATCHES '#\\s*(\\w+)'; | |
Operator GROUP digunakan untuk mengelompokkan data dalam satu atau beberapa string. | |
d = group c by tokens; | |
Operator COUNT untuk menghitung string | |
e = foreach d generate group as tokens, COUNT(c) as cnt; | |
Mengurutkan data dari terbesar ke terkecil | |
f = order e by cnt desc; | |
menyimpan dengan variabel bernama "output" | |
store f into 'output'; | |
Fungsi ini digunakan untuk menampilkan data | |
dump f; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment