Skip to content

Commit

Permalink
Fixed Energy.toString and mandatory parquet value omission
Browse files Browse the repository at this point in the history
Before this change, a lower energy value was printed in KJoule and a
higher one in Joule. This change reverses it.

Before this change no exception was thrown when omitting value in
a required parquet field while exporting, resulting in unreadable
parquet file. Now exception is thrown while exporting.
  • Loading branch information
T0mexX committed Aug 24, 2024
1 parent f9ffdfb commit 3a22d9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public value class Energy private constructor(
override fun toString(): String = fmtValue()

override fun fmtValue(fmt: String): String =
if (value >= 1000.0) {
if (value <= 1000.0) {
"${toJoule().fmt(fmt)} Joule"
} else {
"${toKJoule().fmt(fmt)} KJoule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.DOUBLE
import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.FLOAT
import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32
import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT64
import org.apache.parquet.schema.Type
import org.apache.parquet.schema.Types
import org.opendc.trace.util.parquet.ParquetDataWriter
import java.io.File
Expand Down Expand Up @@ -122,7 +123,13 @@ public class Exporter<T : Exportable>
val valueToAdd: Any =
column.getValue(
record,
) ?: return@forEachIndexed // Maybe add explicit check for optional fields
) ?: let {

Check warning on line 126 in opendc-trace/opendc-trace-parquet/src/main/kotlin/org/opendc/trace/util/parquet/exporter/Exporter.kt

View check run for this annotation

Codecov / codecov/patch

opendc-trace/opendc-trace-parquet/src/main/kotlin/org/opendc/trace/util/parquet/exporter/Exporter.kt#L126

Added line #L126 was not covered by tests
if (column.field.isRepetition(Type.Repetition.OPTIONAL)) {
return@forEachIndexed

Check warning on line 128 in opendc-trace/opendc-trace-parquet/src/main/kotlin/org/opendc/trace/util/parquet/exporter/Exporter.kt

View check run for this annotation

Codecov / codecov/patch

opendc-trace/opendc-trace-parquet/src/main/kotlin/org/opendc/trace/util/parquet/exporter/Exporter.kt#L128

Added line #L128 was not covered by tests
} else {
throw RuntimeException("trying to insert null value in required column $column")

Check warning on line 130 in opendc-trace/opendc-trace-parquet/src/main/kotlin/org/opendc/trace/util/parquet/exporter/Exporter.kt

View check run for this annotation

Codecov / codecov/patch

opendc-trace/opendc-trace-parquet/src/main/kotlin/org/opendc/trace/util/parquet/exporter/Exporter.kt#L130

Added line #L130 was not covered by tests
}
}

startField(column.name, idx)
when (column.primitiveTypeName) {
Expand Down

0 comments on commit 3a22d9a

Please sign in to comment.