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