@@ -340,11 +340,38 @@ public Expression.Literal from(io.substrait.proto.Expression.Literal literal) {
340
340
literal .getNullable (),
341
341
literal .getIntervalYearToMonth ().getYears (),
342
342
literal .getIntervalYearToMonth ().getMonths ());
343
- case INTERVAL_DAY_TO_SECOND -> ExpressionCreator .intervalDay (
344
- literal .getNullable (),
345
- literal .getIntervalDayToSecond ().getDays (),
346
- literal .getIntervalDayToSecond ().getSeconds (),
347
- literal .getIntervalDayToSecond ().getMicroseconds ());
343
+ case INTERVAL_DAY_TO_SECOND -> {
344
+ // Handle deprecated version that doesn't provide precision and that uses microseconds
345
+ // instead of subseconds, for backwards compatibility
346
+ int precision =
347
+ literal .getIntervalDayToSecond ().hasPrecision ()
348
+ ? literal .getIntervalDayToSecond ().getPrecision ()
349
+ : 6 ; // microseconds
350
+ long subseconds =
351
+ literal .getIntervalDayToSecond ().hasPrecision ()
352
+ ? literal .getIntervalDayToSecond ().getSubseconds ()
353
+ : literal .getIntervalDayToSecond ().getMicroseconds ();
354
+ yield ExpressionCreator .intervalDay (
355
+ literal .getNullable (),
356
+ literal .getIntervalDayToSecond ().getDays (),
357
+ literal .getIntervalDayToSecond ().getSeconds (),
358
+ subseconds ,
359
+ precision );
360
+ }
361
+ case INTERVAL_COMPOUND -> {
362
+ if (!literal .getIntervalCompound ().getIntervalDayToSecond ().hasPrecision ()) {
363
+ throw new RuntimeException (
364
+ "Interval compound with deprecated version of interval day (ie. no precision) is not supported" );
365
+ }
366
+ yield ExpressionCreator .intervalCompound (
367
+ literal .getNullable (),
368
+ literal .getIntervalCompound ().getIntervalYearToMonth ().getYears (),
369
+ literal .getIntervalCompound ().getIntervalYearToMonth ().getMonths (),
370
+ literal .getIntervalCompound ().getIntervalDayToSecond ().getDays (),
371
+ literal .getIntervalCompound ().getIntervalDayToSecond ().getSeconds (),
372
+ literal .getIntervalCompound ().getIntervalDayToSecond ().getSubseconds (),
373
+ literal .getIntervalCompound ().getIntervalDayToSecond ().getPrecision ());
374
+ }
348
375
case FIXED_CHAR -> ExpressionCreator .fixedChar (literal .getNullable (), literal .getFixedChar ());
349
376
case VAR_CHAR -> ExpressionCreator .varChar (
350
377
literal .getNullable (), literal .getVarChar ().getValue (), literal .getVarChar ().getLength ());
0 commit comments