Search in sources :

Example 21 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class QueryRewriter method applyPropertyOverride.

private static List<Property> applyPropertyOverride(List<Property> properties, List<Property> overrides) {
    Map<String, Expression> propertyMap = properties.stream().collect(toImmutableMap(property -> property.getName().getValue().toLowerCase(ENGLISH), Property::getValue));
    Map<String, Expression> overrideMap = overrides.stream().collect(toImmutableMap(property -> property.getName().getValue().toLowerCase(ENGLISH), Property::getValue));
    return Stream.concat(propertyMap.entrySet().stream(), overrideMap.entrySet().stream()).collect(Collectors.toMap(Entry::getKey, Entry::getValue, (original, override) -> override)).entrySet().stream().map(entry -> new Property(new Identifier(entry.getKey()), entry.getValue())).collect(toImmutableList());
}
Also used : INCLUDING(com.facebook.presto.sql.tree.LikeClause.PropertiesOption.INCLUDING) TypeSignature(com.facebook.presto.common.type.TypeSignature) QueryObjectBundle(com.facebook.presto.verifier.framework.QueryObjectBundle) MAP(com.facebook.presto.common.type.StandardTypes.MAP) SelectItem(com.facebook.presto.sql.tree.SelectItem) Map(java.util.Map) DropView(com.facebook.presto.sql.tree.DropView) CreateTable(com.facebook.presto.sql.tree.CreateTable) ENGLISH(java.util.Locale.ENGLISH) TIME(com.facebook.presto.common.type.TimeType.TIME) LikeClause(com.facebook.presto.sql.tree.LikeClause) Query(com.facebook.presto.sql.tree.Query) QuerySpecification(com.facebook.presto.sql.tree.QuerySpecification) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ClusterType(com.facebook.presto.verifier.framework.ClusterType) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) SqlParser(com.facebook.presto.sql.parser.SqlParser) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) UNKNOWN(com.facebook.presto.common.type.UnknownType.UNKNOWN) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) DropTable(com.facebook.presto.sql.tree.DropTable) Entry(java.util.Map.Entry) Optional(java.util.Optional) VIEW(com.facebook.presto.sql.tree.ShowCreate.Type.VIEW) Select(com.facebook.presto.sql.tree.Select) ResultSetMetaData(java.sql.ResultSetMetaData) CreateView(com.facebook.presto.sql.tree.CreateView) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) MapType(com.facebook.presto.common.type.MapType) DecimalType(com.facebook.presto.common.type.DecimalType) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter) Field(com.facebook.presto.common.type.RowType.Field) TIMESTAMP_WITH_TIME_ZONE(com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) SHOW_CREATE_VIEW_CONVERTER(com.facebook.presto.verifier.framework.CreateViewVerification.SHOW_CREATE_VIEW_CONVERTER) VerifierUtil.getColumnTypes(com.facebook.presto.verifier.framework.VerifierUtil.getColumnTypes) DATE(com.facebook.presto.common.type.DateType.DATE) SingleColumn(com.facebook.presto.sql.tree.SingleColumn) ArrayList(java.util.ArrayList) Identifier(com.facebook.presto.sql.tree.Identifier) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) TypeManager(com.facebook.presto.common.type.TypeManager) Objects.requireNonNull(java.util.Objects.requireNonNull) REWRITE(com.facebook.presto.verifier.framework.QueryStage.REWRITE) ArrayType(com.facebook.presto.common.type.ArrayType) AllColumns(com.facebook.presto.sql.tree.AllColumns) Cast(com.facebook.presto.sql.tree.Cast) Type(com.facebook.presto.common.type.Type) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect) Property(com.facebook.presto.sql.tree.Property) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) Language(org.intellij.lang.annotations.Language) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ResultSetConverter(com.facebook.presto.verifier.prestoaction.PrestoAction.ResultSetConverter) Insert(com.facebook.presto.sql.tree.Insert) QueryException(com.facebook.presto.verifier.framework.QueryException) UUID.randomUUID(java.util.UUID.randomUUID) Expression(com.facebook.presto.sql.tree.Expression) ShowCreate(com.facebook.presto.sql.tree.ShowCreate) PrestoAction(com.facebook.presto.verifier.prestoaction.PrestoAction) VerifierUtil.getColumnNames(com.facebook.presto.verifier.framework.VerifierUtil.getColumnNames) PARSING_OPTIONS(com.facebook.presto.verifier.framework.VerifierUtil.PARSING_OPTIONS) RowType(com.facebook.presto.common.type.RowType) Statement(com.facebook.presto.sql.tree.Statement) Identifier(com.facebook.presto.sql.tree.Identifier) Expression(com.facebook.presto.sql.tree.Expression) Property(com.facebook.presto.sql.tree.Property)

Example 22 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class QueryRewriter method generateTemporaryName.

private QualifiedName generateTemporaryName(Optional<QualifiedName> originalName, QualifiedName prefix) {
    List<Identifier> parts = new ArrayList<>();
    int originalSize = originalName.map(QualifiedName::getOriginalParts).map(List::size).orElse(0);
    int prefixSize = prefix.getOriginalParts().size();
    if (originalName.isPresent() && originalSize > prefixSize) {
        parts.addAll(originalName.get().getOriginalParts().subList(0, originalSize - prefixSize));
    }
    parts.addAll(prefix.getOriginalParts());
    parts.set(parts.size() - 1, new Identifier(prefix.getSuffix() + "_" + randomUUID().toString().replace("-", "")));
    return QualifiedName.of(parts);
}
Also used : Identifier(com.facebook.presto.sql.tree.Identifier) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) ArrayList(java.util.ArrayList)

Example 23 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class TestDeallocateTask method executeDeallocate.

private Set<String> executeDeallocate(String statementName, String sqlString, Session session) {
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine(sqlString, session, false, transactionManager, executor, metadata);
    Deallocate deallocate = new Deallocate(new Identifier(statementName));
    DeallocateTask deallocateTask = new DeallocateTask();
    deallocateTask.execute(deallocate, transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList());
    return stateMachine.getDeallocatedPreparedStatements();
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) Identifier(com.facebook.presto.sql.tree.Identifier) Deallocate(com.facebook.presto.sql.tree.Deallocate) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl)

Example 24 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class QueryRewriter method checksumSql.

private String checksumSql(List<Column> columns, QualifiedName table) throws SQLException {
    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(), Optional.empty(), Optional.empty()), Optional.empty());
}
Also used : QuerySpecification(com.facebook.presto.sql.tree.QuerySpecification) Identifier(com.facebook.presto.sql.tree.Identifier) Table(com.facebook.presto.sql.tree.Table) DropTable(com.facebook.presto.sql.tree.DropTable) SingleColumn(com.facebook.presto.sql.tree.SingleColumn) Expression(com.facebook.presto.sql.tree.Expression) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) ImmutableList(com.google.common.collect.ImmutableList) SelectItem(com.facebook.presto.sql.tree.SelectItem) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect) Select(com.facebook.presto.sql.tree.Select) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) SingleColumn(com.facebook.presto.sql.tree.SingleColumn)

Example 25 with Identifier

use of com.facebook.presto.sql.tree.Identifier in project presto by prestodb.

the class TestSqlParser method testShowPartitions.

@Test
public void testShowPartitions() {
    assertStatement("SHOW PARTITIONS FROM t", new ShowPartitions(QualifiedName.of("t"), Optional.empty(), ImmutableList.of(), Optional.empty()));
    assertStatement("SHOW PARTITIONS FROM t WHERE x = 1", new ShowPartitions(QualifiedName.of("t"), Optional.of(new ComparisonExpression(ComparisonExpressionType.EQUAL, new Identifier("x"), new LongLiteral("1"))), ImmutableList.of(), Optional.empty()));
    assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y", new ShowPartitions(QualifiedName.of("t"), Optional.of(new ComparisonExpression(ComparisonExpressionType.EQUAL, new Identifier("x"), new LongLiteral("1"))), ImmutableList.of(new SortItem(new Identifier("y"), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)), Optional.empty()));
    assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y LIMIT 10", new ShowPartitions(QualifiedName.of("t"), Optional.of(new ComparisonExpression(ComparisonExpressionType.EQUAL, new Identifier("x"), new LongLiteral("1"))), ImmutableList.of(new SortItem(new Identifier("y"), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)), Optional.of("10")));
    assertStatement("SHOW PARTITIONS FROM t WHERE x = 1 ORDER BY y LIMIT ALL", new ShowPartitions(QualifiedName.of("t"), Optional.of(new ComparisonExpression(ComparisonExpressionType.EQUAL, new Identifier("x"), new LongLiteral("1"))), ImmutableList.of(new SortItem(new Identifier("y"), SortItem.Ordering.ASCENDING, SortItem.NullOrdering.UNDEFINED)), Optional.of("ALL")));
}
Also used : QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) SortItem(com.facebook.presto.sql.tree.SortItem) Identifier(com.facebook.presto.sql.tree.Identifier) ShowPartitions(com.facebook.presto.sql.tree.ShowPartitions) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Test(org.testng.annotations.Test)

Aggregations

Identifier (com.facebook.presto.sql.tree.Identifier)46 Test (org.testng.annotations.Test)31 QueryUtil.quotedIdentifier (com.facebook.presto.sql.QueryUtil.quotedIdentifier)27 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)15 Query (com.facebook.presto.sql.tree.Query)11 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)10 AllColumns (com.facebook.presto.sql.tree.AllColumns)9 DropTable (com.facebook.presto.sql.tree.DropTable)9 QualifiedName (com.facebook.presto.sql.tree.QualifiedName)9 QuerySpecification (com.facebook.presto.sql.tree.QuerySpecification)9 Table (com.facebook.presto.sql.tree.Table)9 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)8 CreateTable (com.facebook.presto.sql.tree.CreateTable)8 Expression (com.facebook.presto.sql.tree.Expression)8 QueryUtil.simpleQuery (com.facebook.presto.sql.QueryUtil.simpleQuery)7 SingleColumn (com.facebook.presto.sql.tree.SingleColumn)7 StringLiteral (com.facebook.presto.sql.tree.StringLiteral)7 WithQuery (com.facebook.presto.sql.tree.WithQuery)7 CreateTableAsSelect (com.facebook.presto.sql.tree.CreateTableAsSelect)6 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)6