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());
}
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);
}
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();
}
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());
}
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")));
}
Aggregations