Kyle Yasinski
11/17/2023, 11:11 PMInternal Error
22:39:28 popped ['materialization'], expected macro.elementary.test_python
Table, Bigquery Project, Dataset, and Connection names have been sanitized for security purposes
Example test
{% macro compare_tables(args) %}
import pandas as pd
def test(model_df, ref, session):
original_table = model_df.toPandas().drop_duplicates()
other_table = ref('{{ args.other_table }}').toPandas().drop_duplicates()
return pd.concat([original_table, other_table]).drop_duplicates(keep=False)
{% endmacro %}
Models.yml
models:
- name: table_name_1
description: ""
tests:
- elementary.python:
code_macro: compare_tables
macro_args:
other_table: table_name_2
dbt.log
============================== 15:59:56.893406 | LABEL ==============================
[0m15:59:56.893406 [info ] [MainThread]: Running with dbt=1.5.6
[0m15:59:56.894045 [debug] [MainThread]: running dbt with arguments {'printer_width': '80', 'indirect_selection': 'eager', 'log_cache_events': 'False', 'write_json': 'True', 'partial_parse': 'True', 'cache_selected_only': 'False', 'warn_error': 'None', 'fail_fast': 'False', 'profiles_dir': '/Users/main_user/.dbt', 'log_path': '/Users/main_user/Codebase/dbt-bigquery/logs', 'debug': 'False', 'version_check': 'True', 'use_colors': 'True', 'use_experimental_parser': 'False', 'no_print': 'None', 'quiet': 'False', 'log_format': 'default', 'static_parser': 'True', 'warn_error_options': 'WarnErrorOptions(include=[], exclude=[])', 'introspect': 'True', 'target_path': 'None', 'send_anonymous_usage_stats': 'True'}
[0m15:59:57.151660 [debug] [MainThread]: Sending event: {'category': 'dbt', 'action': 'project_id', 'label': 'LABEL', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10e570790>]}
[0m15:59:57.161385 [debug] [MainThread]: Sending event: {'category': 'dbt', 'action': 'adapter_info', 'label': 'LABEL', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10e5963d0>]}
[0m15:59:57.162527 [info ] [MainThread]: Registered adapter: bigquery=1.5.6
[0m15:59:57.227038 [debug] [MainThread]: checksum: CHECKSUM, vars: {}, profile: , target: , version: 1.5.6
[0m15:59:57.563295 [debug] [MainThread]: Partial parsing enabled: 0 files deleted, 0 files added, 1 files changed.
[0m15:59:57.565836 [debug] [MainThread]: Partial parsing: updated file: dbt_<bigquery://models/intermediate/tables/_tables__models.yml>
[0m15:59:57.587244 [debug] [MainThread]: 1603: static parser failed on intermediate/tables/table_name_1.sql
[0m15:59:57.602259 [debug] [MainThread]: 1602: parser fallback to jinja rendering on intermediate/tables/table_name_1.sql
[0m15:59:57.760379 [debug] [MainThread]: Sending event: {'category': 'dbt', 'action': 'load_project', 'label': 'LABEL', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10f5db340>]}
[0m15:59:57.854406 [debug] [MainThread]: Sending event: {'category': 'dbt', 'action': 'resource_counts', 'label': 'LABEL', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10ed3ed60>]}
[0m15:59:57.854973 [info ] [MainThread]: Found 155 models, 456 tests, 0 snapshots, 6 analyses, 1192 macros, 0 operations, 0 seed files, 92 sources, 0 exposures, 0 metrics, 0 groups
[0m15:59:57.855380 [debug] [MainThread]: Sending event: {'category': 'dbt', 'action': 'runnable_timing', 'label': 'LABEL', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10ed3ea90>]}
[0m15:59:57.863809 [info ] [MainThread]:
[0m15:59:57.864659 [debug] [MainThread]: Acquiring new bigquery connection 'master'
[0m15:59:57.871398 [debug] [ThreadPool]: Acquiring new bigquery connection 'connection_name'
[0m15:59:57.871869 [debug] [ThreadPool]: Opening a new connection, currently in state init
[0m15:59:59.303130 [debug] [MainThread]: Sending event: {'category': 'dbt', 'action': 'runnable_timing', 'label': '27b777ad-4bd7-49bd-a797-be145cdc63b3', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10ed3eca0>]}
[0m15:59:59.304834 [info ] [MainThread]: Concurrency: 1 threads (target='dev')
[0m15:59:59.305348 [info ] [MainThread]:
[0m15:59:59.310226 [debug] [Thread-1 ]: Began running node test.project_name.elementary_python_table_name_1_compare_tables__table_name_2.821036f283
[0m15:59:59.310774 [info ] [Thread-1 ]: 1 of 1 START test elementary_python_table_name_1_compare_tables__table_name_2 [RUN]
[0m15:59:59.311759 [debug] [Thread-1 ]: Re-using an available connection from the pool (formerly connection_name, now test.project_name.elementary_python_table_name_1_compare_tables__table_name_2.821036f283)
[0m15:59:59.312285 [debug] [Thread-1 ]: Began compiling node test.project_name.elementary_python_table_name_1_compare_tables__table_name_2.821036f283
[0m15:59:59.340493 [debug] [Thread-1 ]: On test.project_name.elementary_python_table_name_1_compare_tables__table_name_2.821036f283:
import pandas
import pyspark.sql
import pandas as pd
def test(model_df, ref, session):
original_table = model_df.toPandas().drop_duplicates()
other_table = ref('stg_index_exchange__parquet_impression_logs').toPandas().drop_duplicates()
return pd.concat([original_table, other_table]).drop_duplicates(keep=False)
def write_output_table(session, output_df, target_relation):
output_df.write.mode('overwrite').format('bigquery').option('writeMethod', 'direct').option('writeDisposition', 'WRITE_TRUNCATE').save(target_relation)
def get_fail_count(test_output):
if isinstance(test_output, int):
return test_output
if isinstance(test_output, bool):
return 0 if test_output else 1
if isinstance(test_output, pyspark.sql.DataFrame):
return test_output.count()
if isinstance(test_output, pandas.DataFrame):
return len(test_output)
raise ValueError('Received invalid return value, expected either DataFrame or a boolean.')
def get_session():
session = pyspark.sql.SparkSession.builder.appName('Elementary').getOrCreate()
session.conf.set('viewsEnabled', 'true')
session.conf.set('temporaryGcsBucket', 'None')
return session
def get_output_df(model_df, code_type, ref, session):
if code_type == "test":
test_output = test(model_df, ref, session)
fail_count = get_fail_count(test_output)
return session.createDataFrame([[fail_count]], ['fail_count'])
elif code_type == "function":
res = func(model_df, ref, session)
return session.createDataFrame([[res]], ['result'])
raise Exception("Unsupported code type: {}".format(code_type))
def main():
session = get_session()
ref = session.read.format('bigquery').load
model_df = ref('project.dataset.table_name_1')
output_df = get_output_df(model_df, 'test', ref, session)
write_output_table(session, output_df, 'pytest_tmp__elementary_python_table_name_hexcode')
main()
[0m15:59:59.342467 [debug] [Thread-1 ]: Timing info for test.project_name.elementary_python_table_name_1_compare_tables__table_name_2.821036f283 (compile): 15:59:59.312583 => 15:59:59.342124
[0m15:59:59.343102 [debug] [Thread-1 ]: [31mInternal error executing [0m
Internal Error
popped ['materialization'], expected macro.elementary.test_python
This is an error in dbt. Please try again. If the error persists, open an issue at <https://github.com/dbt-labs/dbt-core>
[0m15:59:59.343608 [error] [Thread-1 ]: 1 of 1 ERROR elementary_python_table_name_1_compare_tables__table_name_2 [[31mERROR[0m in 0.03s]
[0m15:59:59.344078 [debug] [Thread-1 ]: Finished running node test.project_name.elementary_python_table_name_1_compare_tables__table_name_2.821036f283
[0m15:59:59.345402 [debug] [MainThread]: Connection 'master' was properly closed.
[0m15:59:59.345641 [debug] [MainThread]: Connection 'test.project_name.elementary_python_table_name_1_compare_tables__table_name_2.821036f283' was properly closed.
[0m15:59:59.345908 [info ] [MainThread]:
[0m15:59:59.346246 [info ] [MainThread]: Finished running 1 test in 0 hours 0 minutes and 1.48 seconds (1.48s).
[0m15:59:59.346749 [debug] [MainThread]: Command end result
[0m15:59:59.462344 [info ] [MainThread]:
[0m15:59:59.462820 [info ] [MainThread]: [31mCompleted with 1 error and 0 warnings:[0m
[0m15:59:59.463124 [info ] [MainThread]:
[0m15:59:59.463431 [error] [MainThread]: [33mInternal Error[0m
[0m15:59:59.463720 [error] [MainThread]: popped ['materialization'], expected macro.elementary.test_python
[0m15:59:59.464006 [info ] [MainThread]:
[0m15:59:59.464327 [info ] [MainThread]: Done. PASS=0 WARN=0 ERROR=1 SKIP=0 TOTAL=1
[0m15:59:59.464861 [debug] [MainThread]: Command `dbt test` failed at 15:59:59.464780 after 2.60 seconds
[0m15:59:59.465154 [debug] [MainThread]: Sending event: {'category': 'dbt', 'action': 'invocation', 'label': 'end', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10c0a19a0>, <snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10f783b20>, <snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x10f783070>]}
[0m15:59:59.465430 [debug] [MainThread]: Flushing usage eventsDaniel Pollak
11/19/2023, 10:49 AMtable_name_2 model defined in your dbt project ?
This error is reproduced for me when the python test code tries to ref a model that doesn't exist.Kyle Yasinski
11/20/2023, 11:23 PMDaniel Pollak
11/21/2023, 8:15 AM