zftang
作者zftang·2020-04-29 10:23
其它·小白一枚

hive列操作

字数 1380阅读 621评论 0赞 0

( 1 )重命名列,更改位置,类型和注释
ALTER TABLE log_messages
CHANGE COLUMN hms hours_minutes_seconds INT
COMMENT 'The hours, minutes, and seconds part of the timestamp'
AFTER severity;
更改名称 : new column old column type
comment 不是必须的,你可以添加注释
AFTER 用于更改字段位置
仅修改了元数据并未对源 data 做任何改动
( 2 )添加新列
ALTER TABLE log_messages ADD COLUMNS (
app_name STRING COMMENT 'Application name',
session_id LONG COMMENT 'The current session id');
( 3 )删除和替换列:慎用!!!
ALTER TABLE table_name ADD|REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...)
ADD 是代表新增一字段,字段位置在所有列后面 (partition 列前 )
REPLACE 则是表示替换表中所有字段。
REPLACE COLUMNS removes all existing columns and adds the new set of columns.
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. Note that this does not delete underlying data, it just changes the schema.

( 4 ) REGEX Column Specification
SELECT 语句可以使用正则表达式做列选择,下面的语句查询除了 ds 和 hr 之外的所有列:

SELECT (ds|hr)?+.+ FROM test

4、查看变量

hive> set;

hive> set-v;
… even more output! …
‘ set ’输出 hivevar,hiveconf,system 和 env 命名空间下的所有变量。
‘ set -v ’包括了输出 Hadoop 定义的全部变量。

hive> set hivevar:foo=hello;
hive> set hivevar:foo;
hivevar:foo=hello
使用变量:
hive> create table toss1(i int, ${hivevar:foo} string);

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关问题

相关资料

X社区推广