1

I'd like to create a new table based on columns from an existed table, add a new partition col in hive.

And I'd like to achieve the goal in hive sql.

Is there any other way than the following sql or using ETL tools like kettle.

create table if not exists table_name(
col1,
col2,
col3,
……,
coln
)partitioned by dt;

in which col1 to coln are from the already existed older table, and dt, the partition key is newly added.

Because the older table is too big, may has hundreds of columns, listing them would be tiring.

However, the following sql shows syntax error:

create table if not exists table_name like older_table_name partitioned by dt;

So I'd like to know is there any other better way to solve this in hive sql? thank you.

1 Answer 1

1

If all the columns and dt columnYou can use following ways to create the partitioned table:

CREATE TABLE newtable (col1 int, col2 string) PARTITIONED BY (dt string) AS
SELECT col1 , col2, dt FROM oldtable WHERE dt is not null;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.