You can start by creating a temp table, say trgDataFileBasetmp, then using the same definition create the table on s3. You will need all the parameters in the definition like SERDEPROPERTIES, TBLPROPERTIES. Here the difference I have is saveAsTable:
sqlContext.sql(selectQuery).write.mode("overwrite").format(trgFormat).option("compression", trgCompression).saveAsTable(trgDataFileBase)
If this does not work then you can start with:
sqlContext.sql(selectQuery).write.mode("overwrite").saveAsTable(trgDataFileBase)
Hope one out of the two would help.