You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, really cool project!
I was wondering how would I mock a JSON in a column. I've tried different things already, but none seem to work. I mostly get a Syntax error when I run the test and the (mocked) JSON is fed in.
This is my latest version:
{{ config(tags=["unit-test"]) }}
-- Tests that output produced by the plugins are correctly aggregated
{% call dbt_unit_testing.test("session_plugin_output", "data aggregations correct") %}
{%-set session_all_valid ="'00000000-0000-0000-0000-000000000001'"-%}
{%-set session_mixed ="'00000000-0000-0000-0000-0000000mixed'"-%}
{%-set session_no_output ="'00000000-0000-0000-0000-00000missing'"-%}
{%-set session_no_json ="'00000000-0000-0000-0000-000000nojson'"-%}
{%-set valid_output = {"plugin": {"name": "expectedPlugin", "version": "1.0"}, "outputContentIds": ["Unit 1"]} -%}
{%-set empty_output = {"plugin": {"name": "expectedPlugin", "version": "1.0"}, "outputContentIds": []} -%}
{%-set null_output = {"plugin": {"name": "expectedPlugin", "version": "1.0"}, "outputContentIds": null} -%}
{%-set missing_output = {"plugin": {"name": "expectedPlugin", "version": "1.0"}} -%}
{% set column_transformations = {
"value": "to_json_string(value)"
}
%}
{% call dbt_unit_testing.mock_source(
"event_log", "personalizationpluginrun_events", options={"column_transformations": column_transformations}
) %}
{{ session_all_valid }} as log_id, {{ valid_output }} as value::jsonb
UNION ALL
{{ session_all_valid }} as log_id, {{ valid_output }} as value::jsonb
UNION ALL
{{ session_mixed }} as log_id, {{ valid_output }} as value::jsonb
UNION ALL
{{ session_mixed }} as log_id, {{ empty_output }} as value::jsonb
UNION ALL
{{ session_mixed }} as log_id, {{ empty_output }} as value::jsonb
UNION ALL
{{ session_mixed }} as log_id, {{ valid_output }} as value::jsonb
UNION ALL
{{ session_no_output }} as log_id, {{ empty_output }} as value::jsonb
UNION ALL
{{ session_no_output }} as log_id, {{ null_output }} as value::jsonb
UNION ALL
{{ session_no_output }} as log_id, {{ missing_output }} as value::jsonb
UNION ALL
{{ session_no_json }} as log_id, nullas value::jsonb
{% endcall %}
{% call dbt_unit_testing.expect({"input_format": "csv"}) %}
session_id::varchar(36), plugin_output_produced::int, plugin_runs::int
{{ session_all_valid }}, 2, 2
{{ session_mixed }}, 2, 4
{{ session_no_output }}, 0, 3
{{ session_no_json }}, 0, 1
{% endcall %}
{% endcall %}
This results in the following error:
Database Error in test session_plugin_output (tests/legacy/personalization/session_plugin_output.sql)
syntax error at or near "'00000000-0000-0000-0000-000000000001'" in context "(
with
"personalizationpluginrun_events" as (
'00000000-0000-0000-0000-000000000001'", at line 18, column 5
Before that I also tried it with CSV input, with or without the column_transformation which would make the test way easier to read:
Database Error in test session_plugin_output (tests/legacy/personalization/session_plugin_output.sql)
syntax error at or near "'plugin'" in context ",CAST({'plugin'", at line 17, column 128
Is mocking such a JSON column supported in the first place? If so, how would I mock it?
The text was updated successfully, but these errors were encountered:
Hey, really cool project!
I was wondering how would I mock a JSON in a column. I've tried different things already, but none seem to work. I mostly get a Syntax error when I run the test and the (mocked) JSON is fed in.
This is my latest version:
This results in the following error:
Before that I also tried it with CSV input, with or without the
column_transformation
which would make the test way easier to read:This is results in the following error:
Is mocking such a JSON column supported in the first place? If so, how would I mock it?
The text was updated successfully, but these errors were encountered: