laughingman7743 / PyAthena

PyAthena is a Python DB API 2.0 (PEP 249) client for Amazon Athena.
MIT License
463 stars 105 forks source link

result_reuse_enable and result_reuse_minutes #477

Closed CandiedCode closed 1 year ago

CandiedCode commented 1 year ago

How can we set result_reuse_enable and result_reuse_minutes if we are using sqlalchemy?

I've tried something like this...

conn_str = "awsathena+rest://:@athena.{region_name}.amazonaws.com:443/"\
           "{schema_name}?s3_staging_dir={s3_staging_dir}&work_group=primary&result_reuse_enable=True&result_reuse_minutes=10"
engine = create_engine(conn_str.format(
    region_name="us-east-1",
    schema_name="default",
    s3_staging_dir="s3://some_bucket"))
with engine.connect() as connection:
    # execution_options={"result_reuse_enable": True, "result_reuse_minutes": 10}
    result = connection.exec_driver_sql(query, execution_options={})
    ...

But it fails because they are not converted to the expected value types

Invalid type for parameter ResultReuseConfiguration.ResultReuseByAgeConfiguration.Enabled, value: True, type: <class 'str'>, valid types: <class 'bool'>
Invalid type for parameter ResultReuseConfiguration.ResultReuseByAgeConfiguration.MaxAgeInMinutes, value: 10, type: <class 'str'>, valid types: <class 'int'>
laughingman7743 commented 1 year ago

Perhaps we need to convert the result_reuse_enable and result_reuse_minutes passed to the URL in the following method. https://github.com/laughingman7743/PyAthena/blob/master/pyathena/sqlalchemy/base.py#L987-L1013

CandiedCode commented 1 year ago

Thanks @laughingman7743 that does solve my issue.

https://github.com/laughingman7743/PyAthena/pull/478