dbt-labs / dbt-utils

Utility functions for dbt projects.
https://hub.getdbt.com/dbt-labs/dbt_utils/latest/
Apache License 2.0
1.38k stars 499 forks source link

Unexpected string literal using `dbt_utils.union_relations` #921

Closed jeremychia closed 4 months ago

jeremychia commented 4 months ago

Describe the bug

Syntax error: Unexpected string literal "\n \n\n (\n select\n ..." at [19:10]

Steps to reproduce

This is the SQL code:

    unioned_current_backfill as (
        {{
            dbt_utils.union_relations(
                relations=[
                    ref("stg_d2c_payments__backfill_checkout_balance_statement"),
                    ref("stg_d2c_payments__checkout_balance_statement"),
                ]
            )
        }}
    ),

Expected results

Should be able to compile

Actual results

unioned_current_backfill as (
        ("\n    \n\n        (\n            select\n                cast('''`dv-vgo-fin-test`.`dbt_dbt_ci_vgo_finance_1962_5079_1`.`stg_d2c_payments__backfill_checkout_balance_statement`''' as string) as _dbt_source_relation,\n\n                \n                    cast(`report_id` as STRING) as `report_id` ,\n                    cast(`entity_id` as STRING) as `entity_id` ,\n                    cast(`entity_name` as STRING) as `entity_name` ,\n                    cast(`currency_account_id` as STRING) as `currency_account_id` ,\n                    cast(`currency_account_name` as STRING) as `currency_account_name` ,\n                    cast(`payment_method` as STRING) as `payment_method` ,\n                    cast(`description` as STRING) as `description` ,\n                    cast(`report_date` as STRING) as `report_date` ,\n                    cast(`reporting_start_date` as STRING) as `reporting_start_date` ,\n                    cast(`reporting_end_date` as STRING) as `reporting_end_date` ,\n                    cast(`holding_currency` as STRING) as `holding_currency` ,\n                    cast(`opening_available_balance_holding_currency` as FLOAT64) as `opening_available_balance_holding_currency` ,\n                    cast(`opening_pending_balance_holding_currency` as FLOAT64) as `opening_pending_balance_holding_currency` ,\n                    cast(`opening_payable_balance_holding_currency` as FLOAT64) as `opening_payable_balance_holding_currency` ,\n                    cast(`opening_collateral_balance_holding_currency` as FLOAT64) as `opening_collateral_balance_holding_currency` ,\n                    cast(`payment_amount_holding_currency` as FLOAT64) as `payment_amount_holding_currency` ,\n                    cast(`refund_amount_holding_currency` as FLOAT64) as `refund_amount_holding_currency` ,\n                    cast(`chargeback_amount_holding_currency` as FLOAT64) as `chargeback_amount_holding_currency` ,\n                    cast(`pay_to_card_amount_holding_currency` as FLOAT64) as `pay_to_card_amount_holding_currency` ,\n                    cast(`card_payment_interchange_fee_amount_holding_currency` as FLOAT64) as `card_payment_interchange_fee_amount_holding_currency` ,\n                    cast(`card_payment_scheme_fee_amount_holding_currency` as FLOAT64) as `card_payment_scheme_fee_amount_holding_currency` ,\n                    cast(`acquiring_premium_amount_holding_currency` as FLOAT64) as `acquiring_premium_amount_holding_currency` ,\n                    cast(`card_payment_gateway_fee_amount_holding_currency` as FLOAT64) as `card_payment_gateway_fee_amount_holding_currency` ,\n                    cast(`card_payment_blended_fee_amount_holding_currency` as FLOAT64) as `card_payment_blended_fee_amount_holding_currency` ,\n                    cast(`refunded_interchange_fee_amount_holding_currency` as FLOAT64) as `refunded_interchange_fee_amount_holding_currency` ,\n                    cast(`refund_scheme_fee_amount_holding_currency` as FLOAT64) as `refund_scheme_fee_amount_holding_currency` ,\n                    cast(`refund_gateway_fee_amount_holding_currency` as FLOAT64) as `refund_gateway_fee_amount_holding_currency` ,\n                    cast(`chargeback_fee_amount_holding_currency` as FLOAT64) as `chargeback_fee_amount_holding_currency` ,\n                    cast(`retrievel_fee_amount_holding_currency` as FLOAT64) as `retrievel_fee_amount_holding_currency` ,\n                    cast(`representment_fee_amount_holding_currency` as FLOAT64) as `representment_fee_amount_holding_currency` ,\n                    cast(`pay_to_card_interchange_fee_amount_holding_currency` as FLOAT64) as `pay_to_card_interchange_fee_amount_holding_currency` ,\n                    cast(`pay_to_card_scheme_fee_amount_holding_currency` as FLOAT64) as `pay_to_card_scheme_fee_amount_holding_currency` ,\n                    cast(`pay_to_card_fee_amount_holding_currency` as FLOAT64) as `pay_to_card_fee_amount_holding_currency` ,\n                    cast(`alternative_payment_method_fee_amount_holding_currency` as FLOAT64) as `alternative_payment_method_fee_amount_holding_currency` ,\n                    cast(`adjustment_amount_holding_currency` as FLOAT64) as `adjustment_amount_holding_currency` ,\n                    cast(`tax_amount_holding_currency` as FLOAT64) as `tax_amount_holding_currency` ,\n                    cast(`account_updater_fee_amount_holding_currency` as FLOAT64) as `account_updater_fee_amount_holding_currency` ,\n                    cast(`merchant_payout_fee_amount_holding_currency` as FLOAT64) as `merchant_payout_fee_amount_holding_currency` ,\n                    cast(`pay_to_bank_fee_amount_holding_currency` as FLOAT64) as `pay_to_bank_fee_amount_holding_currency` ,\n                    cast(`pay_to_bank_payout_amount_holding_currency` as FLOAT64) as `pay_to_bank_payout_amount_holding_currency` ,\n                    cast(`transfers_in_amount_holding_currency` as FLOAT64) as `transfers_in_amount_holding_currency` ,\n                    cast(`transfers_out_amount_holding_currency` as FLOAT64) as `transfers_out_amount_holding_currency` ,\n                    cast(`merchant_payout_amount_holding_currency` as FLOAT64) as `merchant_payout_amount_holding_currency` ,\n                    cast(`closing_available_balance_holding_currency` as FLOAT64) as `closing_available_balance_holding_currency` ,\n                    cast(`closing_pending_balance_holding_currency` as FLOAT64) as `closing_pending_balance_holding_currency` ,\n                    cast(`closing_payable_balance_holding_currency` as FLOAT64) as `closing_payable_balance_holding_currency` ,\n                    cast(`closing_collateral_balance_holding_currency` as FLOAT64) as `closing_collateral_balance_holding_currency` ,\n                    cast(`authentication_fees_amount_holding_currency` as FLOAT64) as `authentication_fees_amount_holding_currency` ,\n                    cast(`authentication_scheme_fees_amount_holding_currency` as FLOAT64) as `authentication_scheme_fees_amount_holding_currency` ,\n                    cast(`intelligence_acceptance_fees_amount_holding_currency` as FLOAT64) as `intelligence_acceptance_fees_amount_holding_currency` \n\n            from `dv-vgo-fin-test`.`dbt_dbt_ci_vgo_finance_1962_5079_1`.`stg_d2c_payments__backfill_checkout_balance_statement`\n\n            \n        )\n\n        union all\n        \n\n        (\n            select\n                cast('''`dv-vgo-fin-test`.`dbt_dbt_ci_vgo_finance_1962_5079_1`.`stg_d2c_payments__checkout_balance_statement`''' as string) as _dbt_source_relation,\n\n                \n                    cast(`report_id` as STRING) as `report_id` ,\n                    cast(`entity_id` as STRING) as `entity_id` ,\n                    cast(`entity_name` as STRING) as `entity_name` ,\n                    cast(`currency_account_id` as STRING) as `currency_account_id` ,\n                    cast(`currency_account_name` as STRING) as `currency_account_name` ,\n                    cast(`payment_method` as STRING) as `payment_method` ,\n                    cast(`description` as STRING) as `description` ,\n                    cast(`report_date` as STRING) as `report_date` ,\n                    cast(`reporting_start_date` as STRING) as `reporting_start_date` ,\n                    cast(`reporting_end_date` as STRING) as `reporting_end_date` ,\n                    cast(`holding_currency` as STRING) as `holding_currency` ,\n                    cast(`opening_available_balance_holding_currency` as FLOAT64) as `opening_available_balance_holding_currency` ,\n                    cast(`opening_pending_balance_holding_currency` as FLOAT64) as `opening_pending_balance_holding_currency` ,\n                    cast(`opening_payable_balance_holding_currency` as FLOAT64) as `opening_payable_balance_holding_currency` ,\n                    cast(`opening_collateral_balance_holding_currency` as FLOAT64) as `opening_collateral_balance_holding_currency` ,\n                    cast(`payment_amount_holding_currency` as FLOAT64) as `payment_amount_holding_currency` ,\n                    cast(`refund_amount_holding_currency` as FLOAT64) as `refund_amount_holding_currency` ,\n                    cast(`chargeback_amount_holding_currency` as FLOAT64) as `chargeback_amount_holding_currency` ,\n                    cast(`pay_to_card_amount_holding_currency` as FLOAT64) as `pay_to_card_amount_holding_currency` ,\n                    cast(`card_payment_interchange_fee_amount_holding_currency` as FLOAT64) as `card_payment_interchange_fee_amount_holding_currency` ,\n                    cast(`card_payment_scheme_fee_amount_holding_currency` as FLOAT64) as `card_payment_scheme_fee_amount_holding_currency` ,\n                    cast(`acquiring_premium_amount_holding_currency` as FLOAT64) as `acquiring_premium_amount_holding_currency` ,\n                    cast(`card_payment_gateway_fee_amount_holding_currency` as FLOAT64) as `card_payment_gateway_fee_amount_holding_currency` ,\n                    cast(`card_payment_blended_fee_amount_holding_currency` as FLOAT64) as `card_payment_blended_fee_amount_holding_currency` ,\n                    cast(`refunded_interchange_fee_amount_holding_currency` as FLOAT64) as `refunded_interchange_fee_amount_holding_currency` ,\n                    cast(`refund_scheme_fee_amount_holding_currency` as FLOAT64) as `refund_scheme_fee_amount_holding_currency` ,\n                    cast(`refund_gateway_fee_amount_holding_currency` as FLOAT64) as `refund_gateway_fee_amount_holding_currency` ,\n                    cast(`chargeback_fee_amount_holding_currency` as FLOAT64) as `chargeback_fee_amount_holding_currency` ,\n                    cast(`retrievel_fee_amount_holding_currency` as FLOAT64) as `retrievel_fee_amount_holding_currency` ,\n                    cast(`representment_fee_amount_holding_currency` as FLOAT64) as `representment_fee_amount_holding_currency` ,\n                    cast(`pay_to_card_interchange_fee_amount_holding_currency` as FLOAT64) as `pay_to_card_interchange_fee_amount_holding_currency` ,\n                    cast(`pay_to_card_scheme_fee_amount_holding_currency` as FLOAT64) as `pay_to_card_scheme_fee_amount_holding_currency` ,\n                    cast(`pay_to_card_fee_amount_holding_currency` as FLOAT64) as `pay_to_card_fee_amount_holding_currency` ,\n                    cast(`alternative_payment_method_fee_amount_holding_currency` as FLOAT64) as `alternative_payment_method_fee_amount_holding_currency` ,\n                    cast(`adjustment_amount_holding_currency` as FLOAT64) as `adjustment_amount_holding_currency` ,\n                    cast(`tax_amount_holding_currency` as FLOAT64) as `tax_amount_holding_currency` ,\n                    cast(`account_updater_fee_amount_holding_currency` as FLOAT64) as `account_updater_fee_amount_holding_currency` ,\n                    cast(`merchant_payout_fee_amount_holding_currency` as FLOAT64) as `merchant_payout_fee_amount_holding_currency` ,\n                    cast(`pay_to_bank_fee_amount_holding_currency` as FLOAT64) as `pay_to_bank_fee_amount_holding_currency` ,\n                    cast(`pay_to_bank_payout_amount_holding_currency` as FLOAT64) as `pay_to_bank_payout_amount_holding_currency` ,\n                    cast(`transfers_in_amount_holding_currency` as FLOAT64) as `transfers_in_amount_holding_currency` ,\n                    cast(`transfers_out_amount_holding_currency` as FLOAT64) as `transfers_out_amount_holding_currency` ,\n                    cast(`merchant_payout_amount_holding_currency` as FLOAT64) as `merchant_payout_amount_holding_currency` ,\n                    cast(`closing_available_balance_holding_currency` as FLOAT64) as `closing_available_balance_holding_currency` ,\n                    cast(`closing_pending_balance_holding_currency` as FLOAT64) as `closing_pending_balance_holding_currency` ,\n                    cast(`closing_payable_balance_holding_currency` as FLOAT64) as `closing_payable_balance_holding_currency` ,\n                    cast(`closing_collateral_balance_holding_currency` as FLOAT64) as `closing_collateral_balance_holding_currency` ,\n                    cast(`authentication_fees_amount_holding_currency` as FLOAT64) as `authentication_fees_amount_holding_currency` ,\n                    cast(`authentication_scheme_fees_amount_holding_currency` as FLOAT64) as `authentication_scheme_fees_amount_holding_currency` ,\n                    cast(`intelligence_acceptance_fees_amount_holding_currency` as FLOAT64) as `intelligence_acceptance_fees_amount_holding_currency` \n\n            from `dv-vgo-fin-test`.`dbt_dbt_ci_vgo_finance_1962_5079_1`.`stg_d2c_payments__checkout_balance_statement`\n\n            \n        )\n\n        ",)
    )

Screenshots and log output

System information

The contents of your packages.yml file:

packages:
  - package: calogica/dbt_expectations
    version: [">=0.10.0", "<0.11.0"]
  - package: dbt-labs/dbt_utils
    version: [">=1.1.0", "<1.2.0"]
  - package: dbt-labs/codegen
    version: [">=0.9.0", "<1.0.0"]
  - package: dbt-labs/dbt_external_tables
    version: [">=0.9.0", "<0.10.0"]

Which database are you using dbt with?

The output of dbt --version:

1.8.1

Additional context

Are you interested in contributing the fix?