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

Add support for from_utc_timestamp in Hive->Trino translation #109

Merged
merged 1 commit into from
Aug 10, 2021

Conversation

losipiuk
Copy link
Contributor

@losipiuk losipiuk commented Jul 8, 2021

@losipiuk
Copy link
Contributor Author

losipiuk commented Jul 12, 2021

@wmoustafa, @shenodaguirguis PTAL when you have a chance

{ "test", "get_json_object_view", "SELECT \"json_extract\"(\"b\".\"b1\", '$.name')\nFROM \"test\".\"tablea\"" },

{ "test", "view_from_utc_timestamp", "SELECT "
+ "CAST(\"at_timezone\"(\"from_unixtime_nanos\"(CAST(\"a_tinyint\" AS BIGINT) * 1000000), 'America/Los_Angeles') AS TIMESTAMP), "
Copy link
Contributor

Choose a reason for hiding this comment

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

TIMESTAMP is just an alias to timestamp(3), so:

AS TIMESTAMP -> AS timestamp(3)

plus, add "TODO trinodb/trino#6295 support high-precision timestamp"

+ "CAST(\"at_timezone\"(\"from_unixtime_nanos\"(CAST(\"a_tinyint\" AS BIGINT) * 1000000), 'America/Los_Angeles') AS TIMESTAMP), "
+ "CAST(\"at_timezone\"(\"from_unixtime_nanos\"(CAST(\"a_smallint\" AS BIGINT) * 1000000), 'America/Los_Angeles') AS TIMESTAMP), "
+ "CAST(\"at_timezone\"(\"from_unixtime_nanos\"(CAST(\"a_integer\" AS BIGINT) * 1000000), 'America/Los_Angeles') AS TIMESTAMP), "
+ "CAST(\"at_timezone\"(\"from_unixtime_nanos\"(CAST(\"a_bigint\" AS BIGINT) * 1000000), 'America/Los_Angeles') AS TIMESTAMP), "
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you consider using from_unixtime (without _nanos), to stay with lower precision timestamp where possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I think I itiially though that from_unixtime only allows for second precision.
I updated the case for fractional types to use from_unixtime. For bigint/integer/smallint/tinyint I left from_unixtime_nanos to avoid unnecessary to_double conversion and division.

if (call.getOperator().getName().equals("from_utc_timestamp")) {
Optional<RexNode> modifiedCall = visitFromUtcTimestampCall(call);
if (modifiedCall.isPresent()) {
return modifiedCall.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it possible to handle this with a UDFTransformer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is very limited right now. It feels extending it would be painful. Basically what we would need to do is to allow expressing logic I have here coded in Java in JSON we pass, to setup parameter translation. I strongly belive java code is better tool for the job.


List<RexNode> convertedOperands = visitList(call.getOperands(), (boolean[]) null);
RexNode sourceValue = convertedOperands.get(0);
RexNode timezone = convertedOperands.get(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrap timezone into a canonicalize function call ($canonicalize_hive_timezone_id), so that we can in the future extend support to other Hive timezone identifiers which are not supported by Trino today.

This function would be identity for now.

@losipiuk losipiuk force-pushed the lo/trino-from-utc-timestamp branch from b7f16e4 to 02aa47a Compare July 12, 2021 12:38
@findepi
Copy link
Contributor

findepi commented Aug 4, 2021

@wmoustafa can you please take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants