创建表

创建名为pokes的表

  hive> CREATE TABLE pokes (foo INT, bar STRING);

创建名为invites的表,包含partition column

  hive> CREATE TABLE invites (foo INT, bar STRING) PARTITIONED BY (ds STRING);

展示表

列出所有的表

 hive> SHOW TABLES;

列出以s结尾的表,正则匹配遵循Java正则表达式规则

hive> SHOW TABLES '.*s';

显示表的所有字段

hive> DESCRIBE invites;

更改表

表的名称可以更改,同时列可以增加或替换

  hive> ALTER TABLE events RENAME TO 3koobecaf;
  hive> ALTER TABLE pokes ADD COLUMNS (new_col INT);
  hive> ALTER TABLE invites ADD COLUMNS (new_col2 INT COMMENT 'a comment');
  hive> ALTER TABLE invites REPLACE COLUMNS (foo INT, bar STRING, baz INT COMMENT 'baz replaces new_col2');

REPLACE COLUMNS可以替换所有已经存在的列,但是紧紧是改变schema,而不是数据。

REPLACE COLUMNS也可以用来删除表中的列。

 hive> ALTER TABLE invites REPLACE COLUMNS (foo INT COMMENT 'only keep the first column');

删除表

 hive> DROP TABLE pokes;

results matching ""

    No results matching ""