您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > educoder平台Hive表DDL操作(一)
第1关:Create/Alter/Drop数据库#*********Begin*********#echoCREATEDATABASEIFNOTEXISTStest1LOCATION'/hive/test1'WITHDBPROPERTIES('creator'='John','date'='2019-02-25');ALTERDATABASEtest1SETDBPROPERTIES('creator'='Marry');DROPDATABASEtest1;#*********End*********#测评————————————————————————————————————第2关:Create/Drop/Truncate表#*********Begin*********#echoCREATEDATABASEIFNOTEXISTStest2LOCATION'/hive/test2'WITHDBPROPERTIES('creator'='John','date'='2019-02-25');CREATETABLEIFNOTEXISTStest2.student(SnoINTCOMMENT'studentsno',nameSTRINGCOMMENT'studentname',ageINTCOMMENT'studentage',sexSTRINGCOMMENT'studentsex',scoreSTRUCTChinese:FLOAT,Math:FLOAT,English:FLOATCOMMENT'studentscore')COMMENT'studentsinformationtable'TBLPROPERTIES('creator'='John','date'='2019-02-25');CREATETABLEIFNOTEXISTSstudent_infoLIKEstudent;DROPTABLEIFEXISTSstudent;#*********End*********#测评———————————————————————————————————————第3关:Alter表/列#*********Begin*********#echoCREATEDATABASEIFNOTEXISTStest3LOCATION'/hive/test3'WITHDBPROPERTIES('creator'='John','date'='2019-02-25');CREATETABLEIFNOTEXISTStest3.student(SnoINTCOMMENT'studentsno',nameSTRINGCOMMENT'studentname',ageINTCOMMENT'studentage',sexSTRINGCOMMENT'studentsex',scoreSTRUCTChinese:FLOAT,Math:FLOAT,English:FLOATCOMMENT'studentscore')COMMENT'studentsinformationtable'TBLPROPERTIES('creator'='John','date'='2019-02-25');ALTERTABLEstudentRENAMETOstudent_info;ALTERTABLEstudent_infoCHANGEagestudent_ageINTCOMMENT'studentage';ALTERTABLEstudent_infoADDCOLUMNS(birthdaySTRINGCOMMENT'studentbirthday');#*********End*********#测评———————————————————————————————————————第4关:表分区#*********Begin*********#echoCREATEDATABASEIFNOTEXISTStest4LOCATION'/hive/test4'WITHDBPROPERTIES('creator'='John','date'='2019-02-25');CREATETABLEIFNOTEXISTStest4.student(SnoINTCOMMENT'studentsno',nameSTRINGCOMMENT'studentname',ageINTCOMMENT'studentage',sexSTRINGCOMMENT'studentsex',scoreSTRUCTChinese:FLOAT,Math:FLOAT,English:FLOATCOMMENT'studentscore')COMMENT'studentsinformationtable'PARTITIONEDBY(stu_yearSTRING,subjectSTRING)ROWFORMATDELIMITEDFIELDSTERMINATEDBY'\t'COLLECTIONITEMSTERMINATEDBY','TBLPROPERTIES('creator'='John','date'='2019-02-25');ALTERTABLEstudentADDPARTITION(stu_year='2018',subject='Chinese')LOCATION'/hive/test4/student/2018/Chinese'PARTITION(stu_year='2018',subject='Math')LOCATION'/hive/test4/student/2018/Math';ALTERTABLEstudentPARTITION(stu_year='2018',subject='Math')RENAMETOPARTITION(stu_year='2018',subject='English');ALTERTABLEstudentDROPIFEXISTSPARTITION(stu_year='2018',subject='Chinese');#*********End*********#测评
本文标题:educoder平台Hive表DDL操作(一)
链接地址:https://www.777doc.com/doc-8104838 .html