echo $PATH
export PATH=$PATH:/home/y/bin
export HIVE_HOME=/home/y/libexec/hive
tar -xzvf 2008.tar.gz
hive
-- Creates a new database and stores related data at <hdfs-path>.
hive> CREATE DATABASE ling LOCATION '/user/***/hive';
hive> SHOW DATABASES;
-- Use the database the was just created.
hive> USE ***;
-- Prepare a table;
hive> CREATE TABLE test (a string, b string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LOCATION '/user/***/mydata/test';
CREATE TABLE flight_data(
year INT,
month INT,
day INT,
day_of_week INT,
dep_time INT,
crs_dep_time INT,
arr_time INT,
crs_arr_time INT,
unique_carrier STRING,
flight_num INT,
tail_num STRING,
actual_elapsed_time INT,
crs_elapsed_time INT,
air_time INT,
arr_delay INT,
dep_delay INT,
origin STRING,
dest STRING,
distance INT,
taxi_in INT,
taxi_out INT,
cancelled INT,
cancellation_code STRING,
diverted INT,
carrier_delay STRING,
weather_delay STRING,
nas_delay STRING,
security_delay STRING,
late_aircraft_delay STRING
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
CREATE TABLE airports(
name STRING,
country STRING,
area_code INT,
code STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',';
-- Load data;
hive> LOAD DATA LOCAL INPATH 'data.00000' INTO TABLE test;
hive> LOAD DATA LOCAL INPATH '2008.csv' OVERWRITE INTO TABLE flight_data;hive> LOAD DATA LOCAL INPATH 'airports.csv' OVERWRITE INTO TABLE airports;
SHOW TABLES;
-- Execute a query to retrieve the data.
hive> SELECT * FROM test;
hive> set mapred.job.queue.name=unfunded;
hive> SELECT avg(arr_delay) FROM flight_data WHERE month=1 AND origin='SFO';hive> SELECT * FROM airports LIMIT 10;
hive> CREATE TABLE results AS SELECT name, AVG(arr_delay)
FROM flight_data f
INNER JOIN airports a
ON (f.origin=a.code)
WHERE month=1
GROUP BY name;
hive> SELECT * FROM results LIMIT 10;
-- Clean up the table and database.
hive> DROP TABLE test;
hive> DROP DATABASE ling;
hive --hiveconf mapreduce.map.speculative=true --hiveconf mapreduce.reduce.speculative=true --hiveconf mapreduce.job.acl-view-job="*";
set mapred.reduce.tasks = 500;
set mapreduce.job.queuename=adhoc;
set mapreduce.input.fileinputformat.split.minsize = 2048000000;
set mapreduce.input.fileinputformat.split.maxsize = 2048000000;
use ling;
grant all on database ling to user XXX;
No comments:
Post a Comment