Skip to content

Commit

Permalink
#374 Remove minimum values for offset types.
Browse files Browse the repository at this point in the history
This is because for inclusive intervals minimums are not needed.
  • Loading branch information
yruslan committed Oct 8, 2024
1 parent 745315b commit 30ee28b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ sealed trait OffsetValue extends Comparable[OffsetValue] {
}

object OffsetValue {
val MINIMUM_TIMESTAMP_EPOCH_MILLI: Long = -62135596800000L

case class DateTimeValue(t: Instant) extends OffsetValue {
override val dataType: OffsetType = OffsetType.DateTimeType

Expand Down Expand Up @@ -78,15 +76,6 @@ object OffsetValue {
}
}

def getMinimumForType(dataType: String): OffsetValue = {
dataType match {
case DATETIME_TYPE_STR => DateTimeValue(Instant.ofEpochMilli(MINIMUM_TIMESTAMP_EPOCH_MILLI)) // LocalDateTime.of(1, 1, 1, 0, 0, 0).toInstant(ZoneOffset.UTC).toEpochMilli
case INTEGRAL_TYPE_STR => IntegralValue(Long.MinValue)
case STRING_TYPE_STR => StringValue("")
case _ => throw new IllegalArgumentException(s"Unknown offset data type: $dataType")
}
}

def fromString(dataType: String, value: String): Option[OffsetValue] = {
if (value.isEmpty)
None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package za.co.absa.pramen.api.offset
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types.{LongType, StringType}
import org.scalatest.wordspec.AnyWordSpec
import za.co.absa.pramen.api.offset.OffsetValue.MINIMUM_TIMESTAMP_EPOCH_MILLI

import java.time.Instant

Expand Down Expand Up @@ -50,32 +49,6 @@ class OffsetValueSuite extends AnyWordSpec {
}
}

"getMinimumForType" should {
"be able to get minimum value for datetime type" in {
val offsetValue = OffsetValue.getMinimumForType("datetime")
assert(offsetValue.dataType == OffsetType.DateTimeType)
assert(offsetValue.valueString == MINIMUM_TIMESTAMP_EPOCH_MILLI.toString)
}

"be able to get minimum value for integral type" in {
val offsetValue = OffsetValue.getMinimumForType("integral")
assert(offsetValue.dataType == OffsetType.IntegralType)
assert(offsetValue.valueString == Long.MinValue.toString)
}

"be able to get minimum value for string type" in {
val offsetValue = OffsetValue.getMinimumForType("string")
assert(offsetValue.dataType == OffsetType.StringType)
assert(offsetValue.valueString == "")
}

"throw an exception when trying to get minimum value for an unknown type" in {
assertThrows[IllegalArgumentException] {
OffsetValue.getMinimumForType("unknown")
}
}
}

"fromString" should {
"return None for an empty string" in {
val offsetValue = OffsetValue.fromString("datetime", "")
Expand Down

0 comments on commit 30ee28b

Please sign in to comment.