Search in sources :

Example 1 with SetTimeZone

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

Example 2 with SetTimeZone

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");
}
Also used : Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) StringLiteral(io.trino.sql.tree.StringLiteral) SetTimeZone(io.trino.sql.tree.SetTimeZone) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 3 with SetTimeZone

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");
}
Also used : Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) StringLiteral(io.trino.sql.tree.StringLiteral) SetTimeZone(io.trino.sql.tree.SetTimeZone) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 4 with SetTimeZone

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");
}
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 5 with SetTimeZone

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

Aggregations

SetTimeZone (io.trino.sql.tree.SetTimeZone)12 NodeLocation (io.trino.sql.tree.NodeLocation)11 Test (org.testng.annotations.Test)11 StringLiteral (io.trino.sql.tree.StringLiteral)6 FunctionCall (io.trino.sql.tree.FunctionCall)5 Identifier (io.trino.sql.tree.Identifier)5 IntervalLiteral (io.trino.sql.tree.IntervalLiteral)5 TrinoException (io.trino.spi.TrinoException)4 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)1 Test (org.junit.jupiter.api.Test)1