@@ -576,41 +576,23 @@ public static Expression fromUnixTime(BigIntLiteral second, StringLikeLiteral fo
576576 */
577577 @ ExecFunction (name = "from_unixtime" )
578578 public static Expression fromUnixTime (DecimalLiteral second , StringLikeLiteral format ) {
579- format = (StringLikeLiteral ) SupportJavaDateFormatter .translateJavaFormatter (format );
580-
581- if (second .getValue ().signum () < 0 ) {
582- throw new AnalysisException ("Operation from_unixtime of " + second .getValue () + " out of range" );
583- }
584-
585- BigDecimal decimalVal = second .getValue ();
586- BigDecimal microSeconds = decimalVal .movePointRight (decimalVal .scale ()).setScale (0 , RoundingMode .DOWN );
587- ZonedDateTime dateTime = LocalDateTime .of (1970 , 1 , 1 , 0 , 0 , 0 )
588- .plus (microSeconds .longValue (), ChronoUnit .MICROS )
589- .atZone (ZoneId .of ("UTC+0" ))
590- .toOffsetDateTime ()
591- .atZoneSameInstant (DateUtils .getTimeZone ());
592- DateTimeV2Literal datetime = new DateTimeV2Literal (DateTimeV2Type .of (6 ), dateTime .getYear (),
593- dateTime .getMonthValue (),
594- dateTime .getDayOfMonth (), dateTime .getHour (), dateTime .getMinute (), dateTime .getSecond (),
595- dateTime .getNano () / 1000 );
596- if (datetime .checkRange ()) {
597- throw new AnalysisException ("Operation from_unixtime of " + second .getValue () + " out of range" );
598- }
599- return dateFormat (datetime , format );
579+ return fromUnixTime (second .getValue (), format );
600580 }
601581
602582 /**
603583 * date transformation function: from_unixtime
604584 */
605585 @ ExecFunction (name = "from_unixtime" )
606586 public static Expression fromUnixTime (DecimalV3Literal second , StringLikeLiteral format ) {
607- format = (StringLikeLiteral ) SupportJavaDateFormatter .translateJavaFormatter (format );
587+ return fromUnixTime (second .getValue (), format );
588+ }
608589
609- if (second .getValue ().signum () < 0 ) {
610- throw new AnalysisException ("Operation from_unixtime of " + second .getValue () + " out of range" );
590+ private static Expression fromUnixTime (BigDecimal second , StringLikeLiteral format ) {
591+ if (second .signum () < 0 ) {
592+ throw new AnalysisException ("Operation from_unixtime of " + second + " out of range" );
611593 }
612- BigDecimal decimalVal = second . getValue ( );
613- BigDecimal microSeconds = decimalVal .movePointRight (decimalVal .scale ()).setScale (0 , RoundingMode .DOWN );
594+ format = ( StringLikeLiteral ) SupportJavaDateFormatter . translateJavaFormatter ( format );
595+ BigDecimal microSeconds = second .movePointRight (second .scale ()).setScale (0 , RoundingMode .DOWN );
614596 ZonedDateTime dateTime = LocalDateTime .of (1970 , 1 , 1 , 0 , 0 , 0 )
615597 .plus (microSeconds .longValue (), ChronoUnit .MICROS )
616598 .atZone (ZoneId .of ("UTC+0" ))
@@ -621,7 +603,7 @@ public static Expression fromUnixTime(DecimalV3Literal second, StringLikeLiteral
621603 dateTime .getDayOfMonth (), dateTime .getHour (), dateTime .getMinute (), dateTime .getSecond (),
622604 dateTime .getNano () / 1000 );
623605 if (datetime .checkRange ()) {
624- throw new AnalysisException ("Operation from_unixtime of " + second . getValue () + " out of range" );
606+ throw new AnalysisException ("Operation from_unixtime of " + second + " out of range" );
625607 }
626608 return dateFormat (datetime , format );
627609 }
0 commit comments