Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing functions for Redshift #213

Open
2 of 4 tasks
Smlep opened this issue Jun 8, 2024 · 1 comment
Open
2 of 4 tasks

Add missing functions for Redshift #213

Smlep opened this issue Jun 8, 2024 · 1 comment

Comments

@Smlep
Copy link
Contributor

Smlep commented Jun 8, 2024

Describe the bug
Many redshift functions cannot be mocked, and should be implemented as UDFs

To Reproduce

from pytest_mock_resources import create_redshift_fixture
from sqlalchemy.orm import Session
from sqlalchemy.sql import text

session = create_redshift_fixture(session=True)


def test_len(session: Session):
    q = f"select len('apple')"

    res = session.execute(text(q))
    item = res.fetchone()

    assert item is not None
    assert item[0] == 5

Expected behavior
Test success

Actual Behavior

E       sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) function len(character varying) does not exist
E       LINE 1: select len('apple')
E                      ^
E       HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
E
E       [SQL: select len('apple')]
E       (Background on this error at: https://sqlalche.me/e/20/f405)

Additional context
This happens because the LEN function is not handled by sqlalchemy as is, and is not defined in the custom fixtures

A non-exhaustive list of functions I frequently use that are missing:

  • Len
  • Median
  • Convert_timezone
  • Listagg

I have a PR ready for LEN to begin with, I will try to implement the other ones later.

I can split this into multiple issues if you prefer

@Smlep
Copy link
Contributor Author

Smlep commented Jun 8, 2024

Median and listagg might not be as easy to use since Redshift does not allow UDFs for aggregate operations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant