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 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"); } }
public static LocalQueryRunner createQueryRunner(Map<String, String> catalogProperties, Class<? extends AtopFactory> factoryClass) { Session session = testSessionBuilder() .setCatalog("atop") .setSchema("default") .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(TimeZone.getDefault().getID())) .build(); LocalQueryRunner queryRunner = new LocalQueryRunner(session); try { AtopConnectorFactory connectorFactory = new AtopConnectorFactory(factoryClass, LocalAtopQueryRunner.class.getClassLoader()); ImmutableMap.Builder<String, String> properties = ImmutableMap.<String, String>builder() .putAll(catalogProperties) .put("atop.max-history-days", "1"); queryRunner.createCatalog("atop", connectorFactory, properties.build()); return queryRunner; } catch (Exception e) { closeAllSuppress(e, queryRunner); throw e; } } }
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 testCastToTimeWithTimeZoneWithTZWithRulesChanged() { TimeZoneKey timeZoneThatChangedSince1970 = getTimeZoneKey("Asia/Kathmandu"); DateTimeZone dateTimeZoneThatChangedSince1970 = getDateTimeZone(timeZoneThatChangedSince1970); Session session = Session.builder(this.session) .setTimeZoneKey(timeZoneThatChangedSince1970) .build(); try (FunctionAssertions localAssertions = new FunctionAssertions(session)) { localAssertions.assertFunction( "cast(TIME '03:04:05.321' as time with time zone)", TIME_WITH_TIME_ZONE, new SqlTimeWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, dateTimeZoneThatChangedSince1970).getMillis(), dateTimeZoneThatChangedSince1970.toTimeZone())); } }
public static SessionBuilder testSessionBuilder(SessionPropertyManager sessionPropertyManager) { return Session.builder(sessionPropertyManager) .setQueryId(queryIdGenerator.createNextQueryId()) .setIdentity(new Identity("user", Optional.empty())) .setSource("test") .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) .setTimeZoneKey(DEFAULT_TIME_ZONE_KEY) .setLocale(ENGLISH) .setRemoteUserAddress("address") .setUserAgent("agent"); }
public TestLambdaExpression() { this(testSessionBuilder().setTimeZoneKey(getTimeZoneKey("Pacific/Kiritimati")).build()); }
public TestArrayTransformFunction() { super(testSessionBuilder().setTimeZoneKey(getTimeZoneKey("Pacific/Kiritimati")).build()); }
@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"); } }
public TestArrayReduceFunction() { super(testSessionBuilder().setTimeZoneKey(getTimeZoneKey("Pacific/Kiritimati")).build()); }
protected TestDateBase(boolean legacyTimestamp) { super(testSessionBuilder() .setSystemProperty("legacy_timestamp", String.valueOf(legacyTimestamp)) .setTimeZoneKey(TIME_ZONE_KEY) .build()); }
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)); } }
protected TestTimestampBase(boolean legacyTimestamp) { super(testSessionBuilder() .setSystemProperty("legacy_timestamp", String.valueOf(legacyTimestamp)) .setTimeZoneKey(TIME_ZONE_KEY) .build()); }
protected TestDateTimeOperatorsBase(boolean legacyTimestamp) { super(testSessionBuilder() .setSystemProperty("legacy_timestamp", String.valueOf(legacyTimestamp)) .setTimeZoneKey(TIME_ZONE_KEY) .build()); }
protected TestTimeWithTimeZoneBase(boolean legacyTimestamp) { super(testSessionBuilder() .setSystemProperty("legacy_timestamp", String.valueOf(legacyTimestamp)) .setTimeZoneKey(getTimeZoneKey("+06:09")) .build()); }
public TestTimeBase(boolean legacyTimestamp) { super(testSessionBuilder() .setSystemProperty("legacy_timestamp", String.valueOf(legacyTimestamp)) .setTimeZoneKey(TIME_ZONE_KEY) .build()); }
public static Session createSession(String schema) { return testSessionBuilder() .setCatalog("kudu") .setSchema(schema) .setTimeZoneKey(UTC_KEY) .setLocale(ENGLISH) .build(); } }
protected TestTimestampWithTimeZoneBase(boolean legacyTimestamp) { super(testSessionBuilder() .setSystemProperty("legacy_timestamp", String.valueOf(legacyTimestamp)) .setTimeZoneKey(TIME_ZONE_KEY) .build()); }
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)); } }