Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match Iceberg transforms for negative epoch values #5273

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public final class PartitionTransforms

private static final DateTimeField YEAR_FIELD = ISOChronology.getInstanceUTC().year();
private static final DateTimeField MONTH_FIELD = ISOChronology.getInstanceUTC().monthOfYear();
private static final DateTimeField DAY_OF_YEAR_FIELD = ISOChronology.getInstanceUTC().dayOfYear();
private static final DateTimeField DAY_OF_MONTH_FIELD = ISOChronology.getInstanceUTC().dayOfMonth();

private PartitionTransforms() {}

Expand Down Expand Up @@ -493,27 +495,50 @@ private static Block truncateVarbinary(Block block, int max)
}

@VisibleForTesting
static long epochYear(long epochMillis)
static long epochYear(long epochMilli)
{
return YEAR_FIELD.get(epochMillis) - 1970;
int epochYear = YEAR_FIELD.get(epochMilli) - 1970;
// Iceberg incorrectly handles negative epoch values
if ((epochMilli < 0) && ((DAY_OF_YEAR_FIELD.get(epochMilli) > 1) || !isMidnight(epochMilli))) {
epochYear++;
}
return epochYear;
}

@VisibleForTesting
static long epochMonth(long epochMilli)
{
long year = epochYear(epochMilli);
long year = YEAR_FIELD.get(epochMilli) - 1970;
int month = MONTH_FIELD.get(epochMilli) - 1;
return (year * 12) + month;
long epochMonth = (year * 12) + month;
// Iceberg incorrectly handles negative epoch values
if ((epochMilli < 0) && ((DAY_OF_MONTH_FIELD.get(epochMilli) > 1) || !isMidnight(epochMilli))) {
epochMonth++;
}
return epochMonth;
}

@VisibleForTesting
static long epochDay(long epochMilli)
{
long epochDay = floorDiv(epochMilli, MILLISECONDS_PER_DAY);
// Iceberg incorrectly handles negative epoch values
if ((epochMilli < 0) && !isMidnight(epochMilli)) {
epochDay++;
}
return epochDay;
}

private static long epochDay(long epochMilli)
@VisibleForTesting
static long epochHour(long epochMilli)
{
return floorDiv(epochMilli, MILLISECONDS_PER_DAY);
// Iceberg incorrectly handles negative epoch values
return epochMilli / MILLISECONDS_PER_HOUR;
}

private static long epochHour(long epochMilli)
private static boolean isMidnight(long epochMilli)
{
return floorDiv(epochMilli, MILLISECONDS_PER_HOUR);
return (epochMilli % MILLISECONDS_PER_DAY) == 0;
}

public static class ColumnTransform
Expand Down
Loading