Skip to content

Multiline rowConditions entries lead to invalid SQL #2201

@ByPort

Description

@ByPort

Given the following config:

config {
    type: 'table',
    assertions: {
        rowConditions: [
            `validCheck`,
            `
            invalidCheck
            `,
        ]
    }
}

Dataform compiles assertions into:

SELECT
  'validCheck' AS failing_row_condition,
  *
FROM `project.dataset.test`
WHERE NOT (validCheck)
UNION ALL
SELECT
  '
            invalidCheck
            ' AS failing_row_condition,
  *
FROM `project.dataset.test`
WHERE NOT (
            invalidCheck
            )

The generated SQL is invalid because BigQuery single-quoted string literals cannot span multiple lines. As a result, any multiline rowConditions entry causes a syntax error during execution.

While this is a somewhat synthetic example, more complex expressions can be easier to read and maintain when formatted across multiple lines.

As a workaround, I currently normalize whitespace before passing the condition:

config {
    type: 'table',
    assertions: {
        rowConditions: [
            `validCheck`,
            `
            invalidCheck
            `.replace(/\s+/g, " "),
        ]
    }
}

Possible solutions:

  1. Generate triple-quoted string literals
SELECT
'''
          invalidCheck
          ''' AS failing_row_condition
  1. Escape or normalize newlines before embedding
SELECT
'\n            invalidCheck\n            ' AS failing_row_condition

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions