Ask Your Question
3

How can I incorporate the PARTITION feature into a TABLE creation command in Hive?

asked 2023-07-14 12:49:14 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-07-14 13:18:02 +0000

huitzilopochtli gravatar image

To incorporate the PARTITION feature into a TABLE creation command in Hive, you can add the PARTITIONED BY clause to the CREATE TABLE statement followed by the partition columns.

For example:

CREATE TABLE my_table (
  id INT,
  name STRING
)
PARTITIONED BY (year INT, month INT, day INT)

This creates a table "my_table" with two regular columns "id" and "name" and three partition columns "year", "month", and "day". Data can be inserted into the partitions using the following syntax:

INSERT INTO TABLE my_table PARTITION (year=2021, month=10, day=15)
VALUES (1, 'John'),
       (2, 'Doe')

This inserts two rows into the partition year=2021/month=10/day=15. Additional partitions can be created dynamically using the ALTER TABLE ADD PARTITION command.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-14 12:49:14 +0000

Seen: 9 times

Last updated: Jul 14 '23