use of io.trino.sql.tree.SetTimeZone in project trino by trinodb.
the class TestSetTimeZoneTask method testSetTimeZoneIntervalDayTimeTypeInvalidFunctionCall.
@Test
public void testSetTimeZoneIntervalDayTimeTypeInvalidFunctionCall() {
QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE parse_duration('3601s')");
SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 24), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 24), "parse_duration", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 39), "3601s")))));
assertThatThrownBy(() -> executeSetTimeZone(setTimeZone, stateMachine)).isInstanceOf(TrinoException.class).hasMessage("Invalid time zone offset interval: interval contains seconds");
}
use of io.trino.sql.tree.SetTimeZone in project trino by trinodb.
the class TestSetTimeZoneTask method testSetTimeZoneVarcharFunctionCall.
@Test
public void testSetTimeZoneVarcharFunctionCall() {
QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE concat_ws('/', 'America', 'Los_Angeles')");
SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 15), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 15), "concat_ws", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 25), "/"), new StringLiteral(new NodeLocation(1, 30), "America"), new StringLiteral(new NodeLocation(1, 41), "Los_Angeles")))));
executeSetTimeZone(setTimeZone, stateMachine);
Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
assertThat(setSessionProperties).hasSize(1);
assertEquals(setSessionProperties.get(TIME_ZONE_ID), "America/Los_Angeles");
}
use of io.trino.sql.tree.SetTimeZone in project trino by trinodb.
the class TestSetTimeZoneTask method testSetTimeZoneIntervalDayTimeTypeFunctionCall.
@Test
public void testSetTimeZoneIntervalDayTimeTypeFunctionCall() {
QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE parse_duration('8h')");
SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new FunctionCall(new NodeLocation(1, 24), QualifiedName.of(ImmutableList.of(new Identifier(new NodeLocation(1, 24), "parse_duration", false))), ImmutableList.of(new StringLiteral(new NodeLocation(1, 39), "8h")))));
executeSetTimeZone(setTimeZone, stateMachine);
Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
assertThat(setSessionProperties).hasSize(1);
assertEquals(setSessionProperties.get(TIME_ZONE_ID), "+08:00");
}
use of io.trino.sql.tree.SetTimeZone in project trino by trinodb.
the class TestSetTimeZoneTask method testSetTimeZoneIntervalLiteralLessThanOffsetTimeZoneMin.
@Test
public void testSetTimeZoneIntervalLiteralLessThanOffsetTimeZoneMin() {
QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE INTERVAL -'15' HOUR");
SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new IntervalLiteral("15", NEGATIVE, HOUR)));
assertThatThrownBy(() -> executeSetTimeZone(setTimeZone, stateMachine)).isInstanceOf(TrinoException.class).hasMessage("Invalid offset minutes -900");
}
use of io.trino.sql.tree.SetTimeZone in project trino by trinodb.
the class TestSqlParser method testSetTimeZone.
@Test
public void testSetTimeZone() {
assertThat(statement("SET TIME ZONE LOCAL")).isEqualTo(new SetTimeZone(location(1, 1), Optional.empty()));
assertThat(statement("SET TIME ZONE 'America/Los_Angeles'")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new StringLiteral(location(1, 15), "America/Los_Angeles"))));
assertThat(statement("SET TIME ZONE concat_ws('/', 'America', 'Los_Angeles')")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new FunctionCall(location(1, 15), QualifiedName.of(ImmutableList.of(new Identifier(location(1, 15), "concat_ws", false))), ImmutableList.of(new StringLiteral(location(1, 25), "/"), new StringLiteral(location(1, 30), "America"), new StringLiteral(location(1, 41), "Los_Angeles"))))));
assertThat(statement("SET TIME ZONE '-08:00'")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new StringLiteral(location(1, 15), "-08:00"))));
assertThat(statement("SET TIME ZONE INTERVAL '10' HOUR")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new IntervalLiteral(location(1, 15), "10", Sign.POSITIVE, IntervalField.HOUR, Optional.empty()))));
assertThat(statement("SET TIME ZONE INTERVAL -'08:00' HOUR TO MINUTE")).isEqualTo(new SetTimeZone(location(1, 1), Optional.of(new IntervalLiteral(location(1, 15), "08:00", Sign.NEGATIVE, IntervalField.HOUR, Optional.of(IntervalField.MINUTE)))));
}
Aggregations