Search in sources :

Example 16 with TimeZoneKey

use of io.trino.spi.type.TimeZoneKey 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();
}
Also used : VarcharType(io.trino.spi.type.VarcharType) ExpressionAnalyzer(io.trino.sql.analyzer.ExpressionAnalyzer) NodeRef(io.trino.sql.tree.NodeRef) Type(io.trino.spi.type.Type) VarcharType(io.trino.spi.type.VarcharType) IntervalDayTimeType(io.trino.type.IntervalDayTimeType) ExpressionInterpreter.evaluateConstantExpression(io.trino.sql.planner.ExpressionInterpreter.evaluateConstantExpression) Expression(io.trino.sql.tree.Expression) Slice(io.airlift.slice.Slice) IntervalDayTimeType(io.trino.type.IntervalDayTimeType) TrinoException(io.trino.spi.TrinoException) TimeZoneKey(io.trino.spi.type.TimeZoneKey) TimeZoneKey.getTimeZoneKey(io.trino.spi.type.TimeZoneKey.getTimeZoneKey)

Aggregations

TimeZoneKey (io.trino.spi.type.TimeZoneKey)16 TimeZoneKey.getTimeZoneKey (io.trino.spi.type.TimeZoneKey.getTimeZoneKey)11 LiteralParameters (io.trino.spi.function.LiteralParameters)9 SqlType (io.trino.spi.function.SqlType)9 TrinoException (io.trino.spi.TrinoException)6 TimeZoneNotSupportedException (io.trino.spi.type.TimeZoneNotSupportedException)4 LongTimeWithTimeZone (io.trino.spi.type.LongTimeWithTimeZone)3 DateTimeZone (org.joda.time.DateTimeZone)3 Type (io.trino.spi.type.Type)2 VarcharType (io.trino.spi.type.VarcharType)2 DateTimeZoneIndex.getDateTimeZone (io.trino.util.DateTimeZoneIndex.getDateTimeZone)2 ZonedDateTime (java.time.ZonedDateTime)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Slice (io.airlift.slice.Slice)1 PageListBuilder (io.trino.plugin.iceberg.util.PageListBuilder)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 InMemoryRecordSet (io.trino.spi.connector.InMemoryRecordSet)1 ScalarFunction (io.trino.spi.function.ScalarFunction)1