Skip to content

Instantly share code, notes, and snippets.

@kerbelp
Created December 20, 2016 12:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerbelp/8ae08dfafdaa2b4dbb8cdec7072d5d64 to your computer and use it in GitHub Desktop.
Save kerbelp/8ae08dfafdaa2b4dbb8cdec7072d5d64 to your computer and use it in GitHub Desktop.
/* create elb raw logs table with partition */
CREATE EXTERNAL TABLE IF NOT EXISTS elb_logs_raw_partition (
request_timestamp string,
elb_name string,
request_ip string,
request_port int,
backend_ip string,
backend_port int,
request_processing_time double,
backend_processing_time double,
client_response_time double,
elb_response_code string,
backend_response_code string,
received_bytes bigint,
sent_bytes bigint,
request_verb string,
url string,
protocol string,
user_agent string,
ssl_cipher string,
ssl_protocol string
) PARTITIONED BY(
year string,
month string,
day string
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
'serialization.format' = '1','input.regex' = '([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*):([0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) (-|[0-9]*) (-|[0-9]*) ([-0-9]*) ([-0-9]*) \\\"([^ ]*) ([^ ]*) (- |[^ ]*)\\\" (\"[^\"]*\") ([A-Z0-9-]+) ([A-Za-z0-9.-]*)$' )
LOCATION 's3://atom-elb-access-logs/AWSLogs/elasticloadbalancing/us-east-1/';
/* apply the partiotion on the table */
ALTER TABLE elb_logs_raw_partition ADD PARTITION (year='2016',month='12',day='15')
location 's3://atom-elb-access-logs/AWSLogs/elasticloadbalancing/us-east-1/2016/12/15/';
ALTER TABLE elb_logs_raw_partition ADD PARTITION (year='2016',month='12',day='16')
location 's3://atom-elb-access-logs/AWSLogs/elasticloadbalancing/us-east-1/2016/12/16/';
ALTER TABLE elb_logs_raw_partition ADD PARTITION (year='2016',month='12',day='17')
location 's3://atom-elb-access-logs/AWSLogs/elasticloadbalancing/us-east-1/2016/12/17/';
ALTER TABLE elb_logs_raw_partition ADD PARTITION (year='2016',month='12',day='18')
location 's3://atom-elb-access-logs/AWSLogs/elasticloadbalancing/us-east-1/2016/12/18/';
/* see what partitions were applied */
show partitions elb_logs_raw_partition;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment