-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #580 from elementary-data/ele-1870-correct-max-col…
…umn-size Ele 1870 correct max column size
- Loading branch information
Showing
8 changed files
with
116 additions
and
57 deletions.
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,46 @@ | ||
from dbt_project import DbtProject | ||
|
||
SAFE_QUERY_SIZE = 10000 | ||
|
||
|
||
def generate_query(query_size: int) -> str: | ||
query_start = "SELECT '" | ||
query_end = "' as col" | ||
query_mid = "A" * (query_size - len(query_start) - len(query_end)) | ||
return query_start + query_mid + query_end | ||
|
||
|
||
def read_run_result(dbt_project, test_id): | ||
return dbt_project.read_table( | ||
"dbt_run_results", | ||
where=f"unique_id = 'model.elementary_tests.{test_id}'", | ||
)[0] | ||
|
||
|
||
def test_query_size_exceed(test_id: str, dbt_project: DbtProject): | ||
dbt_project.dbt_runner.vars["disable_run_results"] = False | ||
max_query_size = int( | ||
dbt_project.dbt_runner.run_operation( | ||
"elementary.get_config_var", macro_args={"var_name": "query_max_size"} | ||
)[0] | ||
) | ||
|
||
query = generate_query(max_query_size) | ||
with dbt_project.create_temp_model_for_existing_table( | ||
test_id, raw_code=query | ||
) as model_path: | ||
dbt_project.dbt_runner.run(select=str(model_path)) | ||
result = read_run_result(dbt_project, test_id) | ||
# Expect truncation. | ||
assert len(result["compiled_code"]) < max_query_size | ||
|
||
|
||
def test_query_size_safe(test_id: str, dbt_project: DbtProject): | ||
dbt_project.dbt_runner.vars["disable_run_results"] = False | ||
query = generate_query(SAFE_QUERY_SIZE) | ||
with dbt_project.create_temp_model_for_existing_table( | ||
test_id, raw_code=query | ||
) as model_path: | ||
dbt_project.dbt_runner.run(select=str(model_path)) | ||
result = read_run_result(dbt_project, test_id) | ||
assert len(result["compiled_code"]) == SAFE_QUERY_SIZE |
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
22 changes: 0 additions & 22 deletions
22
macros/edr/system/system_utils/get_compiled_model_code_text.sql
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,16 +1,27 @@ | ||
{% macro get_compiled_code(node) %} | ||
{% do return(adapter.dispatch("get_compiled_code", "elementary")(node)) %} | ||
{% macro get_compiled_code(node, as_column_value=false) %} | ||
{% set compiled_code = adapter.dispatch("get_compiled_code", "elementary")(node) %} | ||
|
||
{% set max_column_size = elementary.get_column_size() %} | ||
{% if as_column_value and max_column_size and compiled_code | length > max_column_size %} | ||
{% do return(elementary.get_compiled_code_too_long_err_msg()) %} | ||
{% endif %} | ||
|
||
{% do return(compiled_code) %} | ||
{% endmacro %} | ||
|
||
{% macro default__get_compiled_code(node) %} | ||
{% do return(node.get('compiled_code') or node.get('compiled_sql')) %} | ||
{% endmacro %} | ||
|
||
{% macro redshift__get_compiled_code(node) %} | ||
{% set compilde_code = node.get('compiled_code') or node.get('compiled_sql') %} | ||
{% if not compilde_code %} | ||
{% set compiled_code = node.get('compiled_code') or node.get('compiled_sql') %} | ||
{% if not compiled_code %} | ||
{% do return(none) %} | ||
{% else %} | ||
{% do return(compilde_code.replace("%", "%%")) %} | ||
{% do return(compiled_code.replace("%", "%%")) %} | ||
{% endif %} | ||
{% endmacro %} | ||
|
||
{% macro get_compiled_code_too_long_err_msg() %} | ||
{% do return("Compiled code is too long.") %} | ||
{% endmacro %} |
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