protected TestDateTimeFunctionsBase(boolean legacyTimestamp) { super(testSessionBuilder() .setSystemProperty("legacy_timestamp", String.valueOf(legacyTimestamp)) .setTimeZoneKey(TIME_ZONE_KEY) .setStartTime(new DateTime(2017, 4, 1, 12, 34, 56, 789, UTC_TIME_ZONE).getMillis()) .build()); TIMESTAMP = legacyTimestamp ? LEGACY_TIMESTAMP : NEW_TIMESTAMP; }
@Test public void testLocalTime() { Session localSession = Session.builder(session) .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("LOCALTIME", TimeType.TIME, "14:30:00.000"); } }
@Test public void testLocalTimestamp() { Session localSession = Session.builder(session) .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("LOCALTIMESTAMP", TimestampType.TIMESTAMP, "2017-03-01 14:30:00.000"); } }
.setRemoteUserAddress(session.getRemoteUserAddress().orElse(null)) .setUserAgent(session.getUserAgent().orElse(null)) .setStartTime(session.getStartTime()) .build();
private InternalTable getInternalTable(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, ConnectorSplit connectorSplit, List<ColumnHandle> columns) { InformationSchemaTransactionHandle transaction = checkType(transactionHandle, InformationSchemaTransactionHandle.class, "transaction"); InformationSchemaSplit split = checkType(connectorSplit, InformationSchemaSplit.class, "split"); requireNonNull(columns, "columns is null"); InformationSchemaTableHandle handle = split.getTableHandle(); Map<String, NullableValue> filters = split.getFilters(); Session session = Session.builder(metadata.getSessionPropertyManager()) .setTransactionId(transaction.getTransactionId()) .setQueryId(new QueryId(connectorSession.getQueryId())) .setIdentity(connectorSession.getIdentity()) .setSource("information_schema") .setCatalog("") // default catalog is not be used .setSchema("") // default schema is not be used .setTimeZoneKey(connectorSession.getTimeZoneKey()) .setLocale(connectorSession.getLocale()) .setStartTime(connectorSession.getStartTime()) .build(); return getInformationSchemaTable(session, handle.getCatalogName(), handle.getSchemaTableName(), filters); }
public static Session toSession(TransactionId transactionId, ConnectorSession session) { return Session.builder(new SessionPropertyManager(SYSTEM_SESSION_PROPERTIES)) .setQueryId(new QueryId(session.getQueryId())) .setTransactionId(transactionId) .setCatalog("catalog") .setSchema("schema") .setIdentity(session.getIdentity()) .setTimeZoneKey(session.getTimeZoneKey()) .setLocale(session.getLocale()) .setStartTime(session.getStartTime()) .build(); }
Session.builder(this.session) .setTimeZoneKey(TIME_ZONE_KEY) .setStartTime(new DateTime(1980, 1, 1, 10, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); Session.builder(this.session) .setTimeZoneKey(europeWarsawTimeZoneKey) .setStartTime(new DateTime(2017, 1, 1, 10, 0, 0, europeWarsawTimeZone).getMillis()) .build(); try (FunctionAssertions europeWarsawAssertionsWinter = new FunctionAssertions(europeWarsawSessionWinter);
.setUserAgent(session.getUserAgent().orElse(null)) .setClientInfo(session.getClientInfo().orElse(null)) .setStartTime(session.getStartTime()) .build();
public static Session toSession(ConnectorTransactionHandle transactionHandle, ConnectorSession session) { TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId(); return Session.builder(new SessionPropertyManager(SYSTEM_SESSION_PROPERTIES)) .setQueryId(new QueryId(session.getQueryId())) .setTransactionId(transactionId) .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) .setIdentity(session.getIdentity()) .setTimeZoneKey(session.getTimeZoneKey()) .setLocale(session.getLocale()) .setStartTime(session.getStartTime()) .build(); } }
@Test public void testCurrentTime() { Session localSession = Session.builder(session) // we use Asia/Kathmandu here to test the difference in semantic change of current_time // between legacy and non-legacy timestamp .setTimeZoneKey(KATHMANDU_ZONE_KEY) .setStartTime(new DateTime(2017, 3, 1, 15, 45, 0, 0, KATHMANDU_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("CURRENT_TIME", TIME_WITH_TIME_ZONE, "15:30:00.000 Asia/Kathmandu"); } }
@Test public void testCastToTimeWithTimeZoneDSTIsNotAppliedWhenTimeCrossesDST() { // Australia/Sydney will switch DST a second after session start // For simplicity we have to use time zone that is going forward when entering DST zone with 1970-01-01 Session session = Session.builder(this.session) .setTimeZoneKey(getTimeZoneKey("Australia/Sydney")) .setStartTime(new DateTime(2017, 10, 1, 1, 59, 59, 999, getDateTimeZone(getTimeZoneKey("Australia/Sydney"))).getMillis()) .build(); try (FunctionAssertions localAssertions = new FunctionAssertions(session)) { localAssertions.assertFunctionString("cast(TIME '12:00:00.000' as time with time zone)", TIME_WITH_TIME_ZONE, "12:00:00.000 Australia/Sydney"); } }
@Test public void testCurrentTime() { Session localSession = Session.builder(session) // we use Asia/Kathmandu here to test the difference in semantic change of current_time // between legacy and non-legacy timestamp .setTimeZoneKey(KATHMANDU_ZONE_KEY) .setStartTime(new DateTime(2017, 3, 1, 15, 45, 0, 0, KATHMANDU_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("CURRENT_TIME", TIME_WITH_TIME_ZONE, "15:45:00.000 Asia/Kathmandu"); } }
@Test public void testCurrentTimestamp() { Session localSession = Session.builder(session) .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); } } }
@Test public void testLocalTime() { Session localSession = Session.builder(session) .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("LOCALTIME", TimeType.TIME, "13:30:00.000"); } }
@Test public void testCurrentTimestamp() { Session localSession = Session.builder(session) .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("CURRENT_TIMESTAMP", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); localAssertion.assertFunctionString("NOW()", TIMESTAMP_WITH_TIME_ZONE, "2017-03-01 14:30:00.000 " + DATE_TIME_ZONE.getID()); } } }
private void testTimeRepresentationOnDate(DateTime date, String timeLiteral, Type expectedType, Object expected) { Session localSession = testSessionBuilder() .setTimeZoneKey(getTimeZoneKey("America/Los_Angeles")) .setStartTime(date.getMillis()) .setSystemProperty("legacy_timestamp", "true") .build(); try (FunctionAssertions localAssertions = new FunctionAssertions(localSession)) { localAssertions.assertFunction(timeLiteral, expectedType, expected); localAssertions.assertFunctionString(timeLiteral, expectedType, valueFromLiteral(timeLiteral)); } }
@Test public void testLocalTimestamp() { Session localSession = Session.builder(session) .setStartTime(new DateTime(2017, 3, 1, 14, 30, 0, 0, DATE_TIME_ZONE).getMillis()) .build(); try (FunctionAssertions localAssertion = new FunctionAssertions(localSession)) { localAssertion.assertFunctionString("LOCALTIMESTAMP", TimestampType.TIMESTAMP, "2017-03-01 14:30:00.000"); } }
private void testTimeRepresentationOnDate(DateTime date, String timeLiteral, Type expectedType, Object expected) { Session localSession = testSessionBuilder() .setTimeZoneKey(getTimeZoneKey("America/Los_Angeles")) .setStartTime(date.getMillis()) .setSystemProperty("legacy_timestamp", "false") .build(); try (FunctionAssertions localAssertions = new FunctionAssertions(localSession)) { localAssertions.assertFunction(timeLiteral, expectedType, expected); localAssertions.assertFunctionString(timeLiteral, expectedType, valueFromLiteral(timeLiteral)); } }