@Override public TimeZoneKey getTimeZoneKey() { return session.getTimeZoneKey(); }
private KafkaLoadingSession(Session session) { this.timeZoneKey = session.getTimeZoneKey(); }
private RedisLoadingSession(Session session) { this.timeZoneKey = session.getTimeZoneKey(); }
public static SqlTime sqlTimeOf(LocalTime time, Session session) { if (session.toConnectorSession().isLegacyTimestamp()) { long millisUtc = LocalDate.ofEpochDay(0) .atTime(time) .atZone(UTC) .withZoneSameLocal(ZoneId.of(session.getTimeZoneKey().getId())) .toInstant() .toEpochMilli(); return new SqlTime(millisUtc, session.getTimeZoneKey()); } return new SqlTime(NANOSECONDS.toMillis(time.toNanoOfDay())); }
@Override public String getTimeZoneId() { return session.getTimeZoneKey().getId(); }
session.getSchema().orElse(null), session.getPath().toString(), session.getTimeZoneKey().getId(), session.getLocale(), resourceEstimates.build(),
secondOfMinute, millisOfSecond, getDateTimeZone(session.getTimeZoneKey()), session.getTimeZoneKey(), session.toConnectorSession());
@Test public void testFunctionWithSessionCall() throws Exception { assertExecute("now()", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(TEST_SESSION.getStartTime(), TEST_SESSION.getTimeZoneKey())); assertExecute("current_timestamp", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(TEST_SESSION.getStartTime(), TEST_SESSION.getTimeZoneKey())); Futures.allAsList(futures).get(); }
public static RowExpression translate( Expression expression, FunctionKind functionKind, Map<NodeRef<Expression>, Type> types, FunctionRegistry functionRegistry, TypeManager typeManager, Session session, boolean optimize) { Visitor visitor = new Visitor( functionKind, types, typeManager, session.getTimeZoneKey(), isLegacyRowFieldOrdinalAccessEnabled(session), SystemSessionProperties.isLegacyTimestamp(session)); RowExpression result = visitor.process(expression, null); requireNonNull(result, "translated expression is null"); if (optimize) { ExpressionOptimizer optimizer = new ExpressionOptimizer(functionRegistry, typeManager, session); return optimizer.optimize(result); } return result; }
@Test public void testExtract() throws Exception { for (DateTime left : dateTimeValues) { for (Field field : Field.values()) { Long expected = null; Long millis = null; if (left != null) { millis = left.getMillis(); expected = callExtractFunction(TEST_SESSION.toConnectorSession(), millis, field); } DateTimeZone zone = getDateTimeZone(TEST_SESSION.getTimeZoneKey()); long zoneOffsetMinutes = millis != null ? MILLISECONDS.toMinutes(zone.getOffset(millis)) : 0; String expressionPattern = format( "extract(%s from from_unixtime(%%s / 1000.0E0, %s, %s))", field, zoneOffsetMinutes / 60, zoneOffsetMinutes % 60); assertExecute(generateExpression(expressionPattern, millis), BIGINT, expected); } } Futures.allAsList(futures).get(); }
private static void assertEqualSessionsWithoutTransactionId(Session actual, Session expected) { assertEquals(actual.getQueryId(), expected.getQueryId()); assertEquals(actual.getIdentity(), expected.getIdentity()); assertEquals(actual.getSource(), expected.getSource()); assertEquals(actual.getCatalog(), expected.getCatalog()); assertEquals(actual.getSchema(), expected.getSchema()); assertEquals(actual.getTimeZoneKey(), expected.getTimeZoneKey()); assertEquals(actual.getLocale(), expected.getLocale()); assertEquals(actual.getRemoteUserAddress(), expected.getRemoteUserAddress()); assertEquals(actual.getUserAgent(), expected.getUserAgent()); assertEquals(actual.getStartTime(), expected.getStartTime()); assertEquals(actual.getSystemProperties(), expected.getSystemProperties()); assertEquals(actual.getConnectorProperties(), expected.getConnectorProperties()); } }
assertEquals(session.getPath().getRawPath().get(), "testPath"); assertEquals(session.getLocale(), Locale.TAIWAN); assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei")); assertEquals(session.getRemoteUserAddress().get(), "testRemote"); assertEquals(session.getClientInfo().get(), "client-info");
.setSchema(schema.orElse(null)) .setPath(session.getPath()) .setTimeZoneKey(session.getTimeZoneKey()) .setLocale(session.getLocale()) .setRemoteUserAddress(session.getRemoteUserAddress().orElse(null))
getSession().getPath(), getSession().getTraceToken(), getSession().getTimeZoneKey(), getSession().getLocale(), getSession().getRemoteUserAddress(),
@Override protected Type visitTimestampLiteral(TimestampLiteral node, StackableAstVisitorContext<Context> context) { try { if (SystemSessionProperties.isLegacyTimestamp(session)) { parseTimestampLiteral(session.getTimeZoneKey(), node.getValue()); } else { parseTimestampLiteral(node.getValue()); } } catch (Exception e) { throw new SemanticException(INVALID_LITERAL, node, "'%s' is not a valid timestamp literal", node.getValue()); } Type type; if (timestampHasTimeZone(node.getValue())) { type = TIMESTAMP_WITH_TIME_ZONE; } else { type = TIMESTAMP; } return setExpressionType(node, type); }
defaultSession.getPath(), defaultSession.getTraceToken(), defaultSession.getTimeZoneKey(), defaultSession.getLocale(), defaultSession.getRemoteUserAddress(),
@Test public void testExtract() DateTime dateTime = new DateTime(2001, 8, 22, 3, 4, 5, 321, getDateTimeZone(TEST_SESSION.getTimeZoneKey())); double seconds = dateTime.getMillis() / 1000.0;
private SqlTimestamp sqlTimestamp(long millisUtc) { return new SqlTimestamp(millisUtc, TEST_SESSION.getTimeZoneKey()); } }
private SqlTime toTime(long milliseconds) { return new SqlTime(milliseconds, session.getTimeZoneKey()); }
@Test public void testCastToTime() throws Exception { assertFunction("cast(TIME '03:04:05.321 +07:09' as time)", TIME, new SqlTime(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), session.getTimeZoneKey())); }