dataform-co/dataform

About error messages during unit tests

Closed this issue · 2 comments

Hello, I conducted the following test:

Test table:

config {
    type: "table",
    schema: "hoge",
    name: "fuga"
}

select
  user_id
from
  ${ref("users")}

Test code:

config {
  type: "test",
  dataset: "fuga",
}

select 1 as user_id union all
select cast(null as int64) as user_id

input "users" {
  select 1 as user_id union all
  select 2 as user_id
}

Even though null is cast to int, the expected message should indicate a value difference as shown here:
https://github.com/dataform-co/dataform/blob/main/cli/api/commands/test.ts#L98

However, the actual message indicates a type difference as shown here:
https://github.com/dataform-co/dataform/blob/main/cli/api/commands/test.ts#L88

I believe this should be corrected. What are your thoughts?

If fixing the type inference is difficult, I would like to propose the following branching as a fix, though it may be somewhat redundant. Is it possible to submit a PR for this?

      // Null value check
      if (expectedValue === null && actualValue !== null) {
        rowMessages.push(
          `For row ${i} and column "${column}": expected null, but saw "${actualValue}".`
        );
        break;
      }
      if (expectedValue !== null && actualValue === null) {
        rowMessages.push(
          `For row ${i} and column "${column}": expected "${expectedValue}", but saw null.`
        );
        break;
      }

Would love for you to patch unit tests with this! The contributing guide is here https://github.com/dataform-co/dataform/blob/main/contributing.md

@Ekrekr
Thank you for your response! I've created the following PR. I would appreciate it if you could review it.

#1812