Skip to content
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 @@ -119,9 +119,18 @@ interface ProcessingPlatformTransformer : ProcessingPlatformRenderer {
DSL.field(field.fullName(), Float::class.java).div(numericRounding.floor.divisor)
).multiply(numericRounding.floor.divisor)

NumericRounding.RoundingCase.ROUND -> DSL.round(
DSL.field(field.fullName(), Float::class.java), numericRounding.round.precision
)
NumericRounding.RoundingCase.ROUND -> {
if (numericRounding.round.hasDivisor()) {
DSL.round(
DSL.field(field.fullName(), Float::class.java).div(numericRounding.round.divisor),
numericRounding.round.precision
).multiply(numericRounding.round.divisor)
} else {
DSL.round(
DSL.field(field.fullName(), Float::class.java), numericRounding.round.precision
)
}
}

NumericRounding.RoundingCase.ROUNDING_NOT_SET, null -> throw InternalException(
InternalException.Code.INTERNAL,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,37 @@ class DefaultProcessingPlatformTransformerTest {
}

@Test
fun `numeric rounding - round`() {
fun `numeric rounding - round without divisor`() {
// Given
val field = namedField("transactionamount", "integer")
val ceil = DataPolicy.RuleSet.FieldTransform.Transform.NumericRounding.newBuilder()
val round = DataPolicy.RuleSet.FieldTransform.Transform.NumericRounding.newBuilder()
.setRound(
DataPolicy.RuleSet.FieldTransform.Transform.NumericRounding.Round.newBuilder().setPrecision(-1)
).build()

// When
val result = DefaultProcessingPlatformTransformer.numericRounding(field, ceil)
val result = DefaultProcessingPlatformTransformer.numericRounding(field, round)

// Then
result.toSql() shouldBe "round(transactionamount, -1)"
}

@Test
fun `numeric rounding - round with divisor`() {
// Given
val field = namedField("transactionamount", "integer")
val round = DataPolicy.RuleSet.FieldTransform.Transform.NumericRounding.newBuilder()
.setRound(
DataPolicy.RuleSet.FieldTransform.Transform.NumericRounding.Round.newBuilder().setPrecision(0).setDivisor(5f)
).build()

// When
val result = DefaultProcessingPlatformTransformer.numericRounding(field, round)

// Then
result.toSql() shouldBe "(round((transactionamount / 5E0), 0) * 5E0)"
}

@Test
fun `aggregation - sum no partition by`() {
// Given
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ springCloudKubernetesVersion=3.1.0

dockertag = pace-local

generatedBufDependencyVersion=00000000000000.934197b6cd79
generatedBufDependencyVersion=00000000000000.385fc313a85f
4 changes: 3 additions & 1 deletion protos/getstrm/pace/api/entities/v1alpha/entities.proto
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ message DataPolicy {
message Round {
// The precision to use for rounding. When positive, the value is rounded to the nearest decimal place. When negative, the value is rounded to the nearest power of 10.
int32 precision = 1;
// The divisor to use when applying integer division. Advise is to use divisors only when rounding to a multiple of that divisor, with a precision of 0.
optional float divisor = 2;
}
}

Expand Down Expand Up @@ -317,4 +319,4 @@ message DataCatalog {
Schema schema = 3;
repeated string tags = 4;
}
}
}