forked from tomwhite/hadoop-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
269 additions
and
153 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
! echo; # == select_users; | ||
! echo; # == sample_1_in_4; | ||
! echo; # == sample_1_in_2; | ||
|
||
DROP TABLE IF EXISTS users; | ||
|
||
CREATE TABLE users (id INT, name STRING); | ||
|
||
LOAD DATA LOCAL INPATH 'input/hive/tables/users.txt' | ||
OVERWRITE INTO TABLE users; | ||
|
||
dfs -cat /user/hive/warehouse/users/users.txt; | ||
|
||
DROP TABLE IF EXISTS bucketed_users; | ||
|
||
CREATE TABLE bucketed_users (id INT, name STRING) | ||
CLUSTERED BY (id) INTO 4 BUCKETS; | ||
|
||
DROP TABLE bucketed_users; | ||
|
||
CREATE TABLE bucketed_users (id INT, name STRING) | ||
CLUSTERED BY (id) SORTED BY (id) INTO 4 BUCKETS; | ||
|
||
! echo; # vv select_users; | ||
SELECT * FROM users; | ||
! echo; # ^^ select_users; | ||
|
||
SET hive.enforce.bucketing=true; | ||
|
||
INSERT OVERWRITE TABLE bucketed_users | ||
SELECT * FROM users; | ||
|
||
dfs -ls /user/hive/warehouse/bucketed_users; | ||
|
||
! echo; # vv sample_1_in_4; | ||
SELECT * FROM bucketed_users | ||
TABLESAMPLE(BUCKET 1 OUT OF 4 ON id); | ||
! echo; # ^^ sample_1_in_4; | ||
|
||
! echo; # vv sample_1_in_2; | ||
SELECT * FROM bucketed_users | ||
TABLESAMPLE(BUCKET 1 OUT OF 2 ON id); | ||
! echo; # ^^ sample_1_in_2; | ||
|
||
SELECT * FROM users | ||
TABLESAMPLE(BUCKET 1 OUT OF 4 ON rand()); |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
! echo; # == select_sales_and_things; | ||
! echo; # == inner_join; | ||
! echo; # == left_outer_join; | ||
! echo; # == right_outer_join; | ||
! echo; # == full_outer_join; | ||
! echo; # == select_things_in_sales; | ||
! echo; # == semi_join; | ||
! echo; # == map_join; | ||
|
||
DROP TABLE IF EXISTS sales; | ||
CREATE TABLE sales (name STRING, id INT) | ||
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'; | ||
|
||
DROP TABLE IF EXISTS things; | ||
CREATE TABLE things (id INT, name STRING) | ||
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'; | ||
|
||
LOAD DATA LOCAL INPATH 'input/hive/joins/sales.txt' | ||
OVERWRITE INTO TABLE sales; | ||
|
||
LOAD DATA LOCAL INPATH 'input/hive/joins/things.txt' | ||
OVERWRITE INTO TABLE things; | ||
|
||
! echo; # vv select_sales_and_things; | ||
SELECT * FROM sales; | ||
SELECT * FROM things; | ||
! echo; # ^^ select_sales_and_things; | ||
|
||
! echo; # vv inner_join; | ||
SELECT sales.*, things.* | ||
FROM sales JOIN things ON (sales.id = things.id); | ||
! echo; # ^^ inner_join; | ||
|
||
! echo; # vv left_outer_join; | ||
SELECT sales.*, things.* | ||
FROM sales LEFT OUTER JOIN things ON (sales.id = things.id); | ||
! echo; # ^^ left_outer_join; | ||
|
||
! echo; # vv right_outer_join; | ||
SELECT sales.*, things.* | ||
FROM sales RIGHT OUTER JOIN things ON (sales.id = things.id); | ||
! echo; # ^^ right_outer_join; | ||
|
||
! echo; # vv full_outer_join; | ||
SELECT sales.*, things.* | ||
FROM sales FULL OUTER JOIN things ON (sales.id = things.id); | ||
! echo; # ^^ full_outer_join; | ||
|
||
! echo; # vv select_things_in_sales; | ||
SELECT * | ||
FROM things | ||
WHERE things.id IN (SELECT id from sales); | ||
! echo; # ^^ select_things_in_sales; | ||
|
||
! echo; # vv semi_join; | ||
SELECT * | ||
FROM things LEFT SEMI JOIN sales ON (sales.id = things.id); | ||
! echo; # ^^ semi_join; | ||
|
||
! echo; # vv map_join; | ||
SELECT /*+ MAPJOIN(things) */ sales.*, things.* | ||
FROM sales JOIN things ON (sales.id = things.id); | ||
! echo; # ^^ map_join; | ||
|
||
SELECT /*+ MAPJOIN(things) */ sales.*, things.* | ||
FROM sales LEFT OUTER JOIN things ON (sales.id = things.id); |
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,4 @@ SHOW PARTITIONS logs; | |
|
||
SELECT ts, dt, line | ||
FROM logs | ||
WHERE country='GB'; | ||
WHERE country='GB'; |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
! echo; # == select_stations; | ||
|
||
DROP TABLE IF EXISTS stations; | ||
|
||
CREATE TABLE stations (usaf STRING, wban STRING, name STRING) | ||
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' | ||
WITH SERDEPROPERTIES ( | ||
"input.regex" = "(\\d{6}) (\\d{5}) (.{29}) .*" | ||
); | ||
|
||
LOAD DATA LOCAL INPATH "input/ncdc/metadata/stations-fixed-width.txt" | ||
INTO TABLE stations; | ||
|
||
! echo; # vv select_stations; | ||
SELECT * FROM stations LIMIT 4; | ||
! echo; # ^^ select_stations; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
! echo; # == define_function; | ||
! echo; # == set_value; | ||
! echo; # == set_show_value; | ||
|
||
! echo; # vv define_function; | ||
DESCRIBE FUNCTION length; | ||
! echo; # ^^ define_function; | ||
|
||
! echo; # vv set_value; | ||
SET hive.enforce.bucketing=true; | ||
! echo; # ^^ set_value; | ||
|
||
! echo; # vv set_show_value; | ||
SET hive.enforce.bucketing; | ||
! echo; # ^^ set_show_value; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
! echo; # == sort_by_year; | ||
|
||
DROP TABLE IF EXISTS records2; | ||
|
||
CREATE TABLE records2 (station STRING, year STRING, temperature INT, quality INT) | ||
ROW FORMAT DELIMITED | ||
FIELDS TERMINATED BY '\t'; | ||
|
||
LOAD DATA LOCAL INPATH 'input/ncdc/micro-tab/sample2.txt' | ||
OVERWRITE INTO TABLE records2; | ||
|
||
! echo; # vv sort_by_year; | ||
FROM records2 | ||
SELECT year, temperature | ||
DISTRIBUTE BY year | ||
SORT BY year ASC, temperature DESC; | ||
! echo; # ^^ sort_by_year; |
Oops, something went wrong.