use of io.trino.sql.tree.FunctionCall 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.FunctionCall 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.FunctionCall in project trino by trinodb.
the class TestSetSessionTask method testSetSessionWithParameters.
@Test
public void testSetSessionWithParameters() {
FunctionCall functionCall = new TestingFunctionResolution(transactionManager, plannerContext).functionCallBuilder(QualifiedName.of("concat")).addArgument(VARCHAR, new StringLiteral("ban")).addArgument(VARCHAR, new Parameter(0)).build();
testSetSessionWithParameters("bar", functionCall, "banana", ImmutableList.of(new StringLiteral("ana")));
}
use of io.trino.sql.tree.FunctionCall in project trino by trinodb.
the class TestLogicalPlanner method testAllFieldsDereferenceFromNonDeterministic.
@Test
public void testAllFieldsDereferenceFromNonDeterministic() {
FunctionCall randomFunction = new FunctionCall(getQueryRunner().getMetadata().resolveFunction(TEST_SESSION, QualifiedName.of("rand"), ImmutableList.of()).toQualifiedName(), ImmutableList.of());
assertPlan("SELECT (x, x).* FROM (SELECT rand()) T(x)", any(project(ImmutableMap.of("output_1", expression("row[1]"), "output_2", expression("row[2]")), project(ImmutableMap.of("row", expression("ROW(\"rand\", \"rand\")")), values(ImmutableList.of("rand"), ImmutableList.of(ImmutableList.of(randomFunction)))))));
assertPlan("SELECT (rand(), rand()).* FROM (VALUES 1) t(x)", any(project(ImmutableMap.of("output_1", expression("r[1]"), "output_2", expression("r[2]")), values(ImmutableList.of("r"), ImmutableList.of(ImmutableList.of(new Row(ImmutableList.of(randomFunction, randomFunction))))))));
// Ensure the calls to rand() are not duplicated by the ORDER BY clause
assertPlan("SELECT (rand(), rand()).* FROM (VALUES 1, 2) t(x) ORDER BY 1", anyTree(node(SortNode.class, any(project(ImmutableMap.of("output_1", expression("row[1]"), "output_2", expression("row[2]")), values(ImmutableList.of("row"), ImmutableList.of(ImmutableList.of(new Row(ImmutableList.of(randomFunction, randomFunction))), ImmutableList.of(new Row(ImmutableList.of(randomFunction, randomFunction))))))))));
}
use of io.trino.sql.tree.FunctionCall in project trino by trinodb.
the class TestLogicalPlanner method testDoNotPlanUnreferencedRowPatternMeasures.
@Test
public void testDoNotPlanUnreferencedRowPatternMeasures() {
// row pattern measure `label` is not referenced
assertPlan("SELECT val OVER w " + " FROM (VALUES (1, 90)) t(id, value) " + " WINDOW w AS ( " + " ORDER BY id " + " MEASURES " + " RUNNING LAST(value) AS val, " + " CLASSIFIER() AS label " + " ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING " + " PATTERN (A+) " + " DEFINE A AS true " + " )", output(project(patternRecognition(builder -> builder.specification(specification(ImmutableList.of(), ImmutableList.of("id"), ImmutableMap.of("id", ASC_NULLS_LAST))).addMeasure("val", "LAST(value)", INTEGER).rowsPerMatch(WINDOW).frame(windowFrame(ROWS, CURRENT_ROW, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty())).pattern(new IrQuantified(new IrLabel("A"), oneOrMore(true))).addVariableDefinition(new IrLabel("A"), "true"), values(ImmutableList.of("id", "value"), ImmutableList.of(ImmutableList.of(new LongLiteral("1"), new LongLiteral("90"))))))));
// row pattern measure `label` is not referenced
assertPlan("SELECT min(value) OVER w " + " FROM (VALUES (1, 90)) t(id, value) " + " WINDOW w AS ( " + " ORDER BY id " + " MEASURES CLASSIFIER() AS label " + " ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING " + " PATTERN (A+) " + " DEFINE A AS true " + " )", output(project(patternRecognition(builder -> builder.specification(specification(ImmutableList.of(), ImmutableList.of("id"), ImmutableMap.of("id", ASC_NULLS_LAST))).addFunction("min", functionCall("min", ImmutableList.of("value"))).rowsPerMatch(WINDOW).frame(windowFrame(ROWS, CURRENT_ROW, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty())).pattern(new IrQuantified(new IrLabel("A"), oneOrMore(true))).addVariableDefinition(new IrLabel("A"), "true"), values(ImmutableList.of("id", "value"), ImmutableList.of(ImmutableList.of(new LongLiteral("1"), new LongLiteral("90"))))))));
}
Aggregations