Search in sources :

Example 21 with FunctionCall

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

the class TestSqlParser method testListagg.

@Test
public void testListagg() {
    assertExpression("LISTAGG(x) WITHIN GROUP (ORDER BY x)", new FunctionCall(Optional.empty(), QualifiedName.of("LISTAGG"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new Identifier("x", false), ASCENDING, UNDEFINED)))), false, Optional.empty(), Optional.empty(), ImmutableList.of(identifier("x"), new StringLiteral(""), new BooleanLiteral("true"), new StringLiteral("..."), new BooleanLiteral("false"))));
    assertExpression("LISTAGG( DISTINCT x) WITHIN GROUP (ORDER BY x)", new FunctionCall(Optional.empty(), QualifiedName.of("LISTAGG"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new Identifier("x", false), ASCENDING, UNDEFINED)))), true, Optional.empty(), Optional.empty(), ImmutableList.of(identifier("x"), new StringLiteral(""), new BooleanLiteral("true"), new StringLiteral("..."), new BooleanLiteral("false"))));
    assertExpression("LISTAGG(x, ',') WITHIN GROUP (ORDER BY y)", new FunctionCall(Optional.empty(), QualifiedName.of("LISTAGG"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new Identifier("y", false), ASCENDING, UNDEFINED)))), false, Optional.empty(), Optional.empty(), ImmutableList.of(identifier("x"), new StringLiteral(","), new BooleanLiteral("true"), new StringLiteral("..."), new BooleanLiteral("false"))));
    assertExpression("LISTAGG(x, ',' ON OVERFLOW ERROR) WITHIN GROUP (ORDER BY x)", new FunctionCall(Optional.empty(), QualifiedName.of("LISTAGG"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new Identifier("x", false), ASCENDING, UNDEFINED)))), false, Optional.empty(), Optional.empty(), ImmutableList.of(identifier("x"), new StringLiteral(","), new BooleanLiteral("true"), new StringLiteral("..."), new BooleanLiteral("false"))));
    assertExpression("LISTAGG(x, ',' ON OVERFLOW TRUNCATE WITH COUNT) WITHIN GROUP (ORDER BY x)", new FunctionCall(Optional.empty(), QualifiedName.of("LISTAGG"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new Identifier("x", false), ASCENDING, UNDEFINED)))), false, Optional.empty(), Optional.empty(), ImmutableList.of(identifier("x"), new StringLiteral(","), new BooleanLiteral("false"), new StringLiteral("..."), new BooleanLiteral("true"))));
    assertExpression("LISTAGG(x, ',' ON OVERFLOW TRUNCATE 'HIDDEN' WITHOUT COUNT) WITHIN GROUP (ORDER BY x)", new FunctionCall(Optional.empty(), QualifiedName.of("LISTAGG"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new Identifier("x", false), ASCENDING, UNDEFINED)))), false, Optional.empty(), Optional.empty(), ImmutableList.of(identifier("x"), new StringLiteral(","), new BooleanLiteral("false"), new StringLiteral("HIDDEN"), new BooleanLiteral("false"))));
}
Also used : OrderBy(io.trino.sql.tree.OrderBy) SortItem(io.trino.sql.tree.SortItem) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.junit.jupiter.api.Test)

Example 22 with FunctionCall

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

the class TestSqlParser method testWindowSpecification.

@Test
public void testWindowSpecification() {
    assertExpression("rank() OVER someWindow", new FunctionCall(Optional.empty(), QualifiedName.of("rank"), Optional.of(new WindowReference(new Identifier("someWindow"))), Optional.empty(), Optional.empty(), false, Optional.empty(), Optional.empty(), ImmutableList.of()));
    assertExpression("rank() OVER (someWindow PARTITION BY x ORDER BY y ROWS CURRENT ROW)", new FunctionCall(Optional.empty(), QualifiedName.of("rank"), Optional.of(new WindowSpecification(Optional.of(new Identifier("someWindow")), ImmutableList.of(new Identifier("x")), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new Identifier("y"), ASCENDING, UNDEFINED)))), Optional.of(new WindowFrame(ROWS, new FrameBound(CURRENT_ROW), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), ImmutableList.of())))), Optional.empty(), Optional.empty(), false, Optional.empty(), Optional.empty(), ImmutableList.of()));
    assertExpression("rank() OVER (PARTITION BY x ORDER BY y ROWS CURRENT ROW)", new FunctionCall(Optional.empty(), QualifiedName.of("rank"), Optional.of(new WindowSpecification(Optional.empty(), ImmutableList.of(new Identifier("x")), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new Identifier("y"), ASCENDING, UNDEFINED)))), Optional.of(new WindowFrame(ROWS, new FrameBound(CURRENT_ROW), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), ImmutableList.of())))), Optional.empty(), Optional.empty(), false, Optional.empty(), Optional.empty(), ImmutableList.of()));
}
Also used : OrderBy(io.trino.sql.tree.OrderBy) SortItem(io.trino.sql.tree.SortItem) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) WindowFrame(io.trino.sql.tree.WindowFrame) FrameBound(io.trino.sql.tree.FrameBound) WindowSpecification(io.trino.sql.tree.WindowSpecification) FunctionCall(io.trino.sql.tree.FunctionCall) WindowReference(io.trino.sql.tree.WindowReference) Test(org.junit.jupiter.api.Test)

Example 23 with FunctionCall

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

the class TestSqlParser method testLambda.

@Test
public void testLambda() {
    assertExpression("() -> x", new LambdaExpression(ImmutableList.of(), new Identifier("x")));
    assertExpression("x -> sin(x)", new LambdaExpression(ImmutableList.of(new LambdaArgumentDeclaration(identifier("x"))), new FunctionCall(QualifiedName.of("sin"), ImmutableList.of(new Identifier("x")))));
    assertExpression("(x, y) -> mod(x, y)", new LambdaExpression(ImmutableList.of(new LambdaArgumentDeclaration(identifier("x")), new LambdaArgumentDeclaration(identifier("y"))), new FunctionCall(QualifiedName.of("mod"), ImmutableList.of(new Identifier("x"), new Identifier("y")))));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) LambdaArgumentDeclaration(io.trino.sql.tree.LambdaArgumentDeclaration) FunctionCall(io.trino.sql.tree.FunctionCall) LambdaExpression(io.trino.sql.tree.LambdaExpression) Test(org.junit.jupiter.api.Test)

Example 24 with FunctionCall

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

the class TestSqlParser method testSetSession.

@Test
public void testSetSession() {
    assertStatement("SET SESSION foo = 'bar'", new SetSession(QualifiedName.of("foo"), new StringLiteral("bar")));
    assertStatement("SET SESSION foo.bar = 'baz'", new SetSession(QualifiedName.of("foo", "bar"), new StringLiteral("baz")));
    assertStatement("SET SESSION foo.bar.boo = 'baz'", new SetSession(QualifiedName.of("foo", "bar", "boo"), new StringLiteral("baz")));
    assertStatement("SET SESSION foo.bar = 'ban' || 'ana'", new SetSession(QualifiedName.of("foo", "bar"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))));
}
Also used : SetSession(io.trino.sql.tree.SetSession) StringLiteral(io.trino.sql.tree.StringLiteral) FunctionCall(io.trino.sql.tree.FunctionCall) Test(org.junit.jupiter.api.Test)

Example 25 with FunctionCall

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

FunctionCall (io.trino.sql.tree.FunctionCall)69 Test (org.testng.annotations.Test)32 StringLiteral (io.trino.sql.tree.StringLiteral)31 ImmutableList (com.google.common.collect.ImmutableList)29 QualifiedName (io.trino.sql.tree.QualifiedName)29 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)25 Expression (io.trino.sql.tree.Expression)25 LongLiteral (io.trino.sql.tree.LongLiteral)25 Optional (java.util.Optional)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 Identifier (io.trino.sql.tree.Identifier)19 TypeSignatureProvider.fromTypes (io.trino.sql.analyzer.TypeSignatureProvider.fromTypes)18 ResolvedFunction (io.trino.metadata.ResolvedFunction)17 Assignments (io.trino.sql.planner.plan.Assignments)16 Cast (io.trino.sql.tree.Cast)15 TypeSignatureTranslator.toSqlType (io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType)14 BIGINT (io.trino.spi.type.BigintType.BIGINT)13 PlanMatchPattern.project (io.trino.sql.planner.assertions.PlanMatchPattern.project)13 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)13 MetadataManager.createTestMetadataManager (io.trino.metadata.MetadataManager.createTestMetadataManager)12