Hi ! We’re encountering a parsing error in Athena ...
# community-support
c
Hi ! We’re encountering a parsing error in Athena when Elementary drops temporary test tables after dbt test. Observed behavior After running
dbt test
with Elementary anomaly tests, Elementary (or the cleanup step triggered through Elementary) issues a DROP TABLE IF EXISTS without quoting the catalog/schema/identifier. Since our schema name contains hyphens, Athena parses “-” as subtraction and fails.
Copy code
Log excerpt 18:33:20.324465 [debug] [MainThread]: On master: -- /* {"app": "dbt", "dbt_version": "1.10.9", "profile_name": "dfn", "target_name": "sales", "connection_name": "master"} / / --ELEMENTARY-METADATA-- {"command": "test", "invocation_id": "18a4eff8-9b0f-42bc-b238-65bc3ce78d77", "package_name": "dfn", "resource_name": "dfn-on-run-end-0", "resource_type": "operation"} --END-ELEMENTARY-METADATA-- */ DROP TABLE IF EXISTS AwsDataCatalog.dfn-sales-dev-dq_elementary.test_ce9b69c0cb_elementary_column_anomalies_bookings_5__null_percent__average__max__zero_percent__price__day__1__country_id__source_id__day__1__day__30__metrics__tmp_20250829163234346922
...
Athena error botocore.errorfactory.InvalidRequestException: An error occurred (InvalidRequestException) when calling the StartQueryExecution operation: line 3:44: mismatched input '-'. Expecting: '.',
What we expect • DROP statements to be rendered with proper quoting, e.g.: DROP TABLE IF EXISTS "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_..._metrics__tmp_..." Notes • Project-level quoting for schema/identifier is enabled, but the statement above appears unquoted. • We cannot change the database/schema naming convention (hyphens are mandated). Environment ◦ Warehouse: Amazon Athena (Glue Data Catalog) ◦ dbt-core version: 1.10.9 ◦ elementary version: 0.19.4 ◦ Adapter: dbt-athena (dbt-athena-community wrapper) ◦ Python client: pyathena/botocore ◦ Target schema includes hyphens ◦ dbt project has quoting enabled for schema/identifier Happy to provide full debug logs or run a minimal repro if helpful. Thanks!
n
Hey @Corentin Fanton! We're looking into it.
🙏 1
y
Hi @Corentin Fanton I've opened a PR to fix this issue: https://github.com/elementary-data/dbt-data-reliability/pull/858 Could you please install the package from the feature branch and verify if this resolves your use case? The instructions for installing the package from the codebase are here, you'll also need to checkout the feature branch after cloning the repo.
c
Hi, thanks for your reactivity. I test with the feature branch and now im having a new issue :
Copy code
line 1:22: mismatched input '"AwsDataCatalog"' expecting {'SELECT', 'FROM', 'ADD', 'AS', 'ALL', 'DISTINCT', 'WHERE', 'GROUP', 'BY', 'GROUPING', 'SETS', 'CUBE', 'ROLLUP', 'ORDER', 'HAVING', 'LIMIT', 'AT', 'OR', 'AND', 'IN', NOT, 'NO', 'EXISTS', 'BETWEEN', 'LIKE', RLIKE, 'IS', 'NULL', 'TRUE', 'FALSE', 'NULLS', 'ASC', 'DESC', 'FOR', 'INTERVAL', 'CASE', 'WHEN', 'THEN', 'ELSE', 'END', 'JOIN', 'CROSS', 'OUTER', 'INNER', 'LEFT', 'SEMI', 'RIGHT', 'FULL', 'NATURAL', 'ON', 'LATERAL', 'WINDOW', 'OVER', 'PARTITION', 'RANGE', 'ROWS', 'UNBOUNDED', 'PRECEDING', 'FOLLOWING', 'CURRENT', 'ROW', 'WITH', 'VALUES', 'CREATE', 'TABLE', 'VIEW', 'REPLACE', 'INSERT', 'DELETE', 'INTO', 'DESCRIBE', 'EXPLAIN', 'FORMAT', 'LOGICAL', 'CODEGEN', 'CAST', 'SHOW', 'TABLES', 'COLUMNS', 'COLUMN', 'USE', 'PARTITIONS', 'FUNCTIONS', 'DROP', 'UNION', 'EXCEPT', 'INTERSECT', 'TO', 'TABLESAMPLE', 'STRATIFY', 'ALTER', 'RENAME', 'ARRAY', 'MAP', 'STRUCT', 'COMMENT', 'SET', 'RESET', 'DATA', 'START', 'TRANSACTION', 'COMMIT', 'ROLLBACK', 'MACRO', 'FIRST', 'AFTER', 'IF', 'DIV', 'PERCENT', 'BUCKET', 'OUT', 'OF', 'SORT', 'CLUSTER', 'DISTRIBUTE', 'OVERWRITE', 'TRANSFORM', 'REDUCE', 'USING', 'SERDE', 'SERDEPROPERTIES', 'RECORDREADER', 'RECORDWRITER', 'DELIMITED', 'FIELDS', 'TERMINATED', 'COLLECTION', 'ITEMS', 'KEYS', 'ESCAPED', 'LINES', 'SEPARATED', 'FUNCTION', 'EXTENDED', 'REFRESH', 'CLEAR', 'CACHE', 'UNCACHE', 'LAZY', 'FORMATTED', TEMPORARY, 'OPTIONS', 'UNSET', 'TBLPROPERTIES', 'DBPROPERTIES', 'BUCKETS', 'SKEWED', 'STORED', 'DIRECTORIES', 'LOCATION', 'EXCHANGE', 'ARCHIVE', 'UNARCHIVE', 'FILEFORMAT', 'TOUCH', 'COMPACT', 'CONCATENATE', 'CHANGE', 'CASCADE', 'RESTRICT', 'CLUSTERED', 'SORTED', 'PURGE', 'INPUTFORMAT', 'OUTPUTFORMAT', DATABASE, DATABASES, 'DFS', 'TRUNCATE', 'ANALYZE', 'COMPUTE', 'LIST', 'STATISTICS', 'PARTITIONED', 'EXTERNAL', 'DEFINED', 'REVOKE', 'GRANT', 'LOCK', 'UNLOCK', 'MSCK', 'REPAIR', 'EXPORT', 'IMPORT', 'LOAD', 'ROLE', 'ROLES', 'COMPACTIONS', 'PRINCIPALS', 'TRANSACTIONS', 'INDEX', 'INDEXES', 'LOCKS', 'OPTION', 'ANTI', 'LOCAL', 'INPATH', IDENTIFIER, BACKQUOTED_IDENTIFIER}
it seems that Athena DROP TABLE statement does not like double quote neither. however it works fine with backtick-quotes. Like this :
Copy code
DROP TABLE IF EXISTS `dfn-sales-dev-dq_elementary`.`test_b260cb04bb_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__impressions__day__3__country_id__source_id__day__1__day__30__metrics__tmp_20250910151940732171`;
y
Thanks! I'll see what can be done
c
thanks 🙏
y
@Corentin Fanton can you check this solution? https://github.com/elementary-data/dbt-data-reliability/pull/859
c
No it tries to create a view from tables that don't exist :
Copy code
[0m17:45:16.901028 [debug] [MainThread]: dbt.adapters.athena.constants adapter: Athena query ID a545cc60-229f-4d15-9a67-160abdc9f40d
[0m17:45:18.031193 [debug] [MainThread]: dbt.adapters.athena.constants adapter: Error running SQL: -- /* {"app": "dbt", "dbt_version": "1.10.9", "profile_name": "dfn", "target_name": "sales", "connection_name": "master"} */
/* --ELEMENTARY-METADATA-- {"command": "test", "invocation_id": "ea653a13-19cb-4dc2-8e92-4c8673a3d1b8", "package_name": "elementary", "resource_name": "elementary-on-run-end-0", "resource_type": "operation"} --END-ELEMENTARY-METADATA-- */
    

    create table "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."data_monitoring_metrics__tmp_20250911154306183175"
    with (
      table_type='hive',
      is_external=true,
      format='parquet'
    )
    as
      with union_temps_metrics as (select * from "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_b260cb04bb_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__impressions__day__3__country_id__source_id__day__1__day__30__metrics__tmp_20250911154022144953" union all select * from "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_10f417179d_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__sot__day__3__country_id__source_id__day__1__day__30__metrics__tmp_20250911154045827474" union all select * from "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_808bfd72c7_elementary_column_anomalies_bookings_3__null_percent__average__max__zero_percent__price__day__3__country_id__source_id__day__1__day__14__metrics__tmp_20250911154109775398" union all select * from "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_0095b83a15_elementary_volume_anomalies_programmatic_campaigns_day__3__day__1__published_at__day__30__metrics__tmp_20250911154129719020"
            ),
            metrics_with_duplicates as (
                select *,
                    row_number() over (partition by id order by updated_at desc) as row_num
                from union_temps_metrics
            )
            select
                id,
                full_table_name,
                column_name,
                metric_name,
                metric_type,
                metric_value,
                source_value,
                bucket_start,
                bucket_end,
                bucket_duration_hours,
                updated_at,
                dimension,
                dimension_value,
                metric_properties
            from metrics_with_duplicates
            where row_num = 1

  
[0m17:45:18.037585 [debug] [MainThread]: On master: Close
[0m17:45:18.047255 [info ] [MainThread]: 
[0m17:45:18.048947 [info ] [MainThread]: [33mExited because of keyboard interrupt[0m
[0m17:45:18.050068 [info ] [MainThread]: 
[0m17:45:18.051310 [info ] [MainThread]: Done. PASS=14 WARN=0 ERROR=0 SKIP=0 NO-OP=0 TOTAL=14
[0m17:45:18.052585 [debug] [MainThread]: Connection 'master' was properly closed.
[0m17:45:18.053245 [debug] [MainThread]: Connection 'list_AwsDataCatalog_dfn-sales-dev-dq_elementary' was properly closed.
[0m17:45:18.053681 [debug] [MainThread]: Connection 'test.dfn.relationships_sold_items_country_id__alpha_2__source_dfn_shared_countries_.82a08b9c23' was properly closed.
[0m17:45:18.055240 [info ] [MainThread]: 
[0m17:45:18.056199 [info ] [MainThread]: Finished running 3 project hooks, 11 data tests in 0 hours 5 minutes and 5.77 seconds (305.77s).
[0m17:45:18.057276 [error] [MainThread]: Encountered an error:
Runtime Error
  TABLE_NOT_FOUND: line 11:6: Table 'awsdatacatalog."dfn-sales-dev-dq_elementary".test_b260cb04bb_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__impressions__day__3__country_id__source_id__day__1__day__30__metrics__tmp_20250911154022144953' does not exist. You may need to manually clean the data at location 's3://aws-athena-query-results-549171697840-eu-west-1/tables/a545cc60-229f-4d15-9a67-160abdc9f40d' before retrying. Athena will not delete data in your account.
[0m17:45:18.058292 [warn ] [MainThread]: [[33mWARNING[0m][DeprecationsSummary]: Deprecated functionality
Summary of encountered deprecations:
the table has been deleted before :
Copy code
[0m17:42:50.952748 [debug] [MainThread]: dbt.adapters.athena.constants adapter: "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_0095b83a15_elementary_volume_anomalies_programmatic_campaigns_day__3__day__1__published_at__day__30__anomaly_scores__tmp_20250911154136612445" is stored in s3://aws-athena-query-results-549171697840-eu-west-1/tables/2438d424-ecb1-4da9-ae09-cfe39c27e805
[0m17:42:51.095106 [debug] [MainThread]: dbt.adapters.athena.constants adapter: Deleting table data: path='s3://aws-athena-query-results-549171697840-eu-west-1/tables/2438d424-ecb1-4da9-ae09-cfe39c27e805', bucket='aws-athena-query-results-549171697840-eu-west-1', prefix='tables/2438d424-ecb1-4da9-ae09-cfe39c27e805/'
[0m17:42:51.351995 [debug] [MainThread]: Elementary: Deleting temporary Elementary test tables: [<AthenaRelation "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_b260cb04bb_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__impressions__day__3__country_id__source_id__day__1__day__30__metrics__tmp_20250911154022144953">, <AthenaRelation "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_b260cb04bb_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__impressions__day__3__country_id__source_id__day__1__day__30__anomaly_scores__tmp_20250911154033306950">, <AthenaRelation "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_10f417179d_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__sot__day__3__country_id__source_id__day__1__day__30__metrics__tmp_20250911154045827474">, <AthenaRelation "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_10f417179d_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__sot__day__3__country_id__source_id__day__1__day__30__anomaly_scores__tmp_20250911154058781979">, <AthenaRelation "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_808bfd72c7_elementary_column_anomalies_bookings_3__null_percent__average__max__zero_percent__price__day__3__country_id__source_id__day__1__day__14__metrics__tmp_20250911154109775398">, <AthenaRelation "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_808bfd72c7_elementary_column_anomalies_bookings_3__null_percent__average__max__zero_percent__price__day__3__country_id__source_id__day__1__day__14__anomaly_scores__tmp_20250911154119537134">, <AthenaRelation "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_0095b83a15_elementary_volume_anomalies_programmatic_campaigns_day__3__day__1__published_at__day__30__metrics__tmp_20250911154129719020">, <AthenaRelation "AwsDataCatalog"."dfn-sales-dev-dq_elementary"."test_0095b83a15_elementary_volume_anomalies_programmatic_campaigns_day__3__day__1__published_at__day__30__anomaly_scores__tmp_20250911154136612445">]
[0m17:42:51.364291 [debug] [MainThread]: Using athena connection "master"
[0m17:42:51.365059 [debug] [MainThread]: On master: -- /* {"app": "dbt", "dbt_version": "1.10.9", "profile_name": "dfn", "target_name": "sales", "connection_name": "master"} */
/* --ELEMENTARY-METADATA-- {"command": "test", "invocation_id": "ea653a13-19cb-4dc2-8e92-4c8673a3d1b8", "package_name": "dfn", "resource_name": "dfn-on-run-end-0", "resource_type": "operation"} --END-ELEMENTARY-METADATA-- */
    DROP TABLE IF EXISTS `AwsDataCatalog`.`dfn-sales-dev-dq_elementary`.`test_b260cb04bb_elementary_column_anomalies_allocations_null_percent__average__max__zero_percent__impressions__day__3__country_id__source_id__day__1__day__30__metrics__tmp_20250911154022144953`
@Yosef Arbiv Nevermind, actually, it was all my fault ! i realized i have added on-run-end - "{{ elementary.on_run_end() }}" in my dbt project config, but it is already included in the elementary dbt_project. which caused dbt to call the on_run_end() macro twice. thanks for you assistance 🙂
Everything is working perfectly now.
y
That's great! I'll make sure that this fix will be included in our next release. In the meantime, you can you the version from the branch.
✅ 1