hive create table statement

1. In the hive-site.xml file installation package /apache-hive-2.3.4-bin/conf hive's path configuration:
<Property>
<name> hive.support.sql11.reserved.keywords </ name>
<value> false </ value>
</ Property>
this parameter is off the table field has created key field. You can also set sql statement before
the SET hive.support.sql11.reserved.keywords = false;
sql statement keywords to use `,和mysql一样。<br/>例如: <br/>CREATE TABLE IF NOT EXISTS traffic.monitor_flow_action( <br/>date` String,
monitor_id String,
the camera_ID String,
CAR String,
ACTION_TIME String,
Speed String,
road_id String,
String area_id
)
the ROW the FORMAT the DELIMITED the FIELDS TERMINATED BY '\ T';

2. Load the data into the hive from hdfs table, where it finished loading hdfs automatically deleted (in fact, mv, and moved to the / user / hive / warehouse down).
For example:
the CREATE TABLE traffic.monitor_flow_action the IF the NOT EXISTS (
dateString,
monitor_id String,
the camera_ID String,
CAR String,
ACTION_TIME String,
Speed String,
road_id String,
area_id String
)
the ROW the FORMAT the DELIMITED the FIELDS TERMINATED BY '\ T';
Load the inpath Data 'HDFS : // mycluster / myfile / monitor_flow_action ' into table traffic.monitor_flow_action;

CREATE TABLE IF NOT EXISTS traffic.monitor_camera_info(
monitor_id string ,
camera_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ;
load data inpath 'hdfs://mycluster/myfile/monitor_camera_info' into table traffic.monitor_camera_info;

从本地路径下加载文件数据到hive表中:
CREATE TABLE IF NOT EXISTS traffic.monitor_flow_action(
date string ,
monitor_id string ,
camera_id string ,
car string ,
action_time string ,
speed string ,
road_id string,
area_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ;
load data local inpath '/usr/java/monitor_flow_action' into table traffic.monitor_flow_action;

CREATE TABLE IF NOT EXISTS traffic.monitor_camera_info(
monitor_id string ,
camera_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ;
load data local inpath '/usr/java/monitor_camera_info' into table traffic.monitor_camera_info;

Note: The syntax to load data load data from two hdfs plus local data and not a local, a local.
Can sql file into a file such as testCreateHiveSql.sql, then use the command: hive -f testCreateHiveSql.sql perform to create tables and load data

Full column shows:
SET = hive.support.sql11.reserved.keywords to false;

CREATE TABLE IF NOT EXISTS traffic.monitor_flow_action(
date string ,
monitor_id string ,
camera_id string ,
car string ,
action_time string ,
speed string ,
road_id string,
area_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ;

load data local inpath '/root/test/monitor_flow_action' into table traffic.monitor_flow_action;

CREATE TABLE IF NOT EXISTS traffic.monitor_camera_info(
monitor_id string ,
camera_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ;

load data local inpath '/root/test/monitor_camera_info' into table traffic.monitor_camera_info;

Guess you like

Origin blog.51cto.com/14159501/2445549