Wednesday, November 20, 2013

Exporting resultset using Impala and chaining multiple commands


Using Hue's Impala UI, you can download the resultset as CSV or Excel. But Impala shell offers a much more flexible way of exporting resultset as you can specify any delimiter you want. Another benefit over using Hue UI Impala 1.1 is that in the Impala UI, you cannot execute multiple commands (even though it doesn't report a failure). Only the first statement will be executed.

If you want to chain a few commands, create a script file (can be any extension although the convention is to give it a .hql extension).

Put all your sql commands in a file. The last command should select the output you want to save. To execute the file, type:

impala-shell -f myscript.hql -B -o results.txt --output_delimiter='\t';

The above command will invoke the impala shell, and run the commands stored in myscrpt.hql, will output the results to a file called "results.txt", and the field delimited is tab.

Contents of myscript.hql:

drop table if exists mytable; create table mytable (adddate string, rowcount bigint); insert into mytable select to_date(adddate), count(*) from transactionmaster group by to_date(adddate); select * from mytable;


-------------------------------------------------------------------------------------------

You can then view the output in the file you specified, in my case:
cat results.txt

1 comment:

  1. Slots 1x2 Casino & Sports Betting Platform - Royal Ascot
    Slots 1x2 is a casino air jordan 18 retro racer blue my site and show to get air jordan 18 retro yellow sports betting platform offering a simple and secure way of playing and 스포츠토토 분석 사이트 샤오미 betting on the go. It's how to buy air jordan 18 retro yellow suede simple and how can i buy air jordan 18 retro racer blue secure, it's fast,

    ReplyDelete