use of io.trino.spi.type.TimeZoneKey in project trino by trinodb.
the class TestDateTimeFunctions method testCurrentDateTimezone.
@Test
public void testCurrentDateTimezone() {
TimeZoneKey kievTimeZoneKey = getTimeZoneKey("Europe/Kiev");
// The zone has 'gap' on 1970-01-01
TimeZoneKey bahiaBanderasTimeZoneKey = getTimeZoneKey("America/Bahia_Banderas");
TimeZoneKey montrealTimeZoneKey = getTimeZoneKey("America/Montreal");
long timeIncrement = TimeUnit.MINUTES.toMillis(53);
// We expect UTC millis later on so we have to use UTC chronology
for (long millis = ISOChronology.getInstanceUTC().getDateTimeMillis(2000, 6, 15, 0, 0, 0, 0); millis < ISOChronology.getInstanceUTC().getDateTimeMillis(2016, 6, 15, 0, 0, 0, 0); millis += timeIncrement) {
Instant instant = Instant.ofEpochMilli(millis);
assertCurrentDateAtInstant(kievTimeZoneKey, instant);
assertCurrentDateAtInstant(bahiaBanderasTimeZoneKey, instant);
assertCurrentDateAtInstant(montrealTimeZoneKey, instant);
assertCurrentDateAtInstant(TIME_ZONE_KEY, instant);
}
}
use of io.trino.spi.type.TimeZoneKey in project trino by trinodb.
the class SnapshotsTable method buildPages.
private static List<Page> buildPages(ConnectorTableMetadata tableMetadata, ConnectorSession session, Table icebergTable) {
PageListBuilder pagesBuilder = PageListBuilder.forTable(tableMetadata);
TimeZoneKey timeZoneKey = session.getTimeZoneKey();
icebergTable.snapshots().forEach(snapshot -> {
pagesBuilder.beginRow();
pagesBuilder.appendTimestampTzMillis(snapshot.timestampMillis(), timeZoneKey);
pagesBuilder.appendBigint(snapshot.snapshotId());
if (checkNonNull(snapshot.parentId(), pagesBuilder)) {
pagesBuilder.appendBigint(snapshot.parentId());
}
if (checkNonNull(snapshot.operation(), pagesBuilder)) {
pagesBuilder.appendVarchar(snapshot.operation());
}
if (checkNonNull(snapshot.manifestListLocation(), pagesBuilder)) {
pagesBuilder.appendVarchar(snapshot.manifestListLocation());
}
if (checkNonNull(snapshot.summary(), pagesBuilder)) {
pagesBuilder.appendVarcharVarcharMap(snapshot.summary());
}
pagesBuilder.endRow();
});
return pagesBuilder.build();
}
use of io.trino.spi.type.TimeZoneKey in project trino by trinodb.
the class DateTimeFunctions method fromIso8601TimestampNanos.
@ScalarFunction("from_iso8601_timestamp_nanos")
@LiteralParameters("x")
@SqlType("timestamp(9) with time zone")
public static LongTimestampWithTimeZone fromIso8601TimestampNanos(ConnectorSession session, @SqlType("varchar(x)") Slice iso8601DateTime) {
java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ISO_DATE_TIME;
String datetimeString = iso8601DateTime.toStringUtf8();
TemporalAccessor parsedDatetime;
try {
parsedDatetime = formatter.parseBest(datetimeString, ZonedDateTime::from, LocalDateTime::from);
} catch (DateTimeParseException e) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, e);
}
ZonedDateTime zonedDatetime;
if (parsedDatetime instanceof ZonedDateTime) {
zonedDatetime = (ZonedDateTime) parsedDatetime;
} else {
zonedDatetime = ((LocalDateTime) parsedDatetime).atZone(session.getTimeZoneKey().getZoneId());
}
long picosOfSecond = zonedDatetime.getNano() * ((long) PICOSECONDS_PER_NANOSECOND);
TimeZoneKey zone = TimeZoneKey.getTimeZoneKey(zonedDatetime.getZone().getId());
return LongTimestampWithTimeZone.fromEpochSecondsAndFraction(zonedDatetime.toEpochSecond(), picosOfSecond, zone);
}
use of io.trino.spi.type.TimeZoneKey in project trino by trinodb.
the class HistoryTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
InMemoryRecordSet.Builder table = InMemoryRecordSet.builder(COLUMNS);
Set<Long> ancestorIds = ImmutableSet.copyOf(SnapshotUtil.currentAncestorIds(icebergTable));
TimeZoneKey timeZoneKey = session.getTimeZoneKey();
for (HistoryEntry historyEntry : icebergTable.history()) {
long snapshotId = historyEntry.snapshotId();
Snapshot snapshot = icebergTable.snapshot(snapshotId);
table.addRow(packDateTimeWithZone(historyEntry.timestampMillis(), timeZoneKey), snapshotId, snapshot != null ? snapshot.parentId() : null, ancestorIds.contains(snapshotId));
}
return table.build().cursor();
}
use of io.trino.spi.type.TimeZoneKey in project trino by trinodb.
the class TestTrinoDriver method testSetTimeZoneId.
@Test
public void testSetTimeZoneId() throws Exception {
TimeZoneKey defaultZoneKey = TimeZoneKey.getTimeZoneKey(TimeZone.getDefault().getID());
DateTimeZone defaultZone = DateTimeZone.forTimeZone(TimeZone.getDefault());
String sql = "SELECT current_timezone() zone, TIMESTAMP '2001-02-03 3:04:05' ts";
try (Connection connection = createConnection()) {
try (Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql)) {
assertTrue(rs.next());
assertEquals(rs.getString("zone"), defaultZoneKey.getId());
assertEquals(rs.getTimestamp("ts"), new Timestamp(new DateTime(2001, 2, 3, 3, 4, 5, defaultZone).getMillis()));
}
connection.unwrap(TrinoConnection.class).setTimeZoneId("UTC");
try (Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql)) {
assertTrue(rs.next());
assertEquals(rs.getString("zone"), "UTC");
// setting the session timezone has no effect on the interpretation of timestamps in the JDBC driver
assertEquals(rs.getTimestamp("ts"), new Timestamp(new DateTime(2001, 2, 3, 3, 4, 5, defaultZone).getMillis()));
}
}
}
Aggregations