private Multimap<QualifiedName, Expression> extractNamedOutputExpressions(Select node) { // Compute aliased output terms so we can resolve order by expressions against them first ImmutableMultimap.Builder<QualifiedName, Expression> assignments = ImmutableMultimap.builder(); for (SelectItem item : node.getSelectItems()) { if (item instanceof SingleColumn) { SingleColumn column = (SingleColumn) item; Optional<Identifier> alias = column.getAlias(); if (alias.isPresent()) { assignments.put(QualifiedName.of(alias.get().getValue()), column.getExpression()); // TODO: need to know if alias was quoted } else if (column.getExpression() instanceof Identifier) { assignments.put(QualifiedName.of(((Identifier) column.getExpression()).getValue()), column.getExpression()); } } } return assignments.build(); }
@Override protected Void visitSingleColumn(SingleColumn node, Integer indent) { builder.append(formatExpression(node.getExpression(), tableNameMapper, columnNameMapper, queryWithTables, escapeIdentifier)); if (node.getAlias().isPresent()) { builder.append(' ') .append(formatExpression(node.getAlias().get(), tableNameMapper, columnNameMapper, queryWithTables, escapeIdentifier)); } return null; }
if (singleColumn.getAlias().isPresent()) { throw new RakamException("Alias in SELECT is not supported", BAD_REQUEST);
Expression expression = column.getExpression(); Optional<String> alias = column.getAlias(); if (!alias.isPresent()) { QualifiedName name = null;
for (SelectItem item : node.getSelect().getSelectItems()) { if (item instanceof SingleColumn) { Optional<String> alias = ((SingleColumn) item).getAlias(); if (alias.isPresent()) {