Search in sources :

Example 71 with Identifier

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

the class QueryRewriter method checksumSql.

private String checksumSql(List<Column> columns, QualifiedName table) throws QueryRewriteException {
    if (columns.isEmpty()) {
        throw new QueryRewriteException("Table " + table + " has no columns");
    }
    ImmutableList.Builder<SelectItem> selectItems = ImmutableList.builder();
    for (Column column : columns) {
        Expression expression = new Identifier(column.getName());
        if (column.isApproximateType()) {
            expression = new FunctionCall(QualifiedName.of("round"), ImmutableList.of(expression, new LongLiteral(Integer.toString(doublePrecision))));
        }
        selectItems.add(new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(expression))));
    }
    Select select = new Select(false, selectItems.build());
    return formatSql(new QuerySpecification(select, Optional.of(new Table(table)), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : DropTable(io.trino.sql.tree.DropTable) CreateTable(io.trino.sql.tree.CreateTable) Table(io.trino.sql.tree.Table) LongLiteral(io.trino.sql.tree.LongLiteral) ImmutableList(com.google.common.collect.ImmutableList) SingleColumn(io.trino.sql.tree.SingleColumn) QuerySpecification(io.trino.sql.tree.QuerySpecification) Identifier(io.trino.sql.tree.Identifier) SingleColumn(io.trino.sql.tree.SingleColumn) Expression(io.trino.sql.tree.Expression) SelectItem(io.trino.sql.tree.SelectItem) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) Select(io.trino.sql.tree.Select) FunctionCall(io.trino.sql.tree.FunctionCall)

Aggregations

Identifier (io.trino.sql.tree.Identifier)71 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)37 Test (org.junit.jupiter.api.Test)37 FunctionCall (io.trino.sql.tree.FunctionCall)19 StringLiteral (io.trino.sql.tree.StringLiteral)19 LongLiteral (io.trino.sql.tree.LongLiteral)18 Test (org.testng.annotations.Test)15 CreateTable (io.trino.sql.tree.CreateTable)14 Property (io.trino.sql.tree.Property)14 Expression (io.trino.sql.tree.Expression)13 Table (io.trino.sql.tree.Table)12 DropTable (io.trino.sql.tree.DropTable)11 AllColumns (io.trino.sql.tree.AllColumns)9 QualifiedName (io.trino.sql.tree.QualifiedName)9 PrincipalSpecification (io.trino.sql.tree.PrincipalSpecification)8 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)6 Session (io.trino.Session)6 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)6 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)5