Search in sources :

Example 1 with NodeLocation

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

the class ParameterUtils method parameterExtractor.

public static Map<NodeRef<Parameter>, Expression> parameterExtractor(Statement statement, List<Expression> parameters) {
    List<Parameter> parametersList = getParameters(statement).stream().sorted(Comparator.comparing(parameter -> parameter.getLocation().get(), Comparator.comparing(NodeLocation::getLineNumber).thenComparing(NodeLocation::getColumnNumber))).collect(toImmutableList());
    ImmutableMap.Builder<NodeRef<Parameter>, Expression> builder = ImmutableMap.builder();
    Iterator<Expression> iterator = parameters.iterator();
    for (Parameter parameter : parametersList) {
        builder.put(NodeRef.of(parameter), iterator.next());
    }
    return builder.buildOrThrow();
}
Also used : NodeRef(io.trino.sql.tree.NodeRef) NodeLocation(io.trino.sql.tree.NodeLocation) Expression(io.trino.sql.tree.Expression) Parameter(io.trino.sql.tree.Parameter) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with NodeLocation

use of io.trino.sql.tree.NodeLocation 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 3 with NodeLocation

use of io.trino.sql.tree.NodeLocation 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 4 with NodeLocation

use of io.trino.sql.tree.NodeLocation 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 5 with NodeLocation

use of io.trino.sql.tree.NodeLocation 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)

Aggregations

NodeLocation (io.trino.sql.tree.NodeLocation)19 Test (org.testng.annotations.Test)14 SetTimeZone (io.trino.sql.tree.SetTimeZone)11 StringLiteral (io.trino.sql.tree.StringLiteral)7 Identifier (io.trino.sql.tree.Identifier)6 TrinoException (io.trino.spi.TrinoException)4 FunctionCall (io.trino.sql.tree.FunctionCall)4 IntervalLiteral (io.trino.sql.tree.IntervalLiteral)4 Parameter (io.trino.sql.tree.Parameter)4 ParsingOptions (io.trino.sql.parser.ParsingOptions)3 Expression (io.trino.sql.tree.Expression)3 Statement (io.trino.sql.tree.Statement)3 Test (org.junit.jupiter.api.Test)3 QueryUtil.simpleQuery (io.trino.sql.QueryUtil.simpleQuery)2 AllColumns (io.trino.sql.tree.AllColumns)2 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)2 CoalesceExpression (io.trino.sql.tree.CoalesceExpression)2 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)2 CreateTable (io.trino.sql.tree.CreateTable)2 DereferenceExpression (io.trino.sql.tree.DereferenceExpression)2