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

[GH-15810] Allow the user to adjust parquet import timezone #16304

Open
wants to merge 5 commits into
base: rel-3.46.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -13,6 +13,8 @@

import java.time.Instant;

import static water.H2O.OptArgs.SYSTEM_PROP_PREFIX;

/**
* Implementation of Parquet's GroupConverter for H2O's chunks.
*
Expand Down Expand Up @@ -303,25 +305,42 @@ public void addBinary(Binary value) {
}

private static class TimestampConverter extends PrimitiveConverter {
public final static String TIMESTAMP_ADJUSTMENT = SYSTEM_PROP_PREFIX + "parquet.import.timestamp.adjustment";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add comment what value we expecting here? I saw it from the tests that it a number representing the hours. What happen if user put something outside of +-24?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no limit basically, someone can adjust for example +- a month

public static final long MILLIS_IN_AN_HOUR = 60 * 60 * 1000;

private final int _colIdx;
private final WriterDelegate _writer;

private int timeStampAdjustmentHours = 0;

TimestampConverter(int _colIdx, WriterDelegate _writer) {
this._colIdx = _colIdx;
this._writer = _writer;
if (System.getProperty(TIMESTAMP_ADJUSTMENT) != null) {
String timestampHours = System.getProperty(TIMESTAMP_ADJUSTMENT);
try {
timeStampAdjustmentHours = Integer.parseInt(timestampHours);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Error parsing " + TIMESTAMP_ADJUSTMENT + ", it should be hours as integer.");
}
}
}

@Override
public void addLong(long value) {
_writer.addNumCol(_colIdx, value, 0);
_writer.addNumCol(_colIdx, adjustTimestamp(value), 0);
}

@Override
public void addBinary(Binary value) {
final long timestampMillis = ParquetInt96TimestampConverter.getTimestampMillis(value);

_writer.addNumCol(_colIdx, timestampMillis);
_writer.addNumCol(_colIdx, adjustTimestamp(timestampMillis));
}

private long adjustTimestamp(long value) {
long adjustment = (long) timeStampAdjustmentHours * MILLIS_IN_AN_HOUR;
return value + adjustment;
}
}

Expand Down
24 changes: 24 additions & 0 deletions h2o-py/tests/testdir_parser/pyunit_parquet_adjust_timezone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys

sys.path.insert(1, "../../../")
from tests import pyunit_utils
from h2o.frame import H2OFrame
import tempfile
import h2o

'''
Adjust timestamp parquet
'''

def adjust_timestamp_parquet():
with tempfile.TemporaryDirectory() as dir:
timestamp_df = H2OFrame({"timestamp": '2024-06-06 06:06:06'})
h2o.export_file(timestamp_df, path=dir, format="parquet", write_checksum=False)
imported_df = h2o.import_file(dir)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to have this option as an export_file parameter..

I see you implement the workaround

manipulate the data before saving

What if user want to manipulate data into different timezones? In this case, they need to restart the cloud with the new jvm arguments.

Am I right or I just overthinking it and its not a probable usecase?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what if user want to adjust the timezone just for the one file, and leave it "as is" for the rest of them? It will also require a restart

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the story was that the users were importing a file and were expecting to see their timezone - the same behavior as Apache Spark if I'm not mistaken - spark is assuming the timestamp is in GMT and then showing it to the user in their own timezone - we do not do that, we just show the "real" value
so the purpose is for the system administrator to just set it so the users do not have to care about it
of course all those points you're mentioning are valid and it's possible that questions will come

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more technical user can adjust on their own though, but very valid points!

Copy link
Collaborator

@valenad1 valenad1 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main user experience issue is that you need to think about the future import of parquet file when you start the h2o. I think its worth to have it as an import (not export) option in the function. WDYT @wendycwong?

Come to think of it, what happen if you import your file with sys.ai.h2o.parquet.import.timestamp.adjustment=2
and export it. IMHO it will export it with +2hours.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

expected_df = H2OFrame({"timestamp": '2024-06-06 08:06:06'})
pyunit_utils.compare_frames(expected_df, imported_df, numElements=1)

if __name__ == "__main__":
pyunit_utils.standalone_test(adjust_timestamp_parquet, init_options={"jvm_custom_args": ["-Dsys.ai.h2o.parquet.import.timestamp.adjustment=2"]})
else:
adjust_timestamp_parquet()
Loading