while loading data from dataframe to spark sql table using .saveAstable() option, not working.

Neeraj_432
New Contributor II

hi , i am loading dataframe data into spark sql table using .saveastable() option.. scema is matching..but column names are diffirent in sql table. is it necessary to maintain the same column names in source and target ? how to handle it in real time, either modifying column names in dataframe or using insert into option in sql..

 

sales_df_cleaned.createOrReplaceTempView("sales")
spark.sql("select count(*) from sales").show()
insert into dev.spark_db.tbl_instax_sales
select * from sales
 
or 
 modifying column names  in dataframe and load in table ..
sales_df_cleaned.write.mode("overwrite").saveAsTable("dev.spark_db.tbl_instax_sales")