@@ -127,7 +127,12 @@ public static Slice currentTimeZone(ConnectorSession session)
127127 public static long fromUnixTime (ConnectorSession session , @ SqlType (StandardTypes .DOUBLE ) double unixTime )
128128 {
129129 // TODO (https://github.com/trinodb/trino/issues/5781)
130- return packDateTimeWithZone (Math .round (unixTime * 1000 ), session .getTimeZoneKey ());
130+ try {
131+ return packDateTimeWithZone (Math .round (unixTime * 1000 ), session .getTimeZoneKey ());
132+ }
133+ catch (IllegalArgumentException e ) {
134+ throw new TrinoException (INVALID_FUNCTION_ARGUMENT , e );
135+ }
131136 }
132137
133138 @ ScalarFunction ("from_unixtime" )
@@ -137,19 +142,24 @@ public static long fromUnixTime(@SqlType(StandardTypes.DOUBLE) double unixTime,
137142 TimeZoneKey timeZoneKey ;
138143 try {
139144 timeZoneKey = getTimeZoneKeyForOffset (toIntExact (hoursOffset * 60 + minutesOffset ));
145+ return packDateTimeWithZone (Math .round (unixTime * 1000 ), timeZoneKey );
140146 }
141147 catch (IllegalArgumentException e ) {
142148 throw new TrinoException (INVALID_FUNCTION_ARGUMENT , e );
143149 }
144- return packDateTimeWithZone (Math .round (unixTime * 1000 ), timeZoneKey );
145150 }
146151
147152 @ ScalarFunction ("from_unixtime" )
148153 @ LiteralParameters ("x" )
149154 @ SqlType ("timestamp(3) with time zone" )
150155 public static long fromUnixTime (@ SqlType (StandardTypes .DOUBLE ) double unixTime , @ SqlType ("varchar(x)" ) Slice zoneId )
151156 {
152- return packDateTimeWithZone (Math .round (unixTime * 1000 ), zoneId .toStringUtf8 ());
157+ try {
158+ return packDateTimeWithZone (Math .round (unixTime * 1000 ), zoneId .toStringUtf8 ());
159+ }
160+ catch (IllegalArgumentException e ) {
161+ throw new TrinoException (INVALID_FUNCTION_ARGUMENT , e );
162+ }
153163 }
154164
155165 @ ScalarFunction ("from_unixtime_nanos" )
@@ -172,7 +182,12 @@ public static LongTimestampWithTimeZone fromLong(@LiteralParameter("s") long sca
172182 epochSeconds -= 1 ;
173183 picosOfSecond += PICOSECONDS_PER_SECOND ;
174184 }
175- return DateTimes .longTimestampWithTimeZone (epochSeconds , picosOfSecond , session .getTimeZoneKey ().getZoneId ());
185+ try {
186+ return DateTimes .longTimestampWithTimeZone (epochSeconds , picosOfSecond , session .getTimeZoneKey ().getZoneId ());
187+ }
188+ catch (ArithmeticException e ) {
189+ throw new TrinoException (INVALID_FUNCTION_ARGUMENT , e );
190+ }
176191 }
177192
178193 @ LiteralParameters ({"p" , "s" })
@@ -216,7 +231,12 @@ public static long fromISO8601Timestamp(ConnectorSession session, @SqlType("varc
216231 DateTimeFormatter formatter = ISODateTimeFormat .dateTimeParser ()
217232 .withChronology (getChronology (session .getTimeZoneKey ()))
218233 .withOffsetParsed ();
219- return packDateTimeWithZone (parseDateTimeHelper (formatter , iso8601DateTime .toStringUtf8 ()));
234+ try {
235+ return packDateTimeWithZone (parseDateTimeHelper (formatter , iso8601DateTime .toStringUtf8 ()));
236+ }
237+ catch (IllegalArgumentException e ) {
238+ throw new TrinoException (INVALID_FUNCTION_ARGUMENT , e );
239+ }
220240 }
221241
222242 @ ScalarFunction ("from_iso8601_timestamp_nanos" )
0 commit comments