-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Feature] Return agate_table
in dbt
run-operation
result
#10957
Open
acjh
wants to merge
4
commits into
dbt-labs:main
Choose a base branch
from
acjh:dbt-run-operation-return-agate-table
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Return agate_table in dbt run-operation result | ||
time: 2024-10-31T20:10:31.10956+08:00 | ||
custom: | ||
Author: acjh | ||
Issue: "10956" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
happy_macros_sql = """ | ||
{% macro select_something(name) %} | ||
{% set query %} | ||
select 'hello, {{ name }}' as name | ||
{% endset %} | ||
{% set table = run_query(query) %} | ||
{% endmacro %} | ||
|
||
{% macro select_something_with_return(name) %} | ||
{% set query %} | ||
select 'hello, {{ name }}' as name | ||
{% endset %} | ||
{% set table = run_query(query) %} | ||
{% do return(table) %} | ||
{% endmacro %} | ||
""" |
33 changes: 33 additions & 0 deletions
33
tests/functional/adapter/dbt_run_operations/test_dbt_run_operations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
import yaml | ||
|
||
from dbt.tests.util import run_dbt | ||
from tests.functional.adapter.dbt_run_operations.fixtures import happy_macros_sql | ||
|
||
|
||
# -- Below we define base classes for tests you import based on if your adapter supports dbt run-operation or not -- | ||
class BaseRunOperationResult: | ||
@pytest.fixture(scope="class") | ||
def macros(self): | ||
return {"happy_macros.sql": happy_macros_sql} | ||
|
||
def run_operation(self, macro, expect_pass=True, extra_args=None, **kwargs): | ||
args = ["run-operation", macro] | ||
if kwargs: | ||
args.extend(("--args", yaml.safe_dump(kwargs))) | ||
if extra_args: | ||
args.extend(extra_args) | ||
return run_dbt(args, expect_pass=expect_pass) | ||
|
||
def test_result_without_return(self, project): | ||
results = self.run_operation("select_something", name="world") | ||
assert results.results[0].agate_table is None | ||
|
||
def test_result_with_return(self, project): | ||
results = self.run_operation("select_something_with_return", name="world") | ||
assert len(results.results[0].agate_table) == 1 | ||
assert results.results[0].agate_table.rows[0]["name"] == "hello, world" | ||
|
||
|
||
class TestPostgresRunOperationResult(BaseRunOperationResult): | ||
pass |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: When there is no explicit
return
function call in the macro — like for theselect_something
test —res
is astr
of newline characters and spaces, at least as observed with the Postgres and SQLite adapters.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more robust check is
not isinstance(res, agate.Table)
but there appears to be deliberate avoidance ofimport agate
. Let me know if that is preferred.