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

feat: handle LEN function for Redshift #212

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytest-mock-resources"
version = "2.10.3"
version = "2.10.4"
description = "A pytest plugin for easily instantiating reproducible mock resources."
authors = [
"Omar Khan <[email protected]>",
Expand Down Expand Up @@ -54,7 +54,7 @@ filelock = {version = "*", optional = true}
python-on-whales = {version = ">=0.22.0", optional = true}

[tool.poetry.dev-dependencies]
botocore = ">=1.31.63"
botocore = "1.33.13"
coverage = "*"
moto = ">=2.3.2"
mypy = {version = "0.982"}
Expand Down
20 changes: 18 additions & 2 deletions src/pytest_mock_resources/fixture/redshift/udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def create_udf(name, args, returns, body, language, schema="public"):

return text(
_template.format(
schema=schema, name=name, args=args, returns=returns, body=body, language=language
schema=schema,
name=name,
args=args,
returns=returns,
body=body,
language=language,
)
)

Expand Down Expand Up @@ -87,6 +92,14 @@ def create_udf(name, args, returns, body, language, schema="public"):
**dateadd_kwargs,
)

len_varchar = create_udf(
name="LEN",
args="s VARCHAR",
returns="INTEGER",
body="SELECT LENGTH(s)",
language=UdfLanguage.SQL.value,
)


datediff_kwargs = {
"returns": "BIGINT",
Expand Down Expand Up @@ -168,7 +181,9 @@ def create_udf(name, args, returns, body, language, schema="public"):
)

datediff_timestamp = create_udf(
name="DATEDIFF", args="units VARCHAR, start_t TIMESTAMP, end_t TIMESTAMP", **datediff_kwargs
name="DATEDIFF",
args="units VARCHAR, start_t TIMESTAMP, end_t TIMESTAMP",
**datediff_kwargs,
)

datediff_timestamptz = create_udf(
Expand All @@ -189,4 +204,5 @@ def create_udf(name, args, returns, body, language, schema="public"):
datediff_timestamptz,
left_integer,
right_integer,
len_varchar,
)
6 changes: 6 additions & 0 deletions tests/fixture/redshift/test_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,9 @@ def test_right_integer(self, redshift):
result = conn.execute(text("SELECT RIGHT(1234, 2)"))
result = result.fetchone()
assert result[0] == 34

def test_len(self, redshift):
with redshift.connect() as conn:
result = conn.execute(text("SELECT len('1234')"))
result = result.fetchone()
assert result[0] == 4
Loading