hive 创建数据表失败

hive 创建数据表失败,第1张

之前根据网上相关教程搭建hive,一直没什么问题,最近新搭建 hive服务时出现了无法创建数据表的问题,从日志中发现报了一个,无法找到/user问题,正常情况下创建一张数据表的时候会在hdfs中创建一个/user/hive/warehouse的文件夹,去hdfs中没有这个目录,我就手动添加

显示添加失败,经过尝试要在目录前添加-p函数,并且添加namenode的域名(机器名)和端口.

创建成功后,重新打开hive使用,创建hive表,依然失败,一样的报错,无法找到/user目录。依据上次手动创建目录的经验我认为应该是没找到对应的hdfs服务。

修改hive-site.xml文件

重新启动hive, 可以创建hive表了。对于之前使用hive无需过多配置,这次却需要修改warehouse,也找到了合理的解释,之前配置hive都是安装在Hadoop namenode的机器上直接可以通过/user/hive/warehouse创建hdfs目录,但是这次为了分散压力我把hive安装到了别的服务器上,导致无法找到正确的namenode,所以需要在hive.metastore.warehouse.dir,添加hdfs联邦的地址。

实际应用中,常常存在修改数据表结构的需求,比如:增加一个新字段。

如果使用如下语句新增列,可以成功添加列col1。但如果数据表tb已经有旧的分区(例如:dt=20190101),则该旧分区中的col1将为空且无法更新,即便insert overwrite该分区也不会生效。

解决方法:

解决方法很简单,就是增加col1时加上cascade关键字。示例如下:

加深记忆的方法也很简单,cascade的中文翻译为“级联”,也就是不仅变更新分区的表结构(metadata),同时也变更旧分区的表结构。

ADD COLUMNS lets you add new columns to the end of the existing columns but before the partition columns. This is supported for Avro backed tables as well, for Hive 0.14 and later.

REPLACE COLUMNS removes all existing columns and adds the new set of columns. This can be done only for tables with a native SerDe (DynamicSerDe, MetadataTypedColumnsetSerDe, LazySimpleSerDe and ColumnarSerDe). Refer to Hive SerDe for more information. REPLACE COLUMNS can also be used to drop columns. For example, "ALTER TABLE test_change REPLACE COLUMNS (a int, b int)" will remove column 'c' from test_change's schema.

The PARTITION clause is available in Hive 0.14.0 and latersee Upgrading Pre-Hive 0.13.0 Decimal Columns for usage.

The CASCADE|RESTRICT clause is available in Hive 1.1.0. ALTER TABLE ADD|REPLACE COLUMNS with CASCADE command changes the columns of a table's metadata, and cascades the same change to all the partition metadata. RESTRICT is the default, limiting column changes only to table metadata.


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11962643.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-20
下一篇2023-05-20

发表评论

登录后才能评论

评论列表(0条)

    保存