You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "bobbai00 (via GitHub)" <gi...@apache.org> on 2025/12/28 21:14:53 UTC

Re: [PR] fix: support more java.time inputs in timestamp parsing [texera]

bobbai00 commented on code in PR #4139:
URL: https://github.com/apache/texera/pull/4139#discussion_r2649934023


##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/AttributeTypeUtils.scala:
##########
@@ -201,10 +201,15 @@ object AttributeTypeUtils extends Serializable {
   def parseTimestamp(fieldValue: Any): Timestamp = {
     val attempt: Try[Timestamp] = Try {
       fieldValue match {
-        case str: String          => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
-        case long: java.lang.Long => new Timestamp(long)
-        case timestamp: Timestamp => timestamp
-        case date: java.util.Date => new Timestamp(date.getTime)
+        case str: String                   => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
+        case long: java.lang.Long          => new Timestamp(long)
+        case timestamp: Timestamp          => timestamp
+        case date: java.util.Date          => new Timestamp(date.getTime)
+        case ldt: java.time.LocalDateTime  => Timestamp.valueOf(ldt)

Review Comment:
   please use `localDateTime` as variable name, not `ldt`.



##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/AttributeTypeUtils.scala:
##########
@@ -201,10 +201,15 @@ object AttributeTypeUtils extends Serializable {
   def parseTimestamp(fieldValue: Any): Timestamp = {
     val attempt: Try[Timestamp] = Try {
       fieldValue match {
-        case str: String          => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
-        case long: java.lang.Long => new Timestamp(long)
-        case timestamp: Timestamp => timestamp
-        case date: java.util.Date => new Timestamp(date.getTime)
+        case str: String                   => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
+        case long: java.lang.Long          => new Timestamp(long)
+        case timestamp: Timestamp          => timestamp
+        case date: java.util.Date          => new Timestamp(date.getTime)
+        case ldt: java.time.LocalDateTime  => Timestamp.valueOf(ldt)
+        case inst: java.time.Instant       => Timestamp.from(inst)
+        case odt: java.time.OffsetDateTime => Timestamp.from(odt.toInstant)
+        case zdt: java.time.ZonedDateTime  => Timestamp.from(zdt.toInstant)

Review Comment:
   ditto



##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/AttributeTypeUtils.scala:
##########
@@ -201,10 +201,15 @@ object AttributeTypeUtils extends Serializable {
   def parseTimestamp(fieldValue: Any): Timestamp = {
     val attempt: Try[Timestamp] = Try {
       fieldValue match {
-        case str: String          => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
-        case long: java.lang.Long => new Timestamp(long)
-        case timestamp: Timestamp => timestamp
-        case date: java.util.Date => new Timestamp(date.getTime)
+        case str: String                   => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
+        case long: java.lang.Long          => new Timestamp(long)
+        case timestamp: Timestamp          => timestamp
+        case date: java.util.Date          => new Timestamp(date.getTime)
+        case ldt: java.time.LocalDateTime  => Timestamp.valueOf(ldt)
+        case inst: java.time.Instant       => Timestamp.from(inst)
+        case odt: java.time.OffsetDateTime => Timestamp.from(odt.toInstant)
+        case zdt: java.time.ZonedDateTime  => Timestamp.from(zdt.toInstant)
+        case ld: java.time.LocalDate       => Timestamp.valueOf(ld.atStartOfDay())

Review Comment:
   ditto



##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/AttributeTypeUtils.scala:
##########
@@ -201,10 +201,15 @@ object AttributeTypeUtils extends Serializable {
   def parseTimestamp(fieldValue: Any): Timestamp = {
     val attempt: Try[Timestamp] = Try {
       fieldValue match {
-        case str: String          => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
-        case long: java.lang.Long => new Timestamp(long)
-        case timestamp: Timestamp => timestamp
-        case date: java.util.Date => new Timestamp(date.getTime)
+        case str: String                   => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
+        case long: java.lang.Long          => new Timestamp(long)
+        case timestamp: Timestamp          => timestamp
+        case date: java.util.Date          => new Timestamp(date.getTime)
+        case ldt: java.time.LocalDateTime  => Timestamp.valueOf(ldt)
+        case inst: java.time.Instant       => Timestamp.from(inst)

Review Comment:
   ditto



##########
common/workflow-core/src/test/scala/org/apache/texera/amber/core/tuple/AttributeTypeUtilsSpec.scala:
##########
@@ -179,9 +182,40 @@ class AttributeTypeUtilsSpec extends AnyFunSuite {
         .getTime == 1699820130000L
     )
 
+    val ldt = LocalDateTime.of(2023, 11, 13, 10, 15, 30)

Review Comment:
   ditto for all these variables



##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/AttributeTypeUtils.scala:
##########
@@ -201,10 +201,15 @@ object AttributeTypeUtils extends Serializable {
   def parseTimestamp(fieldValue: Any): Timestamp = {
     val attempt: Try[Timestamp] = Try {
       fieldValue match {
-        case str: String          => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
-        case long: java.lang.Long => new Timestamp(long)
-        case timestamp: Timestamp => timestamp
-        case date: java.util.Date => new Timestamp(date.getTime)
+        case str: String                   => new Timestamp(DateParserUtils.parseDate(str.trim).getTime)
+        case long: java.lang.Long          => new Timestamp(long)
+        case timestamp: Timestamp          => timestamp
+        case date: java.util.Date          => new Timestamp(date.getTime)
+        case ldt: java.time.LocalDateTime  => Timestamp.valueOf(ldt)
+        case inst: java.time.Instant       => Timestamp.from(inst)
+        case odt: java.time.OffsetDateTime => Timestamp.from(odt.toInstant)

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org