Skip to content

Commit

Permalink
Remove unnecessary condition else check
Browse files Browse the repository at this point in the history
  • Loading branch information
Akanksha-kedia authored and tdcmeehan committed Dec 1, 2023
1 parent 381d51c commit a3946f5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,14 @@ public static long castToTimeWithTimeZone(SqlFunctionProperties properties, @Sql
if (properties.isLegacyTimestamp()) {
return packDateTimeWithZone(value, properties.getTimeZoneKey());
}
else {
ISOChronology localChronology = getChronology(properties.getTimeZoneKey());

// This cast does treat TIME as wall time in session TZ. This means that in order to get
// its UTC representation we need to shift the value by the offset of TZ.
// We use value offset in this place to be sure that we will have same hour represented
// in TIME WITH TIME ZONE. Calculating real TZ offset will happen when really required.
// This is done due to inadequate TIME WITH TIME ZONE representation.
return packDateTimeWithZone(localChronology.getZone().convertLocalToUTC(value, false), properties.getTimeZoneKey());
}
ISOChronology localChronology = getChronology(properties.getTimeZoneKey());
// This cast does treat TIME as wall time in session TZ. This means that in order to get
// its UTC representation we need to shift the value by the offset of TZ.
// We use value offset in this place to be sure that we will have same hour represented
// in TIME WITH TIME ZONE. Calculating real TZ offset will happen when really required.
// This is done due to inadequate TIME WITH TIME ZONE representation.

return packDateTimeWithZone(localChronology.getZone().convertLocalToUTC(value, false), properties.getTimeZoneKey());
}

@ScalarOperator(CAST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,13 @@ public static long castToTimestamp(SqlFunctionProperties properties, @SqlType(St
if (properties.isLegacyTimestamp()) {
return unpackMillisUtc(value);
}
else {
// This is hack that we need to use as the timezone interpretation depends on date (not only on time)
// TODO remove REFERENCE_TIMESTAMP_UTC when removing support for political time zones in TIME WIT TIME ZONE
long currentMillisOfDay = ChronoField.MILLI_OF_DAY.getFrom(Instant.ofEpochMilli(REFERENCE_TIMESTAMP_UTC).atZone(ZoneOffset.UTC));
long timeMillisUtcInCurrentDay = REFERENCE_TIMESTAMP_UTC - currentMillisOfDay + unpackMillisUtc(value);

ISOChronology chronology = getChronology(unpackZoneKey(value));
return unpackMillisUtc(value) + chronology.getZone().getOffset(timeMillisUtcInCurrentDay);
}
// This is hack that we need to use as the timezone interpretation depends on date (not only on time)
// TODO remove REFERENCE_TIMESTAMP_UTC when removing support for political time zones in TIME WIT TIME ZONE
long currentMillisOfDay = ChronoField.MILLI_OF_DAY.getFrom(Instant.ofEpochMilli(REFERENCE_TIMESTAMP_UTC).atZone(ZoneOffset.UTC));
long timeMillisUtcInCurrentDay = REFERENCE_TIMESTAMP_UTC - currentMillisOfDay + unpackMillisUtc(value);

ISOChronology chronology = getChronology(unpackZoneKey(value));
return unpackMillisUtc(value) + chronology.getZone().getOffset(timeMillisUtcInCurrentDay);
}

@ScalarOperator(CAST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ public static long castToDate(SqlFunctionProperties properties, @SqlType(Standar
long millis = date + chronology.getZone().getOffset(date);
return TimeUnit.MILLISECONDS.toDays(millis);
}
else {
return TimeUnit.MILLISECONDS.toDays(value);
}
return TimeUnit.MILLISECONDS.toDays(value);
}

@ScalarOperator(CAST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ public static long castToDate(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) l
@SqlType(StandardTypes.TIME)
public static long castToTime(SqlFunctionProperties properties, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long value)
{
if (properties.isLegacyTimestamp()) {
return modulo24Hour(unpackChronology(value), unpackMillisUtc(value));
}
else {
return modulo24Hour(castToTimestamp(properties, value));
}
return properties.isLegacyTimestamp() ? modulo24Hour(unpackChronology(value), unpackMillisUtc(value)) : modulo24Hour(castToTimestamp(properties, value));
}

@ScalarOperator(CAST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,8 @@ private boolean canSetSessionProperty(ConnectorIdentity identity, String propert
{
for (SessionPropertyAccessControlRule rule : sessionPropertyRules) {
Optional<Boolean> allowed = rule.match(identity.getUser(), property);
if (allowed.isPresent() && allowed.get()) {
return true;
}
if (allowed.isPresent() && !allowed.get()) {
return false;
if (allowed.isPresent()) {
return allowed.get();
}
}
return false;
Expand Down

0 comments on commit a3946f5

Please sign in to comment.