Search in sources :

Example 1 with CharLiteral

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

the class TestMergeProjectWithValues method testMergeProjectWithValues.

@Test
public void testMergeProjectWithValues() {
    tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> {
        Symbol a = p.symbol("a");
        Symbol b = p.symbol("b");
        Symbol c = p.symbol("c");
        Symbol d = p.symbol("d");
        Symbol e = p.symbol("e");
        Symbol f = p.symbol("f");
        Assignments.Builder assignments = Assignments.builder();
        // identity assignment
        assignments.putIdentity(a);
        // renaming assignment
        assignments.put(d, b.toSymbolReference());
        // expression involving input symbol
        assignments.put(e, new IsNullPredicate(a.toSymbolReference()));
        // constant expression
        assignments.put(f, new LongLiteral("1"));
        return p.project(assignments.build(), p.valuesOfExpressions(ImmutableList.of(a, b, c), ImmutableList.of(new Row(ImmutableList.of(new CharLiteral("x"), new BooleanLiteral("true"), new LongLiteral("1"))), new Row(ImmutableList.of(new CharLiteral("y"), new BooleanLiteral("false"), new LongLiteral("2"))), new Row(ImmutableList.of(new CharLiteral("z"), new BooleanLiteral("true"), new LongLiteral("3"))))));
    }).matches(values(ImmutableList.of("a", "d", "e", "f"), ImmutableList.of(ImmutableList.of(new CharLiteral("x"), new BooleanLiteral("true"), new IsNullPredicate(new CharLiteral("x")), new LongLiteral("1")), ImmutableList.of(new CharLiteral("y"), new BooleanLiteral("false"), new IsNullPredicate(new CharLiteral("y")), new LongLiteral("1")), ImmutableList.of(new CharLiteral("z"), new BooleanLiteral("true"), new IsNullPredicate(new CharLiteral("z")), new LongLiteral("1")))));
    // ValuesNode has no rows
    tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> {
        Symbol a = p.symbol("a");
        Symbol b = p.symbol("b");
        Symbol c = p.symbol("c");
        Symbol d = p.symbol("d");
        Symbol e = p.symbol("e");
        Symbol f = p.symbol("f");
        Assignments.Builder assignments = Assignments.builder();
        // identity assignment
        assignments.putIdentity(a);
        // renaming assignment
        assignments.put(d, b.toSymbolReference());
        // expression involving input symbol
        assignments.put(e, new IsNullPredicate(a.toSymbolReference()));
        // constant expression
        assignments.put(f, new LongLiteral("1"));
        return p.project(assignments.build(), p.values(ImmutableList.of(a, b, c), ImmutableList.of()));
    }).matches(values(ImmutableList.of("a", "d", "e", "f"), ImmutableList.of()));
}
Also used : IsNullPredicate(io.trino.sql.tree.IsNullPredicate) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) Cast(io.trino.sql.tree.Cast) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) LongLiteral(io.trino.sql.tree.LongLiteral) NullLiteral(io.trino.sql.tree.NullLiteral) FunctionCall(io.trino.sql.tree.FunctionCall) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) Symbol(io.trino.sql.planner.Symbol) RowType(io.trino.spi.type.RowType) StringLiteral(io.trino.sql.tree.StringLiteral) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) Assignments(io.trino.sql.planner.plan.Assignments) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) DoubleLiteral(io.trino.sql.tree.DoubleLiteral) QualifiedName(io.trino.sql.tree.QualifiedName) CharLiteral(io.trino.sql.tree.CharLiteral) ADD(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.ADD) BIGINT(io.trino.spi.type.BigintType.BIGINT) SymbolReference(io.trino.sql.tree.SymbolReference) Row(io.trino.sql.tree.Row) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) MINUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.MINUS) CharLiteral(io.trino.sql.tree.CharLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) Symbol(io.trino.sql.planner.Symbol) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) IsNullPredicate(io.trino.sql.tree.IsNullPredicate) Row(io.trino.sql.tree.Row) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 2 with CharLiteral

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

the class TestMergeProjectWithValues method testProjectWithoutOutputSymbols.

@Test
public void testProjectWithoutOutputSymbols() {
    // ValuesNode has two output symbols and two rows
    tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(), p.valuesOfExpressions(ImmutableList.of(p.symbol("a"), p.symbol("b")), ImmutableList.of(new Row(ImmutableList.of(new CharLiteral("x"), new BooleanLiteral("true"))), new Row(ImmutableList.of(new CharLiteral("y"), new BooleanLiteral("false"))))))).matches(values(2));
    // ValuesNode has no output symbols and two rows
    tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(), p.values(ImmutableList.of(), ImmutableList.of(ImmutableList.of(), ImmutableList.of())))).matches(values(2));
    // ValuesNode has two output symbols and no rows
    tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(), p.values(ImmutableList.of(p.symbol("a"), p.symbol("b")), ImmutableList.of()))).matches(values());
    // ValuesNode has no output symbols and no rows
    tester().assertThat(new MergeProjectWithValues(tester().getMetadata())).on(p -> p.project(Assignments.of(), p.values(ImmutableList.of(), ImmutableList.of()))).matches(values());
}
Also used : IsNullPredicate(io.trino.sql.tree.IsNullPredicate) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) Cast(io.trino.sql.tree.Cast) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) LongLiteral(io.trino.sql.tree.LongLiteral) NullLiteral(io.trino.sql.tree.NullLiteral) FunctionCall(io.trino.sql.tree.FunctionCall) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) Symbol(io.trino.sql.planner.Symbol) RowType(io.trino.spi.type.RowType) StringLiteral(io.trino.sql.tree.StringLiteral) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) Assignments(io.trino.sql.planner.plan.Assignments) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) DoubleLiteral(io.trino.sql.tree.DoubleLiteral) QualifiedName(io.trino.sql.tree.QualifiedName) CharLiteral(io.trino.sql.tree.CharLiteral) ADD(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.ADD) BIGINT(io.trino.spi.type.BigintType.BIGINT) SymbolReference(io.trino.sql.tree.SymbolReference) Row(io.trino.sql.tree.Row) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) MINUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.MINUS) CharLiteral(io.trino.sql.tree.CharLiteral) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) Row(io.trino.sql.tree.Row) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 3 with CharLiteral

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

the class TestSqlParser method testLiterals.

@Test
public void testLiterals() {
    assertExpression("TIME 'abc'", new TimeLiteral("abc"));
    assertExpression("TIMESTAMP 'abc'", new TimestampLiteral("abc"));
    assertExpression("INTERVAL '33' day", new IntervalLiteral("33", Sign.POSITIVE, IntervalField.DAY, Optional.empty()));
    assertExpression("INTERVAL '33' day to second", new IntervalLiteral("33", Sign.POSITIVE, IntervalField.DAY, Optional.of(IntervalField.SECOND)));
    assertExpression("CHAR 'abc'", new CharLiteral("abc"));
}
Also used : IntervalLiteral(io.trino.sql.tree.IntervalLiteral) TimestampLiteral(io.trino.sql.tree.TimestampLiteral) CharLiteral(io.trino.sql.tree.CharLiteral) TimeLiteral(io.trino.sql.tree.TimeLiteral) Test(org.junit.jupiter.api.Test)

Aggregations

CharLiteral (io.trino.sql.tree.CharLiteral)3 ImmutableList (com.google.common.collect.ImmutableList)2 BIGINT (io.trino.spi.type.BigintType.BIGINT)2 RowType (io.trino.spi.type.RowType)2 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)2 TypeSignatureProvider.fromTypes (io.trino.sql.analyzer.TypeSignatureProvider.fromTypes)2 TypeSignatureTranslator.toSqlType (io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType)2 Symbol (io.trino.sql.planner.Symbol)2 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)2 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)2 PlanBuilder.expression (io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression)2 Assignments (io.trino.sql.planner.plan.Assignments)2 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)2 ADD (io.trino.sql.tree.ArithmeticBinaryExpression.Operator.ADD)2 ArithmeticUnaryExpression (io.trino.sql.tree.ArithmeticUnaryExpression)2 MINUS (io.trino.sql.tree.ArithmeticUnaryExpression.Sign.MINUS)2 BooleanLiteral (io.trino.sql.tree.BooleanLiteral)2 Cast (io.trino.sql.tree.Cast)2 DoubleLiteral (io.trino.sql.tree.DoubleLiteral)2 FunctionCall (io.trino.sql.tree.FunctionCall)2