쿼리 파일로 쿼리 실행하기
파일에 쿼리를 작성하고 파일을 로딩하여 쿼리를 실행하기 위해서 다음의 커맨드를 사용할 수 있습니다.
# impala-shell.sh -i impala-host -f query.sql
Partition Key 지정하기
테이블 생성시 Partition Key를 지정하려면 다음과 같이 테이블을 생성합니다.
create table logs ( field1 string, field2 string, field3 string ) partitioned by (year string, month string , day string, host string) row format delimited fields terminated by ','
데이터를 INSERT할 때에는 다음과 같이 Partition Key를 지정할 수 있습니다.
insert into logs partition (year="2013", month="07", day="28", host="host1") values ("foo","foo","foo");
External Table 생성하기
Managed Table 대신 저장 위치를 별도로 지정하여 생성할 수 있는 External Table을 생성하려면 다음의 쿼리를 실행합니다.
create external table logs ( field1 string, field2 string, field3 string ) partitioned by (year string, month string, day string, host string) row format delimited fields terminated by ',' location '/user/impala/data/logs';
이 경우 새로운 파티션을 추가하기 위해서는 다음의 쿼리를 실행할 수 있습니다.
alter table logs add partition (year="2013",month="07",day="28",host="host1")
이제 생성한 파티션에 데이터를 적재합니다.
$ cat >dummy_log_data bar,baz,bletch $ hdfs dfs -put dummy_log_data /user/impala/data/logs/year=2013/month=07/day=28/host=host1
이제 마지막으로 Refresh를 실행합니다.
refresh log_type; select * from log_type limit 100; +--------+--------+--------+------+-------+-----+-------+ | field1 | field2 | field3 | year | month | day | host | +--------+--------+--------+------+-------+-----+-------+ | bar | baz | bletch | 2013 | 07 | 28 | host1 | | bar | baz | bletch | 2013 | 08 | 01 | host1 | | bar | baz | bletch | 2013 | 07 | 29 | host1 | | bar | baz | bletch | 2013 | 07 | 28 | host2 | +--------+--------+--------+------+-------+-----+-------+