Frontier:
Hive also uses SQL-like syntax, but as a data warehouse, hive is naturally different from traditional relational databases (MySQL/Oracle) for OLTP. it is used for offline data computing and analysis, without the pursuit of high concurrency/low latency application scenarios. in particular, hive's data is schema on read, which is very free and loose for Data Writing, while reading data is subject to various restrictions. while rmdbs is schema on write, which imposes strict data writing restrictions.
*). Data Import/Export
Let's see how to import the following hive data:
1) Create Database db_hive_test;
Create Database db_hive_test;
In the HDFS directory/user/hive/warehouse
[<Username >@< hostname> ~] # Sudo-u hdfs dfs-ls/user/hive/warehouse
Drwxrwxrwt-root hive 0 2014-07-02 10: 49/user/hive/warehouse/db_hive_test.db
2) create a data table tb_user
CREATE TABLE tb_user ( user_id int, username string, age int, phone string ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t‘ STORED AS TEXTFILE;
3). Data Preparation
Edit data.txt in the workshop. The content is as follows:
[<username>@
4) import data into hive
Load data local inpath '/path/to/data.txt' into Table db_hive_test.tb_user;
5). Data Verification
Select * From tb_user;
Is it easy? But why not use insert into to insert data into a single row? In fact, hive does not support insert and update operations on a single row ).
You can use
#) Load data syntax
Load data [local] inpath 'filepath' [overwrite] into Table tablename [partition (partcol1 = val1, partcol2 = val2...)]
#) Insert select syntax
Insert overwrite/into Table <table_name> [partition (partcol1 = val1, partclo2 = val2...)] select_statement
Note: overwrite rewrite and into append.
6) create a data table tb_newuser;
CREATE TABLE tb_newuser ( user_id int, username string, age int, phone string ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t‘ STORED AS TEXTFILE;
7). Insert select
Insert into Table tb_newuser select * From tb_user;
8). Data Verification
Select * From tb_newuser;
Data Table Structure Replication
Create Table tb_newuser02 like tb_user;
Import when creating a table
Create Table tb_newuser01 select * From tb_user;
How to export data
Export Syntax: insert overwrite/into local directory '<directory> 'select_statement
Insert overwrite local directory '/path/to/data' select * From tb_user;
CAT/path/to/data/1_00_0
Insert overwrite directory '/path/to/data' select * From tb_user;
The difference between local and local is that one is stored locally and the other is stored on HDFS.