Search in sources :

Example 1 with QueryPeriod

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

the class AstBuilder method visitQueryPeriod.

@Override
public Node visitQueryPeriod(SqlBaseParser.QueryPeriodContext context) {
    QueryPeriod.RangeType type = getRangeType((Token) context.rangeType().getChild(0).getPayload());
    Expression marker = (Expression) visit(context.valueExpression());
    return new QueryPeriod(getLocation(context), type, marker);
}
Also used : QueryPeriod(io.trino.sql.tree.QueryPeriod) DereferenceExpression(io.trino.sql.tree.DereferenceExpression) LogicalExpression(io.trino.sql.tree.LogicalExpression) SearchedCaseExpression(io.trino.sql.tree.SearchedCaseExpression) BindExpression(io.trino.sql.tree.BindExpression) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) SimpleCaseExpression(io.trino.sql.tree.SimpleCaseExpression) SubqueryExpression(io.trino.sql.tree.SubqueryExpression) LambdaExpression(io.trino.sql.tree.LambdaExpression) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) NullIfExpression(io.trino.sql.tree.NullIfExpression) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) TryExpression(io.trino.sql.tree.TryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression)

Example 2 with QueryPeriod

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

the class TestSqlParser method testQueryPeriod.

@Test
public void testQueryPeriod() {
    Expression rangeValue = new TimestampLiteral(location(1, 37), "2021-03-01 00:00:01");
    QueryPeriod queryPeriod = new QueryPeriod(location(1, 17), QueryPeriod.RangeType.TIMESTAMP, rangeValue);
    Table table = new Table(location(1, 15), qualifiedName(location(1, 15), "t"), queryPeriod);
    assertThat(statement("SELECT * FROM t FOR TIMESTAMP AS OF TIMESTAMP '2021-03-01 00:00:01'")).isEqualTo(new Query(location(1, 1), Optional.empty(), new QuerySpecification(location(1, 1), new Select(location(1, 1), false, ImmutableList.of(new AllColumns(location(1, 8), Optional.empty(), ImmutableList.of()))), Optional.of(table), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
    rangeValue = new StringLiteral(location(1, 35), "version1");
    queryPeriod = new QueryPeriod(new NodeLocation(1, 17), QueryPeriod.RangeType.VERSION, rangeValue);
    table = new Table(location(1, 15), qualifiedName(location(1, 15), "t"), queryPeriod);
    assertThat(statement("SELECT * FROM t FOR VERSION AS OF 'version1'")).isEqualTo(new Query(location(1, 1), Optional.empty(), new QuerySpecification(location(1, 1), new Select(location(1, 1), false, ImmutableList.of(new AllColumns(location(1, 8), Optional.empty(), ImmutableList.of()))), Optional.of(table), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : QuerySpecification(io.trino.sql.tree.QuerySpecification) CreateTable(io.trino.sql.tree.CreateTable) DropTable(io.trino.sql.tree.DropTable) Table(io.trino.sql.tree.Table) TruncateTable(io.trino.sql.tree.TruncateTable) RenameTable(io.trino.sql.tree.RenameTable) TimestampLiteral(io.trino.sql.tree.TimestampLiteral) QueryPeriod(io.trino.sql.tree.QueryPeriod) QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) Query(io.trino.sql.tree.Query) WithQuery(io.trino.sql.tree.WithQuery) StringLiteral(io.trino.sql.tree.StringLiteral) NodeLocation(io.trino.sql.tree.NodeLocation) DereferenceExpression(io.trino.sql.tree.DereferenceExpression) LogicalExpression(io.trino.sql.tree.LogicalExpression) SearchedCaseExpression(io.trino.sql.tree.SearchedCaseExpression) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) SimpleCaseExpression(io.trino.sql.tree.SimpleCaseExpression) SubqueryExpression(io.trino.sql.tree.SubqueryExpression) LambdaExpression(io.trino.sql.tree.LambdaExpression) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) NullIfExpression(io.trino.sql.tree.NullIfExpression) NotExpression(io.trino.sql.tree.NotExpression) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) Select(io.trino.sql.tree.Select) AllColumns(io.trino.sql.tree.AllColumns) Test(org.junit.jupiter.api.Test)

Aggregations

ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)2 CoalesceExpression (io.trino.sql.tree.CoalesceExpression)2 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)2 DereferenceExpression (io.trino.sql.tree.DereferenceExpression)2 Expression (io.trino.sql.tree.Expression)2 IfExpression (io.trino.sql.tree.IfExpression)2 LambdaExpression (io.trino.sql.tree.LambdaExpression)2 LogicalExpression (io.trino.sql.tree.LogicalExpression)2 NotExpression (io.trino.sql.tree.NotExpression)2 NullIfExpression (io.trino.sql.tree.NullIfExpression)2 QuantifiedComparisonExpression (io.trino.sql.tree.QuantifiedComparisonExpression)2 QueryPeriod (io.trino.sql.tree.QueryPeriod)2 SearchedCaseExpression (io.trino.sql.tree.SearchedCaseExpression)2 SimpleCaseExpression (io.trino.sql.tree.SimpleCaseExpression)2 SubqueryExpression (io.trino.sql.tree.SubqueryExpression)2 SubscriptExpression (io.trino.sql.tree.SubscriptExpression)2 QueryUtil.simpleQuery (io.trino.sql.QueryUtil.simpleQuery)1 AllColumns (io.trino.sql.tree.AllColumns)1 ArithmeticUnaryExpression (io.trino.sql.tree.ArithmeticUnaryExpression)1 BindExpression (io.trino.sql.tree.BindExpression)1