Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Will Insert Into Command preserve order in Spark3

Would like to know if the columns will be inserted into the Hive table in the correct position when I use insert into the target table select * from the temp table created in spark.

I am trying to insert into a partitioned table in hive from spark. I do a select on the df and then create a temp table and then insert into target from the temp table. Would like to know if it will preserve the Order.

df.select("col1","col2","col3","YearMonth").createOrReplaceTempView("Table1")
spark.sql("insert into TargetTable partition(yyyymm) select * from Table1")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, order is maintained.
But in addition,
If your TargetTable has same no of columns and corresponding datatypes from select * query, then there wont be a problem

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading