Search in sources :

Example 1 with IntervalLiteral

use of io.trino.sql.tree.IntervalLiteral 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");
}
Also used : IntervalLiteral(io.trino.sql.tree.IntervalLiteral) NodeLocation(io.trino.sql.tree.NodeLocation) SetTimeZone(io.trino.sql.tree.SetTimeZone) TrinoException(io.trino.spi.TrinoException) Test(org.testng.annotations.Test)

Example 2 with IntervalLiteral

use of io.trino.sql.tree.IntervalLiteral 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)))));
}
Also used : IntervalLiteral(io.trino.sql.tree.IntervalLiteral) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) SetTimeZone(io.trino.sql.tree.SetTimeZone) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.junit.jupiter.api.Test)

Example 3 with IntervalLiteral

use of io.trino.sql.tree.IntervalLiteral in project trino by trinodb.

the class TestSetTimeZoneTask method testSetTimeZoneIntervalLiteralGreaterThanOffsetTimeZoneMax.

@Test
public void testSetTimeZoneIntervalLiteralGreaterThanOffsetTimeZoneMax() {
    QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE INTERVAL '15' HOUR");
    SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new IntervalLiteral("15", POSITIVE, HOUR)));
    assertThatThrownBy(() -> executeSetTimeZone(setTimeZone, stateMachine)).isInstanceOf(TrinoException.class).hasMessage("Invalid offset minutes 900");
}
Also used : IntervalLiteral(io.trino.sql.tree.IntervalLiteral) NodeLocation(io.trino.sql.tree.NodeLocation) SetTimeZone(io.trino.sql.tree.SetTimeZone) TrinoException(io.trino.spi.TrinoException) Test(org.testng.annotations.Test)

Example 4 with IntervalLiteral

use of io.trino.sql.tree.IntervalLiteral in project trino by trinodb.

the class TestSetTimeZoneTask method testSetTimeZoneIntervalLiteral.

@Test
public void testSetTimeZoneIntervalLiteral() {
    QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE INTERVAL '10' HOUR");
    SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new IntervalLiteral("10", POSITIVE, HOUR)));
    executeSetTimeZone(setTimeZone, stateMachine);
    Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
    assertThat(setSessionProperties).hasSize(1);
    assertEquals(setSessionProperties.get(TIME_ZONE_ID), "+10:00");
}
Also used : IntervalLiteral(io.trino.sql.tree.IntervalLiteral) NodeLocation(io.trino.sql.tree.NodeLocation) SetTimeZone(io.trino.sql.tree.SetTimeZone) Test(org.testng.annotations.Test)

Example 5 with IntervalLiteral

use of io.trino.sql.tree.IntervalLiteral in project trino by trinodb.

the class TestSetTimeZoneTask method testSetTimeIntervalLiteralZoneHourToMinute.

@Test
public void testSetTimeIntervalLiteralZoneHourToMinute() {
    QueryStateMachine stateMachine = createQueryStateMachine("SET TIME ZONE INTERVAL -'08:00' HOUR TO MINUTE");
    SetTimeZone setTimeZone = new SetTimeZone(new NodeLocation(1, 1), Optional.of(new IntervalLiteral("8", NEGATIVE, HOUR, Optional.of(MINUTE))));
    executeSetTimeZone(setTimeZone, stateMachine);
    Map<String, String> setSessionProperties = stateMachine.getSetSessionProperties();
    assertThat(setSessionProperties).hasSize(1);
    assertEquals(setSessionProperties.get(TIME_ZONE_ID), "-08:00");
}
Also used : IntervalLiteral(io.trino.sql.tree.IntervalLiteral) NodeLocation(io.trino.sql.tree.NodeLocation) SetTimeZone(io.trino.sql.tree.SetTimeZone) Test(org.testng.annotations.Test)

Aggregations

IntervalLiteral (io.trino.sql.tree.IntervalLiteral)7 SetTimeZone (io.trino.sql.tree.SetTimeZone)5 NodeLocation (io.trino.sql.tree.NodeLocation)4 Test (org.testng.annotations.Test)4 Test (org.junit.jupiter.api.Test)3 TrinoException (io.trino.spi.TrinoException)2 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)1 CharLiteral (io.trino.sql.tree.CharLiteral)1 FunctionCall (io.trino.sql.tree.FunctionCall)1 Identifier (io.trino.sql.tree.Identifier)1 StringLiteral (io.trino.sql.tree.StringLiteral)1 TimeLiteral (io.trino.sql.tree.TimeLiteral)1 TimestampLiteral (io.trino.sql.tree.TimestampLiteral)1