hive - Insert data in HDFS -
i need create tables in hive , want insert data in hdfs hive table created automatically.
i consider example:
i need information stored in hive. tell me example of how have insert data in hdfs this?
hive tables not created atomatically when upload data hdfs. have manually, or programmatically app. command creating (external) hive tables basically:
hive> create external table <table_name> (param_1_name param_1_type, ...) row format delimited fields terminated ',' location '/user/<your_hdfs_user>/path/to/the/data/directory/';
the above structured data in csv-like format. if data written in json, need use serde.
being said that, once hive tables created easy way add new data tables upload such data hdfs directly. can done through webhdfs. instance, if want add file hdfs folder hive table pointing (using curl
http cient):
$ curl -i -x put "http://<host>:<port>/webhdfs/v1/<path>?op=create [&overwrite=<true |false>][&blocksize=<long>][&replication=<short>] [&permission=<octal>][&buffersize=<int>]"
you receive redirection must followed:
http/1.1 307 temporary_redirect location: http://<datanode>:<port>/webhdfs/v1/<path>?op=create... content-length: 0
thus, perform put on redirection url:
curl -i -x put -t <local_file> "http://<datanode>:<port>/webhdfs/v1/<path>?op=create..."
(btw, curl
can automatically follow redirections if use -l
option).
once file created, can append new data existent file using post method (op=append
stated in teh documentation).
hth
Comments
Post a Comment