[Hive - LanguageManual] DML: Load, Insert, Update, Delete
2015-01-25 12:41
323 查看
LanguageManualDML
HiveDataManipulationLanguage
TherearemultiplewaystomodifydatainHive:
INSERT
Loadingfilesintotables
Hivedoesnotdoanytransformationwhileloadingdataintotables.Loadoperationsarecurrentlypurecopy/move(纯复制,移动)operationsthatmovedatafilesintolocationscorrespondingtoHivetables.Syntax语法
Loadoperationsarecurrentlypurecopy/moveoperationsthatmovedatafilesintolocationscorrespondingtoHivetables.
filepathcanbe:
arelativepath,suchas
project/data1
anabsolutepath,suchas
/user/hive/project/data1
afullURIwithschemeand(optionally)anauthority,suchas
hdfs://namenode:9000/user/hive/project/data1
Thetargetbeingloadedtocanbeatableorapartition.Ifthetableispartitioned,thenonemustspecifyaspecificpartitionofthetablebyspecifyingvaluesforallofthepartitioningcolumns.
filepathcanrefertoafile(inwhichcaseHivewillmovethefileintothetable)oritcanbeadirectory(inwhichcaseHivewillmoveallthefileswithinthatdirectoryintothetable).Ineithercase,filepathaddressesasetoffiles.
IfthekeywordLOCALisspecified,then:
theloadcommandwilllookforfilepathinthelocalfilesystem.Ifarelativepathisspecified,itwillbeinterpretedrelativetotheuser'scurrentworkingdirectory.TheusercanspecifyafullURIforlocalfilesaswell-forexample:
file:///user/hive/project/data1
theloadcommandwilltrytocopyallthefilesaddressedbyfilepathtothetargetfilesystem.Thetargetfilesystemisinferredbylookingatthelocationattributeofthetable.Thecopieddatafileswillthenbemovedtothetable.
IfthekeywordLOCALisnotspecified,thenHivewilleitherusethefullURIoffilepath,ifoneisspecified,orwillapplythefollowingrules:
Ifschemeorauthorityarenotspecified,Hivewillusetheschemeandauthorityfromthehadoopconfigurationvariable
fs.default.namethatspecifiestheNamenodeURI.
Ifthepathisnotabsolute,thenHivewillinterpretitrelativeto
/user/<username>
Hivewillmovethefilesaddressedbyfilepathintothetable(orpartition)
IftheOVERWRITEkeywordisusedthenthecontentsofthetargettable(orpartition)willbedeletedandreplacedbythefilesreferredtobyfilepath;otherwisethefilesreferredbyfilepathwillbeaddedtothetable.
Notethatifthetargettable(orpartition)alreadyhasafilewhosenamecollides(冲突)withanyofthefilenamescontainedinfilepath,thentheexistingfilewillbereplacedwiththenewfile.
Notes
filepathcannotcontainsubdirectories.(filepath可以是目录也可以是文件,但是不能包含子目录)
IfthekeywordLOCALisnotgiven,filepathmustrefertofileswithinthesamefilesystemasthetable's(orpartition's)location.
Hivedoessomeminimalcheckstomakesurethatthefilesbeingloadedmatchthetargettable.Currentlyitchecksthatifthetableisstoredinsequencefileformat,thefilesbeingloadedarealsosequencefiles,andviceversa.
Abugthatpreventedloadingafilewhenitsnameincludesthe"+"characterisfixedinrelease0.13.0(
Pleaseread
InsertingdataintoHiveTablesfromqueries
QueryResultscanbeinsertedintotablesbyusingtheinsertclause.Syntax语法
INSERTOVERWRITEwilloverwriteanyexistingdatainthetableorpartition
unless
IFNOTEXISTSisprovidedforapartition(asofHive
INSERTINTOwillappendtothetableorpartition,keepingtheexistingdataintact(完整无缺的).(Note:INSERTINTOsyntaxisonlyavailablestartinginversion0.8.)
AsofHive
INSERTINTObehaviorintoanimmutabletableisdisallowedifanydataisalreadypresent,althoughINSERTINTOstillworksiftheimmutabletableisempty.ThebehaviorofINSERTOVERWRITEisnotaffectedbythe"immutable"tableproperty.(INSERTOVERWRITE不受immutable属性的限制)
Animmutabletableisprotectedagainstaccidentalupdatesduetoascriptloadingdataintoitbeingrunmultipletimesbymistake.(避免多次插入和修改)Thefirstinsertintoanimmutabletablesucceedsandsuccessiveinsertsfail,resultinginonlyonesetofdatainthetable,insteadofsilentlysucceedingwithmultiplecopiesofthedatainthetable.
Insertscanbedonetoatableorapartition.Ifthetableispartitioned,thenonemustspecifyaspecificpartitionofthetablebyspecifyingvaluesforallofthepartitioningcolumns.
Multipleinsertclauses(alsoknownasMultiTableInsert)canbespecifiedinthesamequery.
Theoutputofeachoftheselectstatementsiswrittentothechosentable(orpartition).CurrentlytheOVERWRITEkeywordismandatory(强制的)andimplies(暗示,说明)thatthecontentsofthechosentableorpartitionarereplacedwiththeoutputofcorresponding(适当的)selectstatement.
Theoutputformatandserializationclassisdeterminedbythetable'smetadata(asspecifiedviaDDLcommandsonthetable).
Asof
Notes
MultiTableInsertsminimizethenumberofdatascansrequired.Hivecaninsertdataintomultipletablesbyscanningtheinputdatajustonce(andapplyingdifferentqueryoperators)totheinputdata.
Startingwith
DynamicPartitionInserts动态分区插入
Versioninformation
Icon
ThisinformationreflectsthesituationinHive0.12;dynamicpartitioninsertswereaddedinHive0.6.
Inthedynamicpartitioninserts,userscangivepartialpartitionspecifications,whichmeansjustspecifyingthelistofpartitioncolumnnamesinthePARTITIONclause.Thecolumnvaluesareoptional.Ifapartitioncolumnvalueisgiven,wecallthisastaticpartition,otherwiseitisadynamicpartition.Eachdynamicpartitioncolumnhasacorrespondinginputcolumnfromtheselectstatement.Thismeansthatthedynamicpartitioncreationisdeterminedbythevalueoftheinputcolumn.ThedynamicpartitioncolumnsmustbespecifiedlastamongthecolumnsintheSELECTstatementandinthesameorderinwhichtheyappearinthePARTITION()clause.
DynamicPartitioninsertsaredisabledbydefault.Thesearetherelevant(相关的)configurationpropertiesfordynamicpartitioninserts:
Configurationproperty | Default | Note |
---|---|---|
hive.exec.dynamic.partition | false | Needstobesettotruetoenabledynamicpartitioninserts |
hive.exec.dynamic.partition.mode | strict | Instrictmode,theusermustspecifyatleastonestaticpartitionincasetheuseraccidentallyoverwritesallpartitions,in nonstrictmodeallpartitionsareallowedtobedynamic |
hive.exec.max.dynamic.partitions.pernode | 100 | Maximumnumberofdynamicpartitionsallowedtobecreatedineachmapper/reducernode |
hive.exec.max.dynamic.partitions | 1000 | Maximumnumberofdynamicpartitionsallowedtobecreatedintotal |
hive.exec.max.created.files | 100000 | MaximumnumberofHDFSfilescreatedbyallmappers/reducersinaMapReducejob |
hive.error.on.empty.partition | false | Whethertothrowanexceptionifdynamicpartitioninsertgeneratesemptyresults |
countrypartitionwillbedynamicallycreatedbythelastcolumnfromthe
SELECTclause(i.e.
pvs.cnt).Notethatthenameisnotused.In
nonstrictmodethe
dtpartitioncouldalsobedynamicallycreated.
AdditionalDocumentation
Writingdataintothefilesystemfromqueries
Queryresultscanbeinsertedintofilesystemdirectoriesbyusingaslightvariation(细微的变化)ofthesyntaxabove:Syntax
DirectorycanbeafullURI.Ifschemeorauthorityarenotspecified,Hivewillusetheschemeandauthorityfromthehadoopconfigurationvariable
fs.default.namethatspecifiestheNamenodeURI.
IfLOCALkeywordisused,Hivewillwritedatatothedirectoryonthelocalfilesystem.
Datawrittentothefilesystemisserializedastextwithcolumnsseparatedby^Aandrowsseparatedbynewlines.Ifanyofthecolumnsarenotofprimitivetype,thenthosecolumnsareserializedtoJSONformat.
Notes
INSERTOVERWRITEstatementstodirectories,localdirectories,andtables(orpartitions)canallbeusedtogetherwithinthesamequery.
INSERTOVERWRITEstatementstoHDFSfilesystemdirectoriesarethebestwaytoextractlargeamountsofdatafromHive.HivecanwritetoHDFSdirectoriesinparallelfromwithinamap-reducejob.
Thedirectoryis,asyouwouldexpect,OVERWRITten;inotherwords,ifthespecifiedpathexists,itisclobberedandreplacedwiththeoutput.
AsofHive
In
InsertingvaluesintotablesfromSQL
TheINSERT...VALUESstatementcanbeusedtoinsertdataintotablesdirectlyfromSQL.VersionInformation
Icon
INSERT...VALUESisavailablestartingin
InsertingvaluesfromSQLstatementscanonlybeperformedontablesthatsupportACID.See
Syntax
EachrowlistedintheVALUESclauseisinsertedintotabletablename.
Valuesmustbeprovidedforeverycolumninthetable.ThestandardSQLsyntaxthatallowstheusertoinsertvaluesintoonlysomecolumnsisnotyetsupported.TomimicthestandardSQL,nullscanbeprovidedforcolumnstheuserdoesnotwishtoassignavalueto.
Dynamicpartitioningissupportedinthesamewayasfor
Ifthetablebeinginsertedintosupports
Insert,update,deleteoperationsarenotsupportedontablesthataresorted(tablescreatedwiththe
Hivedoesnotsupportliteralsforcomplextypes,soitisnotpossibletousetheminINSERTINTO...VALUESclauses.
Meansusercannotinsertdataintocomplexdatatype[array,map,struct,union]columnsusingINSERTINTO...VALUESclause.
Examples
Update
VersionInformationIcon
UPDATEisavailablestartingin
UpdatescanonlybeperformedontablesthatsupportACID.See
Syntax
Thereferencedcolumnmustbeacolumnofthetablebeingupdated.
ThevalueassignedmustbeanexpressionthatHivesupportsintheselectclause.Thusarithmeticoperators,UDFs,casts,literals,etc.aresupported.Subqueriesarenotsupported.
OnlyrowsthatmatchtheWHEREclausewillbeupdated.
Partitioningcolumnscannotbeupdated.
Bucketingcolumnscannotbeupdated.
InHive0.14,uponsuccessfulcompletionofthisoperationthechangeswillbeauto-committed.
Notes
Vectorizationwillbeturnedoffforupdateoperations.Thisisautomaticandrequiresnoactiononthepartoftheuser.Non-updateoperationsarenotaffected.Updatedtablescanstillbequeriedusingvectorization.
Inversion0.14itisrecommendedthatyouset
Delete
VersionInformationIcon
DELETEisavailablestartingin
DeletescanonlybeperformedontablesthatsupportACID.See
Syntax
OnlyrowsthatmatchtheWHEREclausewillbedeleted.
InHive0.14,uponsuccessfulcompletionofthisoperationthechangeswillbeauto-committed.
Notes
Vectorizationwillbeturnedofffordeleteoperations.Thisisautomaticandrequiresnoactiononthepartoftheuser.Non-deleteoperationsarenotaffected.Tableswithdeleteddatacanstillbequeriedusingvectorization.
Inversion0.14itisrecommendedthatyouset
相关文章推荐
- hive如何配置支持事务及insert、update、delete
- 让Hive支持行级insert、update、delete
- 08-Oracle学习_DML-insert-update-delete
- .Nettiers的事件:下拉控件数据绑定,Insert,调用自定存储过程,获取新增ID,事务,DeepLoad,DeepSave,Save,Update,DeepDelete【原创】
- Hive基本操作,DDL操作(创建表,修改表,显示命令),DML操作(Load Insert Select),Hive Join,Hive Shell参数(内置运算符、内置函数)等
- DML语句(delete,insert,update)
- Hql 也可以进行DML操作update delete insert
- 让Hive支持行级insert、update、delete
- oracle DML-(insert,select,update,delete)
- 配置Hive支持事务——让hive支持行级insert、update、delete操作
- MYSQL——DML : 数据操作语句 (insert update delete)
- Oracle的Insert、Update、Delete等DML操作速度的提高
- 1Z0-051-DML INSERT-UPDATE-DELETE-TRUNCATE-MERGE
- Oracle DML语句(insert,update,delete) 回滚开销估算
- SQL之merge into 批量更新数据 Merge关键字是一个神奇的DML关键字。它在SQL Server 2008被引入,它能将Insert,Update,Delete简单的并为一句。M
- hive0.14-insert、update、delete操作测
- (尚硅谷) Orcale 数据处理DML(INSERT/DELETE/UPDATE) DCL :COMMOT ROLLBACK SAVE
- [转] hive0.14-insert、update、delete操作测试
- hive0.14-insert、update、delete操作测试
- SQL-insert-delete-update(DML)常用命令