Search in sources :

Example 1 with Table

use of io.prestosql.sql.tree.Table in project hetu-core by openlookeng.

the class AstBuilder method visitVacuumTable.

@Override
public Node visitVacuumTable(SqlBaseParser.VacuumTableContext context) {
    boolean isFull = context.FULL() != null;
    boolean isMerge = context.UNIFY() != null;
    // Exclude single quotes
    Optional<String> partition = getTextIfPresent(context.partition).map(s -> {
        if (s.startsWith("'") && s.endsWith("'")) {
            return Optional.of(s.substring(1, s.length() - 1));
        }
        return Optional.of(s);
    }).orElse(Optional.empty());
    boolean isAsync = context.AND_WAIT() == null;
    return new VacuumTable(Optional.of(getLocation(context)), new Table(getLocation(context), getQualifiedName(context.qualifiedName())), isFull, isMerge, partition, isAsync);
}
Also used : CreateSchema(io.prestosql.sql.tree.CreateSchema) DETERMINISTIC(io.prestosql.sql.tree.RoutineCharacteristics.Determinism.DETERMINISTIC) Prepare(io.prestosql.sql.tree.Prepare) Statement(io.prestosql.sql.tree.Statement) Execute(io.prestosql.sql.tree.Execute) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) FetchFirst(io.prestosql.sql.tree.FetchFirst) Identifier(io.prestosql.sql.tree.Identifier) Cube(io.prestosql.sql.tree.Cube) DescribeInput(io.prestosql.sql.tree.DescribeInput) RenameColumn(io.prestosql.sql.tree.RenameColumn) GrantRoles(io.prestosql.sql.tree.GrantRoles) Delete(io.prestosql.sql.tree.Delete) GroupingElement(io.prestosql.sql.tree.GroupingElement) NullLiteral(io.prestosql.sql.tree.NullLiteral) ShowStats(io.prestosql.sql.tree.ShowStats) ShowCache(io.prestosql.sql.tree.ShowCache) Insert(io.prestosql.sql.tree.Insert) TableElement(io.prestosql.sql.tree.TableElement) DropView(io.prestosql.sql.tree.DropView) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) Call(io.prestosql.sql.tree.Call) Union(io.prestosql.sql.tree.Union) ExplainFormat(io.prestosql.sql.tree.ExplainFormat) BetweenPredicate(io.prestosql.sql.tree.BetweenPredicate) Extract(io.prestosql.sql.tree.Extract) DropRole(io.prestosql.sql.tree.DropRole) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) AllColumns(io.prestosql.sql.tree.AllColumns) ShowRoleGrants(io.prestosql.sql.tree.ShowRoleGrants) Node(io.prestosql.sql.tree.Node) ResetSession(io.prestosql.sql.tree.ResetSession) Deallocate(io.prestosql.sql.tree.Deallocate) Lists(com.google.common.collect.Lists) SqlParameterDeclaration(io.prestosql.sql.tree.SqlParameterDeclaration) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Comment(io.prestosql.sql.tree.Comment) SelectItem(io.prestosql.sql.tree.SelectItem) RETURNS_NULL_ON_NULL_INPUT(io.prestosql.sql.tree.RoutineCharacteristics.NullCallClause.RETURNS_NULL_ON_NULL_INPUT) RenameTable(io.prestosql.sql.tree.RenameTable) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) TransactionMode(io.prestosql.sql.tree.TransactionMode) DescribeOutput(io.prestosql.sql.tree.DescribeOutput) Query(io.prestosql.sql.tree.Query) Cache(io.prestosql.sql.tree.Cache) TransactionAccessMode(io.prestosql.sql.tree.TransactionAccessMode) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) NodeLocation(io.prestosql.sql.tree.NodeLocation) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) CurrentUser(io.prestosql.sql.tree.CurrentUser) ShowFunctions(io.prestosql.sql.tree.ShowFunctions) Lateral(io.prestosql.sql.tree.Lateral) ShowCreate(io.prestosql.sql.tree.ShowCreate) Format(io.prestosql.sql.tree.Format) Expression(io.prestosql.sql.tree.Expression) TableSubquery(io.prestosql.sql.tree.TableSubquery) Intersect(io.prestosql.sql.tree.Intersect) RoutineCharacteristics(io.prestosql.sql.tree.RoutineCharacteristics) CreateCube(io.prestosql.sql.tree.CreateCube) DropSchema(io.prestosql.sql.tree.DropSchema) Locale(java.util.Locale) StartTransaction(io.prestosql.sql.tree.StartTransaction) Return(io.prestosql.sql.tree.Return) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) Except(io.prestosql.sql.tree.Except) ImmutableSet(com.google.common.collect.ImmutableSet) IsNullPredicate(io.prestosql.sql.tree.IsNullPredicate) PathElement(io.prestosql.sql.tree.PathElement) DropCache(io.prestosql.sql.tree.DropCache) PathSpecification(io.prestosql.sql.tree.PathSpecification) Collectors(java.util.stream.Collectors) Rollback(io.prestosql.sql.tree.Rollback) SingleColumn(io.prestosql.sql.tree.SingleColumn) CharLiteral(io.prestosql.sql.tree.CharLiteral) With(io.prestosql.sql.tree.With) ExplainType(io.prestosql.sql.tree.ExplainType) DropCube(io.prestosql.sql.tree.DropCube) ShowRoles(io.prestosql.sql.tree.ShowRoles) ShowTables(io.prestosql.sql.tree.ShowTables) CreateRole(io.prestosql.sql.tree.CreateRole) ShowViews(io.prestosql.sql.tree.ShowViews) CurrentPath(io.prestosql.sql.tree.CurrentPath) DecimalLiteral(io.prestosql.sql.tree.DecimalLiteral) Values(io.prestosql.sql.tree.Values) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) ImmutableList(com.google.common.collect.ImmutableList) FunctionCall(io.prestosql.sql.tree.FunctionCall) JoinUsing(io.prestosql.sql.tree.JoinUsing) IntervalLiteral(io.prestosql.sql.tree.IntervalLiteral) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) Limit(io.prestosql.sql.tree.Limit) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) PrincipalSpecification(io.prestosql.sql.tree.PrincipalSpecification) RenameIndex(io.prestosql.sql.tree.RenameIndex) WithQuery(io.prestosql.sql.tree.WithQuery) Offset(io.prestosql.sql.tree.Offset) Collectors.toList(java.util.stream.Collectors.toList) DropIndex(io.prestosql.sql.tree.DropIndex) ReloadCube(io.prestosql.sql.tree.ReloadCube) Use(io.prestosql.sql.tree.Use) JoinOn(io.prestosql.sql.tree.JoinOn) ShowCatalogs(io.prestosql.sql.tree.ShowCatalogs) Table(io.prestosql.sql.tree.Table) SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) Token(org.antlr.v4.runtime.Token) Property(io.prestosql.sql.tree.Property) ShowGrants(io.prestosql.sql.tree.ShowGrants) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) Cast(io.prestosql.sql.tree.Cast) CreateTable(io.prestosql.sql.tree.CreateTable) Join(io.prestosql.sql.tree.Join) ExplainOption(io.prestosql.sql.tree.ExplainOption) ShowExternalFunction(io.prestosql.sql.tree.ShowExternalFunction) WhenClause(io.prestosql.sql.tree.WhenClause) Row(io.prestosql.sql.tree.Row) AssignmentItem(io.prestosql.sql.tree.AssignmentItem) ShowIndex(io.prestosql.sql.tree.ShowIndex) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) CALLED_ON_NULL_INPUT(io.prestosql.sql.tree.RoutineCharacteristics.NullCallClause.CALLED_ON_NULL_INPUT) TimeLiteral(io.prestosql.sql.tree.TimeLiteral) SetSession(io.prestosql.sql.tree.SetSession) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) CreateView(io.prestosql.sql.tree.CreateView) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) DropColumn(io.prestosql.sql.tree.DropColumn) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Grant(io.prestosql.sql.tree.Grant) GroupingSets(io.prestosql.sql.tree.GroupingSets) Analyze(io.prestosql.sql.tree.Analyze) LikeClause(io.prestosql.sql.tree.LikeClause) SetPath(io.prestosql.sql.tree.SetPath) ShowCubes(io.prestosql.sql.tree.ShowCubes) Types(io.prestosql.spi.sql.expression.Types) ArrayList(java.util.ArrayList) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) ShowColumns(io.prestosql.sql.tree.ShowColumns) ParseTree(org.antlr.v4.runtime.tree.ParseTree) LikePredicate(io.prestosql.sql.tree.LikePredicate) LinkedHashSet(java.util.LinkedHashSet) Isolation(io.prestosql.sql.tree.Isolation) ExternalBodyReference(io.prestosql.sql.tree.ExternalBodyReference) CurrentTime(io.prestosql.sql.tree.CurrentTime) QueryBody(io.prestosql.sql.tree.QueryBody) Explain(io.prestosql.sql.tree.Explain) NOT_DETERMINISTIC(io.prestosql.sql.tree.RoutineCharacteristics.Determinism.NOT_DETERMINISTIC) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) AddColumn(io.prestosql.sql.tree.AddColumn) BinaryLiteral(io.prestosql.sql.tree.BinaryLiteral) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) Unnest(io.prestosql.sql.tree.Unnest) Parameter(io.prestosql.sql.tree.Parameter) QualifiedName(io.prestosql.sql.tree.QualifiedName) FunctionProperty(io.prestosql.sql.tree.FunctionProperty) RenameSchema(io.prestosql.sql.tree.RenameSchema) Select(io.prestosql.sql.tree.Select) GrantorSpecification(io.prestosql.sql.tree.GrantorSpecification) Rollup(io.prestosql.sql.tree.Rollup) WindowFrame(io.prestosql.sql.tree.WindowFrame) SetRole(io.prestosql.sql.tree.SetRole) Window(io.prestosql.sql.tree.Window) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) Commit(io.prestosql.sql.tree.Commit) BindExpression(io.prestosql.sql.tree.BindExpression) GroupingOperation(io.prestosql.sql.tree.GroupingOperation) IsNotNullPredicate(io.prestosql.sql.tree.IsNotNullPredicate) ShowSchemas(io.prestosql.sql.tree.ShowSchemas) CreateIndex(io.prestosql.sql.tree.CreateIndex) GroupBy(io.prestosql.sql.tree.GroupBy) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) String.format(java.lang.String.format) RefreshMetadataCache(io.prestosql.sql.tree.RefreshMetadataCache) List(java.util.List) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) AtTimeZone(io.prestosql.sql.tree.AtTimeZone) Optional(java.util.Optional) FrameBound(io.prestosql.sql.tree.FrameBound) IfExpression(io.prestosql.sql.tree.IfExpression) InPredicate(io.prestosql.sql.tree.InPredicate) UpdateIndex(io.prestosql.sql.tree.UpdateIndex) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) CallArgument(io.prestosql.sql.tree.CallArgument) Objects.requireNonNull(java.util.Objects.requireNonNull) RevokeRoles(io.prestosql.sql.tree.RevokeRoles) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) SortItem(io.prestosql.sql.tree.SortItem) TimestampLiteral(io.prestosql.sql.tree.TimestampLiteral) Iterator(java.util.Iterator) OrderBy(io.prestosql.sql.tree.OrderBy) LambdaArgumentDeclaration(io.prestosql.sql.tree.LambdaArgumentDeclaration) Update(io.prestosql.sql.tree.Update) ExistsPredicate(io.prestosql.sql.tree.ExistsPredicate) InsertCube(io.prestosql.sql.tree.InsertCube) Revoke(io.prestosql.sql.tree.Revoke) ShowSession(io.prestosql.sql.tree.ShowSession) TryExpression(io.prestosql.sql.tree.TryExpression) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable)

Example 2 with Table

use of io.prestosql.sql.tree.Table in project hetu-core by openlookeng.

the class TestSqlParser method testCreateTableAsWith.

@Test
public void testCreateTableAsWith() {
    String queryParenthesizedWith = "CREATE TABLE foo " + "AS " + "( WITH t(x) AS (VALUES 1) " + "TABLE t ) " + "WITH NO DATA";
    String queryUnparenthesizedWith = "CREATE TABLE foo " + "AS " + "WITH t(x) AS (VALUES 1) " + "TABLE t " + "WITH NO DATA";
    String queryParenthesizedWithHasAlias = "CREATE TABLE foo(a) " + "AS " + "( WITH t(x) AS (VALUES 1) " + "TABLE t ) " + "WITH NO DATA";
    String queryUnparenthesizedWithHasAlias = "CREATE TABLE foo(a) " + "AS " + "WITH t(x) AS (VALUES 1) " + "TABLE t " + "WITH NO DATA";
    QualifiedName table = QualifiedName.of("foo");
    Query query = new Query(Optional.of(new With(false, ImmutableList.of(new WithQuery(identifier("t"), query(new Values(ImmutableList.of(new LongLiteral("1")))), Optional.of(ImmutableList.of(identifier("x"))))))), new Table(QualifiedName.of("t")), Optional.empty(), Optional.empty(), Optional.empty());
    assertStatement(queryParenthesizedWith, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
    assertStatement(queryUnparenthesizedWith, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.empty(), Optional.empty()));
    assertStatement(queryParenthesizedWithHasAlias, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("a"))), Optional.empty()));
    assertStatement(queryUnparenthesizedWithHasAlias, new CreateTableAsSelect(table, query, false, ImmutableList.of(), false, Optional.of(ImmutableList.of(new Identifier("a"))), Optional.empty()));
}
Also used : Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) LongLiteral(io.prestosql.sql.tree.LongLiteral) WithQuery(io.prestosql.sql.tree.WithQuery) QualifiedName(io.prestosql.sql.tree.QualifiedName) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Values(io.prestosql.sql.tree.Values) With(io.prestosql.sql.tree.With) Test(org.testng.annotations.Test)

Example 3 with Table

use of io.prestosql.sql.tree.Table in project hetu-core by openlookeng.

the class TestSqlParser method testShowStats.

@Test
public void testShowStats() {
    final String[] tableNames = { "t", "s.t", "c.s.t" };
    for (String fullName : tableNames) {
        QualifiedName qualifiedName = makeQualifiedName(fullName);
        assertStatement(format("SHOW STATS FOR %s", qualifiedName), new ShowStats(new Table(qualifiedName)));
    }
}
Also used : Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) ShowStats(io.prestosql.sql.tree.ShowStats) QualifiedName(io.prestosql.sql.tree.QualifiedName) Test(org.testng.annotations.Test)

Example 4 with Table

use of io.prestosql.sql.tree.Table in project hetu-core by openlookeng.

the class TestSqlParser method testSelectWithOffset.

@Test
public void testSelectWithOffset() {
    assertStatement("SELECT * FROM table1 OFFSET 2 ROWS", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset("2")), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 OFFSET 2", new Query(Optional.empty(), new QuerySpecification(selectList(new AllColumns()), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset("2")), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
    Query valuesQuery = query(values(row(new LongLiteral("1"), new StringLiteral("1")), row(new LongLiteral("2"), new StringLiteral("2"))));
    assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) OFFSET 2 ROWS", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset("2")), Optional.empty()));
    assertStatement("SELECT * FROM (VALUES (1, '1'), (2, '2')) OFFSET 2", simpleQuery(selectList(new AllColumns()), subquery(valuesQuery), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new Offset("2")), Optional.empty()));
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) QueryUtil.simpleQuery(io.prestosql.sql.QueryUtil.simpleQuery) Query(io.prestosql.sql.tree.Query) WithQuery(io.prestosql.sql.tree.WithQuery) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) AllColumns(io.prestosql.sql.tree.AllColumns) Offset(io.prestosql.sql.tree.Offset) Test(org.testng.annotations.Test)

Example 5 with Table

use of io.prestosql.sql.tree.Table in project hetu-core by openlookeng.

the class TestSqlParser method testJoinPrecedence.

@Test
public void testJoinPrecedence() {
    assertStatement("SELECT * FROM a CROSS JOIN b LEFT JOIN c ON true", simpleQuery(selectList(new AllColumns()), new Join(Join.Type.LEFT, new Join(Join.Type.CROSS, new Table(QualifiedName.of("a")), new Table(QualifiedName.of("b")), Optional.empty()), new Table(QualifiedName.of("c")), Optional.of(new JoinOn(BooleanLiteral.TRUE_LITERAL)))));
    assertStatement("SELECT * FROM a CROSS JOIN b NATURAL JOIN c CROSS JOIN d NATURAL JOIN e", simpleQuery(selectList(new AllColumns()), new Join(Join.Type.INNER, new Join(Join.Type.CROSS, new Join(Join.Type.INNER, new Join(Join.Type.CROSS, new Table(QualifiedName.of("a")), new Table(QualifiedName.of("b")), Optional.empty()), new Table(QualifiedName.of("c")), Optional.of(new NaturalJoin())), new Table(QualifiedName.of("d")), Optional.empty()), new Table(QualifiedName.of("e")), Optional.of(new NaturalJoin()))));
}
Also used : Table(io.prestosql.sql.tree.Table) CreateTable(io.prestosql.sql.tree.CreateTable) VacuumTable(io.prestosql.sql.tree.VacuumTable) DropTable(io.prestosql.sql.tree.DropTable) RenameTable(io.prestosql.sql.tree.RenameTable) Join(io.prestosql.sql.tree.Join) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) AllColumns(io.prestosql.sql.tree.AllColumns) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) JoinOn(io.prestosql.sql.tree.JoinOn) Test(org.testng.annotations.Test)

Aggregations

Table (io.prestosql.sql.tree.Table)23 CreateTable (io.prestosql.sql.tree.CreateTable)18 DropTable (io.prestosql.sql.tree.DropTable)18 RenameTable (io.prestosql.sql.tree.RenameTable)15 VacuumTable (io.prestosql.sql.tree.VacuumTable)14 Test (org.testng.annotations.Test)14 Identifier (io.prestosql.sql.tree.Identifier)13 Query (io.prestosql.sql.tree.Query)13 QuerySpecification (io.prestosql.sql.tree.QuerySpecification)13 LongLiteral (io.prestosql.sql.tree.LongLiteral)12 AllColumns (io.prestosql.sql.tree.AllColumns)11 WithQuery (io.prestosql.sql.tree.WithQuery)10 QueryUtil.simpleQuery (io.prestosql.sql.QueryUtil.simpleQuery)8 Expression (io.prestosql.sql.tree.Expression)8 FunctionCall (io.prestosql.sql.tree.FunctionCall)8 StringLiteral (io.prestosql.sql.tree.StringLiteral)7 ImmutableList (com.google.common.collect.ImmutableList)6 Select (io.prestosql.sql.tree.Select)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 TableHandle (io.prestosql.spi.metadata.TableHandle)5