Impala-shell Import and Export
Parameter description:
-q Query (--query=query) executes queries from the command line without entering Impala-shell
-d default_db (--database=default_db) Specify database
-b (--delimited) to format the output
--output_delimiter=character specifying delimiters
--print_header Print column names
-f Query_file (--query_file=query_file) executes the query file, separated by semicolons
-o filename (--output_file filename) Results output to the specified file
1. Export
1.1 Exporting results to CSV
Impala-shell-q "Select Id,price,name,dtime from Config.price_test limit 3"-B--output_delimiter= ","--print_header-o/V Ar/testimpalaout.csv
1.2 Exporting results to excle
Impala-shell-q "Select Id,price,name,dtime from Config.price_test limit 3"-B--output_delimiter= "\ T"--print_header-o/ Var/testimpalaout.xlsx
2. Import
2.1 Hadoop Create Folder
Hadoop fs-mkdir/tmp/price_txternal
2.2 Local File Upload Hadoop
Hadoop fs-put/var/testimpalaout.csv/tmp/price_txternal
2.3 Creating temporary tables (no partitions, plain text tables)
Impala-shell, enter Impala-shell database, (delimiter, custom)
CREATE TABLE Config.price_test_ls (
ID INT,
Price DOUBLE,
Name VARCHAR (200),
Dtime TIMESTAMP
)
Row format delimited terminated by ', '
Location '/tmp/price_txternal ';
2.4 Importing a partitioned table
INSERT into Config.price_test PARTITION (day = 20170701, MINUTE = cast (' 0000 ' as char (4)))
SELECT
Id
Price
NAME,
Dtime
From
Config.price_test_ls
2.5 Deleting a temporary table
drop table Config.price_test_ls;