hive - Hive - 加载到外部表的默认位置
问题描述
我在配置单元中创建了一个具有默认位置的外部表
CREATE EXTERNAL TABLE `testtable`(
`id` int,
`name` string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'<hdfs-uri>/hive/warehouse/testtable'
想确认我是否可以将包含 ID/名称值的文本文件从本地移动到外部表 testtable 的 HDFS 位置 /hive/warehouse/testtable/test.txt?谢谢。
解决方案
是的。test.txt
您可以从外部表( )local
的位置上传。即使是默认的仓库目录,这也将起作用。HDFS
testtable
<hdfs-uri>/hive/warehouse/testtable
<hdfs-uri>/hive/warehouse/
Hive
请记住 - 对于非外部(称为Hive 管理的)表,删除表将HDFS
自动删除其仓库目录。对于外部表,删除表不会删除HDFS
备份它的目录,需要作为单独的操作删除。
插图:
Here the Hive warehouse directory is hdfs:///apps/hive/warehouse
创建表
hive> CREATE EXTERNAL TABLE `testtable`(
`id` int,
`name` string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION 'hdfs:///apps/hive/warehouse/testtable';
test.txt 中的数据
1,name-1
2,name-2
3,name-3
上传数据到 HDFS
hadoop fs -put test.txt hdfs:///apps/hive/warehouse/testtable
查询表
hive> select * from testtable;
1 name-1
2 name-2
3 name-3
推荐阅读
- python-3.x - Python用NaN填充网络提取文本中的空白
- matplotlib - x 和 y 轴刻度从原点偏移
- python - 关于 pygame image.load 函数的问题
- swift - 在 ScrollView 中居中和对齐 SwiftUI 元素
- python - 我使用 matplotlib.pyplot 子图的多个图没有相同的位置
- php - 将隐藏的输入值从 ajax 获取到 php
- node.js - 使用 onCreate 的 Firebase 函数未在文档创建时运行
- java - 停止 Apache Camel 记录被移动文件的完整路径
- docker - Docker COPY 在 gitlab 管道中新创建的文件失败
- android - 离开并重新打开项目后,Android Studio Binding 类抛出错误