Skip to content

TrinoHook uses wrong parameter representation when inserting rows #25937

Description

@alexandermalyga

Apache Airflow Provider(s)

trino

Versions of Apache Airflow Providers

apache-airflow-providers-trino==4.0.0

Apache Airflow version

2.3.3

Operating System

macOS 12.5.1 (21G83)

Deployment

Docker-Compose

Deployment details

No response

What happened

TrinoHook.insert_rows() throws a syntax error due to the underlying prepared statement using "%s" as representation for parameters, instead of "?" which Trino uses.

What you think should happen instead

TrinoHook.insert_rows() should insert rows using Trino-compatible SQL statements.

The following exception is raised currently:
trino.exceptions.TrinoUserError: TrinoUserError(type=USER_ERROR, name=SYNTAX_ERROR, message="line 1:88: mismatched input '%'. Expecting: ')', <expression>, <query>", query_id=xxx)

How to reproduce

Instantiate an airflow.providers.trino.hooks.trino.TrinoHook instance and use it's insert_rows() method.
Operators using this method internally are also broken: e.g. airflow.providers.trino.transfers.gcs_to_trino.GCSToTrinoOperator

Anything else

The issue seems to come from TrinoHook.insert_rows() relying on DbApiHook.insert_rows(), which uses "%s" to represent query parameters.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. boring-cyborg commented on Aug 24, 2022

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template!

  2. alexandermalyga commented on Aug 24, 2022

    @alexandermalyga
    ContributorAuthor

    Currently working on a PR that will handle this the same way other hooks do (e.g SqliteHook): by overriding the DbApiHook._generate_insert_sql() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions