use of io.trino.type.IntervalDayTimeType in project trino by trinodb.
the class SetTimeZoneTask method getTimeZoneId.
private String getTimeZoneId(Expression expression, SetTimeZone statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Map<NodeRef<Parameter>, Expression> parameterLookup = parameterExtractor(statement, parameters);
ExpressionAnalyzer analyzer = createConstantAnalyzer(plannerContext, accessControl, stateMachine.getSession(), parameterLookup, warningCollector);
Type type = analyzer.analyze(expression, Scope.create());
if (!(type instanceof VarcharType || type instanceof IntervalDayTimeType)) {
throw new TrinoException(TYPE_MISMATCH, format("Expected expression of varchar or interval day-time type, but '%s' has %s type", expression, type.getDisplayName()));
}
Object timeZoneValue = evaluateConstantExpression(expression, analyzer.getExpressionCoercions(), analyzer.getTypeOnlyCoercions(), plannerContext, stateMachine.getSession(), accessControl, ImmutableSet.of(), parameterLookup);
TimeZoneKey timeZoneKey;
if (timeZoneValue instanceof Slice) {
timeZoneKey = getTimeZoneKey(((Slice) timeZoneValue).toStringUtf8());
} else if (timeZoneValue instanceof Long) {
timeZoneKey = getTimeZoneKeyForOffset(getZoneOffsetMinutes((Long) timeZoneValue));
} else {
throw new IllegalStateException(format("Time Zone expression '%s' not supported", expression));
}
return timeZoneKey.getId();
}
Aggregations