hive DDL操作1
hive DDL操作:
create/drop/alter database
CREATE DATABASE IF NOT EXISTS test1 LOCATION '/hive/test1' WITH DBPROPERTIES('creator'='John','date'='2019-02-25'); ALTER DATABASE test1 SET DBPROPERTIES('creator'='Marry'); DROP DATABASE test1;
create/drop/alter table
#********* Begin *********# echo " CREATE DATABASE IF NOT EXISTS test3 LOCATION '/hive/test3' WITH DBPROPERTIES('creator'='John','date'='2019-02-25'); CREATE TABLE IF NOT EXISTS test3.student( Sno INT COMMENT 'student sno', name STRING COMMENT 'student name', age INT COMMENT 'student age', sex STRING COMMENT 'student sex', score STRUCT<Chinese:FLOAT,Math:FLOAT,English:FLOAT> COMMENT 'student score') COMMENT 'students information table' TBLPROPERTIES ('creator'='John','date'='2019-02-25'); ALTER TABLE student RENAME TO student_info; ALTER TABLE student_info CHANGE age student_age INT COMMENT 'student age'; ALTER TABLE student_info ADD COLUMNS (birthday STRING COMMENT 'student birthday'); " #********* End *********#
create/alter/drop partition
#********* Begin *********# echo " CREATE DATABASE IF NOT EXISTS test4 LOCATION '/hive/test4' WITH DBPROPERTIES('creator'='John','date'='2019-02-25'); CREATE TABLE IF NOT EXISTS test4.student( Sno INT COMMENT 'student sno', name STRING COMMENT 'student name', age INT COMMENT 'student age', sex STRING COMMENT 'student sex', score STRUCT<Chinese:FLOAT,Math:FLOAT,English:FLOAT> COMMENT 'student score') COMMENT 'students information table' PARTITIONED BY (stu_year STRING,subject STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' COLLECTION ITEMS TERMINATED BY ',' TBLPROPERTIES ('creator'='John','date'='2019-02-25'); ALTER TABLE student ADD PARTITION (stu_year='2018',subject='Chinese') LOCATION '/hive/test4/student/2018/Chinese' PARTITION (stu_year='2018',subject='Math') LOCATION '/hive/test4/student/2018/Math'; ALTER TABLE student PARTITION (stu_year='2018',subject='Chinese') RENAME TO PARTITION (stu_year='2018',subject='English'); ALTER TABLE student DROP IF EXISTS PARTITION (stu_year='2018',subject='English'); " #********* End *********#