I want to define manually the Redshift table before of my first write. This is because I want to leverage of distkey
and sortkey
on defined columns. The SQL query is going to be something like that:
my_sql_command = """
create table if not exists my_db.my_schema.my_table(
my_id VARCHAR(MAX) NOT NULL DISTKEY,
type VARCHAR(MAX),
my_timestamp TIMESTAMP,
)
compound sortkey(my_timestamp, my_id);
"""
I'm calling this SQL string as a preactions
parameter (mentioned here, could't find any better documentation unfortunately) like this:
my_frame = DynamicFrame.fromDF(my_df, glue_context, "my_frame")
glue_context.write_dynamic_frame.from_jdbc_conf(
frame=my_frame, catalog_connection=params['db_connection_name'],
connection_options={"preactions": my_sql_command, "dbtable": "my_schema.my_table", "database": "my_db"},
redshift_tmp_dir="s3://my_bucket/", transformation_ctx="my_ctx")
But I am getting this error message:
py4j.protocol.Py4JJavaError: An error occurred while calling o227.pyWriteDynamicFrame.
: java.sql.SQLException: [JDBC Driver]String index out of range: 0
at java.lang.String.charAt(String.java:658)
which I really don't know how to interpret.
What's causing this exception?