-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check fields by name when we can
In some cases we do not care about the order of the fields as long as the name and type matches.
- Loading branch information
Showing
4 changed files
with
106 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package no.nrk.bigquery | ||
|
||
import com.google.cloud.bigquery.{Field, StandardSQLTypeName} | ||
import munit.FunSuite | ||
|
||
class conformsTest extends FunSuite { | ||
test("failing check by index") { | ||
val res = conforms( | ||
BQSchema.of( | ||
BQField("one", StandardSQLTypeName.STRING, Field.Mode.NULLABLE), | ||
BQField("two", StandardSQLTypeName.INT64, Field.Mode.NULLABLE) | ||
), | ||
BQSchema.of( | ||
BQField("one", StandardSQLTypeName.INT64, Field.Mode.NULLABLE), | ||
BQField("two", StandardSQLTypeName.STRING, Field.Mode.NULLABLE) | ||
), | ||
checkIndex = true | ||
) | ||
assertEquals(res.map(_.length), Some(2), clue(res.map(_.mkString(", ")))) | ||
} | ||
|
||
test("passing check by index") { | ||
val res = conforms( | ||
BQSchema.of( | ||
BQField("one", StandardSQLTypeName.STRING, Field.Mode.NULLABLE), | ||
BQField("two", StandardSQLTypeName.INT64, Field.Mode.NULLABLE) | ||
), | ||
BQSchema.of( | ||
BQField("one", StandardSQLTypeName.STRING, Field.Mode.NULLABLE), | ||
BQField("two", StandardSQLTypeName.INT64, Field.Mode.NULLABLE) | ||
), | ||
checkIndex = true | ||
) | ||
assertEquals(res.map(_.length), None, clue(res.map(_.mkString(", ")))) | ||
} | ||
|
||
test("passing check by name") { | ||
val res = conforms( | ||
BQSchema.of( | ||
BQField("one", StandardSQLTypeName.STRING, Field.Mode.NULLABLE), | ||
BQField("two", StandardSQLTypeName.INT64, Field.Mode.NULLABLE) | ||
), | ||
BQSchema.of( | ||
BQField("two", StandardSQLTypeName.INT64, Field.Mode.NULLABLE), | ||
BQField("one", StandardSQLTypeName.STRING, Field.Mode.NULLABLE) | ||
), | ||
checkIndex = false | ||
) | ||
assertEquals(res.map(_.length), None, clue(res.map(_.mkString(", ")))) | ||
} | ||
|
||
test("failing check by name") { | ||
val res = conforms( | ||
BQSchema.of( | ||
BQField("one", StandardSQLTypeName.STRING, Field.Mode.NULLABLE), | ||
BQField("two", StandardSQLTypeName.INT64, Field.Mode.NULLABLE) | ||
), | ||
BQSchema.of( | ||
BQField("two", StandardSQLTypeName.STRING, Field.Mode.NULLABLE), | ||
BQField("one", StandardSQLTypeName.INT64, Field.Mode.NULLABLE) | ||
), | ||
checkIndex = false | ||
) | ||
assertEquals(res.map(_.length), Some(2), clue(res.map(_.mkString(", ")))) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters