Skip to content

Commit

Permalink
Support negative steps in Faker sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Dec 29, 2024
1 parent cb6b72e commit 021867e
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ private static ValueSet stepValue(ColumnMetadata column)
}
if (DATE.equals(column.getType()) || type instanceof TimestampType || type instanceof TimestampWithTimeZoneType || type instanceof TimeType || type instanceof TimeWithTimeZoneType) {
try {
return ValueSet.of(BIGINT, Duration.valueOf(rawStep).roundTo(TimeUnit.NANOSECONDS));
byte sign = 1;
if (rawStep.charAt(0) == '-') {
rawStep = rawStep.substring(1);
sign = -1;
}
return ValueSet.of(BIGINT, sign * Duration.valueOf(rawStep).roundTo(TimeUnit.NANOSECONDS));
}
catch (IllegalArgumentException e) {
throw new TrinoException(INVALID_COLUMN_PROPERTY, "The `%s` property for a %s column must be a valid duration literal".formatted(STEP_PROPERTY, column.getType().getDisplayName()), e);
Expand Down
Loading

0 comments on commit 021867e

Please sign in to comment.