-
Notifications
You must be signed in to change notification settings - Fork 56
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
Implement fetchmany #341
Merged
Merged
Implement fetchmany #341
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,7 @@ | ||
kind: Fixes | ||
body: Implemented fetchmany | ||
time: 2023-08-09T16:24:35.116089+02:00 | ||
custom: | ||
Author: damian3031 | ||
Issue: "" | ||
PR: "341" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
models__sample_model = """ | ||
select * from {{ ref('sample_seed') }} | ||
""" | ||
|
||
models__second_model = """ | ||
select | ||
sample_num as col_one, | ||
sample_bool as col_two, | ||
42 as answer | ||
from {{ ref('sample_model') }} | ||
""" | ||
|
||
models__sql_header = """ | ||
{% call set_sql_header(config) %} | ||
set time zone 'Asia/Kolkata'; | ||
{%- endcall %} | ||
select current_timezone() as timezone | ||
""" | ||
|
||
private_model_yml = """ | ||
groups: | ||
- name: my_cool_group | ||
owner: {name: me} | ||
|
||
models: | ||
- name: private_model | ||
access: private | ||
config: | ||
group: my_cool_group | ||
""" | ||
|
||
|
||
schema_yml = """ | ||
models: | ||
- name: sample_model | ||
latest_version: 1 | ||
|
||
# declare the versions, and fully specify them | ||
versions: | ||
- v: 2 | ||
config: | ||
materialized: table | ||
columns: | ||
- name: sample_num | ||
data_type: int | ||
- name: sample_bool | ||
data_type: boolean | ||
- name: answer | ||
data_type: int | ||
|
||
- v: 1 | ||
config: | ||
materialized: table | ||
contract: {enforced: true} | ||
columns: | ||
- name: sample_num | ||
data_type: int | ||
- name: sample_bool | ||
data_type: boolean | ||
""" | ||
|
||
models__ephemeral_model = """ | ||
{{ config(materialized = 'ephemeral') }} | ||
select | ||
coalesce(sample_num, 0) + 10 as col_deci | ||
from {{ ref('sample_model') }} | ||
""" | ||
|
||
models__second_ephemeral_model = """ | ||
{{ config(materialized = 'ephemeral') }} | ||
select | ||
col_deci + 100 as col_hundo | ||
from {{ ref('ephemeral_model') }} | ||
""" | ||
|
||
seeds__sample_seed = """sample_num,sample_bool | ||
1,true | ||
2,false | ||
3,true | ||
4,false | ||
5,true | ||
6,false | ||
7,true | ||
""" |
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,160 @@ | ||
import pytest | ||
from dbt.exceptions import DbtRuntimeError | ||
from dbt.exceptions import Exception as DbtException | ||
from dbt.tests.util import run_dbt, run_dbt_and_capture | ||
|
||
from tests.functional.adapter.show.fixtures import ( | ||
models__ephemeral_model, | ||
models__sample_model, | ||
models__second_ephemeral_model, | ||
models__second_model, | ||
models__sql_header, | ||
private_model_yml, | ||
schema_yml, | ||
seeds__sample_seed, | ||
) | ||
|
||
|
||
class TestShow: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"sample_model.sql": models__sample_model, | ||
"second_model.sql": models__second_model, | ||
"ephemeral_model.sql": models__ephemeral_model, | ||
"sql_header.sql": models__sql_header, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return {"sample_seed.csv": seeds__sample_seed} | ||
|
||
def test_none(self, project): | ||
with pytest.raises( | ||
DbtRuntimeError, match="Either --select or --inline must be passed to show" | ||
): | ||
run_dbt(["seed"]) | ||
run_dbt(["show"]) | ||
|
||
def test_select_model_text(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture(["show", "--select", "second_model"]) | ||
assert "Previewing node 'sample_model'" not in log_output | ||
assert "Previewing node 'second_model'" in log_output | ||
assert "col_one" in log_output | ||
assert "col_two" in log_output | ||
assert "answer" in log_output | ||
|
||
def test_select_multiple_model_text(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture( | ||
["show", "--select", "sample_model second_model"] | ||
) | ||
assert "Previewing node 'sample_model'" in log_output | ||
assert "sample_num" in log_output | ||
assert "sample_bool" in log_output | ||
|
||
def test_select_single_model_json(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture( | ||
["show", "--select", "sample_model", "--output", "json"] | ||
) | ||
assert "Previewing node 'sample_model'" not in log_output | ||
assert "sample_num" in log_output | ||
assert "sample_bool" in log_output | ||
|
||
def test_inline_pass(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture( | ||
["show", "--inline", "select * from {{ ref('sample_model') }}"] | ||
) | ||
assert "Previewing inline node" in log_output | ||
assert "sample_num" in log_output | ||
assert "sample_bool" in log_output | ||
|
||
def test_inline_fail(self, project): | ||
with pytest.raises(DbtException, match="Error parsing inline query"): | ||
run_dbt(["show", "--inline", "select * from {{ ref('third_model') }}"]) | ||
|
||
def test_inline_fail_database_error(self, project): | ||
with pytest.raises(DbtRuntimeError, match="Database Error"): | ||
run_dbt(["show", "--inline", "slect asdlkjfsld;j"]) | ||
|
||
def test_ephemeral_model(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture(["show", "--select", "ephemeral_model"]) | ||
assert "col_deci" in log_output | ||
|
||
def test_second_ephemeral_model(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture( | ||
["show", "--inline", models__second_ephemeral_model] | ||
) | ||
assert "col_hundo" in log_output | ||
|
||
# test_limit tests ConnectionWrapper.fetchmany() | ||
@pytest.mark.parametrize( | ||
"args,expected", | ||
[ | ||
([], 5), # default limit | ||
(["--limit", 3], 3), # fetch 3 rows | ||
(["--limit", -1], 7), # fetch all rows | ||
], | ||
) | ||
def test_limit(self, project, args, expected): | ||
run_dbt(["build"]) | ||
dbt_args = ["show", "--inline", models__second_ephemeral_model, *args] | ||
results, log_output = run_dbt_and_capture(dbt_args) | ||
assert len(results.results[0].agate_table) == expected | ||
|
||
def test_seed(self, project): | ||
(results, log_output) = run_dbt_and_capture(["show", "--select", "sample_seed"]) | ||
assert "Previewing node 'sample_seed'" in log_output | ||
|
||
def test_sql_header(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture(["show", "--select", "sql_header"]) | ||
assert "Asia/Kolkata" in log_output | ||
|
||
|
||
class TestShowModelVersions: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"schema.yml": schema_yml, | ||
"sample_model.sql": models__sample_model, | ||
"sample_model_v2.sql": models__second_model, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return {"sample_seed.csv": seeds__sample_seed} | ||
|
||
def test_version_unspecified(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture(["show", "--select", "sample_model"]) | ||
assert "Previewing node 'sample_model.v1'" in log_output | ||
assert "Previewing node 'sample_model.v2'" in log_output | ||
|
||
def test_none(self, project): | ||
run_dbt(["build"]) | ||
(results, log_output) = run_dbt_and_capture(["show", "--select", "sample_model.v2"]) | ||
assert "Previewing node 'sample_model.v1'" not in log_output | ||
assert "Previewing node 'sample_model.v2'" in log_output | ||
|
||
|
||
class TestShowPrivateModel: | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"schema.yml": private_model_yml, | ||
"private_model.sql": models__sample_model, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return {"sample_seed.csv": seeds__sample_seed} | ||
|
||
def test_version_unspecified(self, project): | ||
run_dbt(["build"]) | ||
run_dbt(["show", "--inline", "select * from {{ ref('private_model') }}"]) |
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.
Please add a comment that this test is used for
fetchmany
testing.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.
Added