本专栏已收集头歌大数据所有答案 以供参考
第1关:Create/Alter/Drop 数据库
答案
复制点击测评
代码块:
#********* Begin *********#
echo "
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;
"
#创建数据库test1,位于HDFS的/hive/test1下,创建人creator为John,创建日期date为2019-02-25
#修改数据库test1的创建人为Marry
#删除数据库test1
#********* End *********#
第2关:Create/Drop/Truncate 表
答案
复制点击测评
#********* Begin *********#
echo "
CREATE DATABASE IF NOT EXISTS test2;
CREATE TABLE IF NOT EXISTS test2.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');
CREATE TABLE IF NOT EXISTS student_info LIKE student;
DROP TABLE student;
"
#********* End *********#
第3关:Alter 表/列
答案
复制点击测评
#********* Begin *********#
echo "
CREATE DATABASE IF NOT EXISTS test3;
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');
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 *********#
第4关:表分区
答案
复制点击测评
#********* Begin *********#
echo "
CREATE DATABASE IF NOT EXISTS test4;
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')
PARTITIONED BY (stu_year STRING,subject STRING);
ALTER TABLE student ADD PARTITION (subject='Chinese',stu_year='2018')
LOCATION '/hive/test4/student/2018/Chinese'
PARTITION (subject='Math',stu_year='2018')
LOCATION '/hive/test4/student/2018/Math';
ALTER TABLE student PARTITION (subject='Math',stu_year='2018')
RENAME TO PARTITION (subject='English',stu_year='2018');
ALTER TABLE student DROP IF EXISTS PARTITION (subject='Chinese',stu_year='2018');
"
#********* End *********#