Search in sources :

Example 1 with IntervalDayTimeType

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();
}
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

Slice (io.airlift.slice.Slice)1 TrinoException (io.trino.spi.TrinoException)1 TimeZoneKey (io.trino.spi.type.TimeZoneKey)1 TimeZoneKey.getTimeZoneKey (io.trino.spi.type.TimeZoneKey.getTimeZoneKey)1 Type (io.trino.spi.type.Type)1 VarcharType (io.trino.spi.type.VarcharType)1 ExpressionAnalyzer (io.trino.sql.analyzer.ExpressionAnalyzer)1 ExpressionInterpreter.evaluateConstantExpression (io.trino.sql.planner.ExpressionInterpreter.evaluateConstantExpression)1 Expression (io.trino.sql.tree.Expression)1 NodeRef (io.trino.sql.tree.NodeRef)1 IntervalDayTimeType (io.trino.type.IntervalDayTimeType)1