Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for Bytes to ColumnSumCheck #45

Merged
merged 1 commit into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ case class ColumnSumCheck(
case LongType => evaluate(r.getLong(idx))
case FloatType => evaluate(r.getFloat(idx))
case DoubleType => evaluate(r.getDouble(idx))
case ByteType => evaluate(r.getByte(idx))
case ut => throw new Exception(s"Unsupported type for $name found in schema: $ut")
colindean marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
1 change: 1 addition & 0 deletions src/test/scala/com/target/data_validator/TestHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object TestHelpers {
case "java.lang.Double" => DoubleType
case "java.lang.Boolean" => BooleanType
case "java.lang.Long" => LongType
case "java.lang.Byte" => ByteType
case _ => throw new IllegalArgumentException(s"Unknown type '${v.getClass.getCanonicalName}'")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,22 @@ class ColumnSumCheckSpec extends FunSpec with Matchers with TestingSparkSession
assert(!sut.failed)
}

it("upper bound success") {
it("upper bound success with short") {
val check = ColumnSumCheck("foo", maxValue = Some(Json.fromDouble(10).get)) // scalastyle:ignore magic.number
val df = mkDf(spark, "foo" -> List[Short](1, 2, 1))
val sut = ValidatorDataFrame(df, None, None, List(check))
assert(!sut.quickChecks(spark, mkDict())(config))
assert(!sut.failed)
}

it("upper bound success with byte") {
val check = ColumnSumCheck("foo", maxValue = Some(Json.fromDouble(10).get)) // scalastyle:ignore magic.number
val df = mkDf(spark, "foo" -> List[Byte](1, 2, 1))
val sut = ValidatorDataFrame(df, None, None, List(check))
assert(!sut.quickChecks(spark, mkDict())(config))
assert(!sut.failed)
}

it("upper bound failure") {
val check = ColumnSumCheck("foo", maxValue = Some(Json.fromFloat(1).get)) // scalastyle:ignore magic.number
val df = mkDf(spark, "foo" -> List(1L, 1L, 1L))
Expand Down