在配置单元中创建表时向列添加默认值 [英] Adding a default value to a column while creating table in hive

查看:25
本文介绍了在配置单元中创建表时向列添加默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够从外部文件中的数据创建一个 hive 表.现在我希望从上一个表中的数据创建另一个表,并带有默认值的附加列.

I'm able to create a hive table from data in external file. Now I wish to create another table from data in previous table with additional columns with default value.

我知道可以使用 CREATE TABLE AS SELECT 但如何添加具有默认值的其他列?

I understand that CREATE TABLE AS SELECT can be used but how do I add additional columns with default value?

推荐答案

您可以指定在创建/更新时从表中选择哪些列.只需提供默认值作为列之一.更新示例如下:

You could specify which columns to select from table on create/update. Simply provide default value as one of columns. Example with UPDATE is below:

创建简单的表并用值填充它:

Creating simple table and populating it with value:

hive> create table table1(col1 string);
hive> insert into table table1 values('val1');
hive> select col1 from table1;
OK
val1
Time taken: 0.087 seconds, Fetched: 1 row(s)

允许动态分区:

hive> SET hive.exec.dynamic.partition.mode=nonstrict;

创建第二个表:

hive> create table table2(col1 string, col2 string);

使用默认值从 table1 填充它:

Populating it from table1 with default value:

hive> insert overwrite table table2 select col1, 'DEFAULT' from table1;
hive> select * from table2;
OK
val1    DEFAULT
Time taken: 0.081 seconds, Fetched: 1 row(s)

这篇关于在配置单元中创建表时向列添加默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆