2

We have a query for loading the data into a table using a INSERT-SELECT query directly on another table(s) as shown below

INSERT OVERWRITE TABLE <table1>
SELECT * FROM <table2> t2
WHERE <some-conditions>;

Similarly how can load a table with complex data types? How can I let couple of/some of columns in my SELECT query contribute for a complex data typed column? Am i clear?

Schema of the table1 is

TABLE (col1 INT, col2 STRING, col3 ARRAY<STRING>)

Note: Loading from a file to such tables is possible, but I just wanna try whether I can load using above INSERT-SELECT query fashion. Appreciate your interest.

4
  • what is the schema of the table where the data is coming from? e.g. t2 in your example? does it match the schema of the table being loaded, can it be converted/casted? Commented Nov 6, 2013 at 16:46
  • Going one by one of your questions, Schema given above is for table1 only. Now I may get the data as a text file to be loaded into table1, which is very well possible and feasible as well. If I have a simple SELECT query or a JOIN query which takes couple of columns from table2 (or from couple of tables using JOIN) in order to load the data into tabel1, how can i make sure that the data being pulled suits the schema? Am I clear? Thats where I need the syntax of the INSERT-SELECT query. Commented Nov 6, 2013 at 18:24
  • how can i make sure that the data being pulled suits the schema? -- if you know the destination schema, then you can chose what to select and convert if necessary to new schema -- using CAST of UDFs which generate new types of data, e.g. SPLIT will create array<string> from string. Commented Nov 8, 2013 at 15:24
  • Can i have any example for using SPLIT? Commented Nov 11, 2013 at 17:36

1 Answer 1

1

The Hive equivalent of insert .. select is one of:

1. from (table 2 query)
insert [overwrite] table <table1> [partition clause if partitioned table]

OR

2. create table table1 as select <table2 query>

Note the #2 (CTAS) is not reliable. You would be better served by doing #1 in conjunction with either an explicit table creation or something like:

create table <table1> **like** table2
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.