'Refresh redshift materialized view using glue jbdc connection

I have a glue connection which connects to redshift using jdbc. The redshift has spectrum which automatically fetches latest data from S3 location. I need to create a view from that spectrum while utilizing the glue connection!

I have tried using below code where I have added sql query in post_actions to refresh redshift view!

datasink1 = glueContext.write_dynamic_frame.from_jdbc_conf(frame=inputGDF_final, 
catalog_connection=f"{srvc_user}",connection_options={"preactions":pre_query,"dbtable": f" 
{table_dbname}.{table}","database": f"{database}","postactions": post_query},
redshift_tmp_dir=args["TempDir"],transformation_ctx="datasink1")

But issue with the above piece of code is that it creates a table in redshift and then uses that table to create view. I need to utilize the redshift spectrum and not table!

Can anyone please help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source