dataform icon indicating copy to clipboard operation
dataform copied to clipboard

Allow for a flag to indicate that the result order of a test is not important

Open igofunke opened this issue 4 years ago • 3 comments

In some occasions the order of rows of the result of a test is nondeterministic in BigQuery. This makes it very hard to come up with the expected order of rows. There should be some sort of flag in the config block of a test to indicate that the order of expected rows does not matter.

igofunke avatar Sep 08 '21 14:09 igofunke

Could you give an example of when the expected order matters, so that I can add it as a test?

Example using inline assertions from https://cloud.google.com/dataform/docs/assertions#built-in

config {
  type: "table",
  assertions: {
    uniqueKey: ["user_id"],
    nonNull: ["user_id", "customer_id"],
    rowConditions: [
      'row like A',
      'row like B'
    ]
  }
}
SELECT 1

Becomes the execution SQL of:

create or replace view `cloud-dataform-testing.dataform_core_testing.dataform_core_testing_tmp_assertions_rowConditions` as
SELECT
  'row like A' AS failing_row_condition,
  *
FROM `cloud-dataform-testing.dataform_core_testing.tmp`
WHERE NOT (row like A)
UNION ALL
SELECT
  'row like B' AS failing_row_condition,
  *
FROM `cloud-dataform-testing.dataform_core_testing.tmp`
WHERE NOT (row like B)
UNION ALL
SELECT
  'user_id IS NOT NULL' AS failing_row_condition,
  *
FROM `cloud-dataform-testing.dataform_core_testing.tmp`
WHERE NOT (user_id IS NOT NULL)
UNION ALL
SELECT
  'customer_id IS NOT NULL' AS failing_row_condition,
  *
FROM `cloud-dataform-testing.dataform_core_testing.tmp`
WHERE NOT (customer_id IS NOT NULL)

(using bazel run //packages/@dataform/cli:bin run <dir> -- --dry-run --json)

Ekrekr avatar Mar 27 '24 09:03 Ekrekr

I believe @igofunke is talking about dataform unit tests, not assertions.

There used to be docs about unit tests available at dataform.co, but they are gone now and I can't find the equivalent in GCP docs. I looked quickly and this looks like where unit tests are run.

ttogola avatar Apr 11 '24 20:04 ttogola

Any progress on this so far? Its a really important feature...

lucasespinos avatar Jul 17 '24 15:07 lucasespinos