Java 类com.facebook.presto.sql.tree.SingleColumn 实例源码

项目:hue    文件:VeroAccessSqlFormatter.java   
@Override
protected Void visitSingleColumn(SingleColumn node, Integer indent)
{
    builder.append(expFormatter.formatExpression(node.getExpression()));
    if (node.getAlias().isPresent()) {
        builder.append(" AS ")
            .append(getIdenSurroundingSymbolLeft())
            .append(caseSensitivityName(node.getAlias().get()))
            .append(getIdenSurroundingSymbolRight()); // TODO: handle quoting properly
    }

    return null;
}
项目:presto-query-formatter    文件:StatementFormatter.java   
@Override
protected Void visitSingleColumn(SingleColumn node, Integer indent)
{
    builder.append(formatExpression(node.getExpression(), parameters, indent));
    if (node.getAlias().isPresent()) {
        builder.append(' ')
                .append('"')
                .append(node.getAlias().get())
                .append('"'); // TODO: handle quoting properly
    }

    return null;
}
项目:sql4es    文件:SelectParser.java   
@Override
protected Object visitSelectItem(SelectItem node, QueryState state){
    if(node instanceof SingleColumn){
        SingleColumn sc = (SingleColumn)node;
        Column column = (Column)sc.getExpression().accept(this, state);
        if(column != null){
            String alias = null;
            if(sc.getAlias().isPresent()) alias = sc.getAlias().get();
            column.setAlias(alias);
            Column col2 = state.getHeading().getColumnByNameAndOp(column.getColumn(), column.getOp());
            if(col2 != null){
                if(!col2.isVisible()) {
                    state.getHeading().remove(col2);
                }
                if(col2.getAlias() != null && alias != null && !col2.getAlias().equals(alias)){
                    state.getHeading().add(column);
                }else {
                    state.getHeading().add(column);
                    if(col2.getAlias() == null) col2.setAlias(alias);
                    col2.setVisible(true);
                    col2.setIndex(column.getIndex());
                }
            }else{
                state.getHeading().add(column);
            }
        }
    }else{
        state.getHeading().add(createColumn(node.toString(), null, state, "select.+", ".+from"));
    }
    return true;
}
项目:presto    文件:StatementAnalyzer.java   
private RelationType computeOutputDescriptor(QuerySpecification node, RelationType inputTupleDescriptor)
{
    ImmutableList.Builder<Field> outputFields = ImmutableList.builder();

    for (SelectItem item : node.getSelect().getSelectItems()) {
        if (item instanceof AllColumns) {
            // expand * and T.*
            Optional<QualifiedName> starPrefix = ((AllColumns) item).getPrefix();

            for (Field field : inputTupleDescriptor.resolveFieldsWithPrefix(starPrefix)) {
                outputFields.add(Field.newUnqualified(field.getName(), field.getType()));
            }
        }
        else if (item instanceof SingleColumn) {
            SingleColumn column = (SingleColumn) item;
            Expression expression = column.getExpression();

            Optional<String> alias = column.getAlias();
            if (!alias.isPresent()) {
                QualifiedName name = null;
                if (expression instanceof QualifiedNameReference) {
                    name = ((QualifiedNameReference) expression).getName();
                }
                else if (expression instanceof DereferenceExpression) {
                    name = DereferenceExpression.getQualifiedName((DereferenceExpression) expression);
                }
                if (name != null) {
                    alias = Optional.of(getLast(name.getOriginalParts()));
                }
            }

            outputFields.add(Field.newUnqualified(alias, analysis.getType(expression))); // TODO don't use analysis as a side-channel. Use outputExpressions to look up the type
        }
        else {
            throw new IllegalArgumentException("Unsupported SelectItem type: " + item.getClass().getName());
        }
    }

    return new RelationType(outputFields.build());
}
项目:presto    文件:SqlFormatter.java   
@Override
protected Void visitSingleColumn(SingleColumn node, Integer indent)
{
    builder.append(formatExpression(node.getExpression()));
    if (node.getAlias().isPresent()) {
        builder.append(' ')
                .append('"')
                .append(node.getAlias().get())
                .append('"'); // TODO: handle quoting properly
    }

    return null;
}
项目:presto    文件:AstBuilder.java   
@Override
public Node visitSelectSingle(SqlBaseParser.SelectSingleContext context)
{
    Optional<String> alias = getTextIfPresent(context.identifier());

    return new SingleColumn(getLocation(context), (Expression) visit(context.expression()), alias);
}
项目:presto    文件:QueryUtil.java   
public static Select selectList(Expression... expressions)
{
    ImmutableList.Builder<SelectItem> items = ImmutableList.builder();
    for (Expression expression : expressions) {
        items.add(new SingleColumn(expression));
    }
    return new Select(false, items.build());
}
项目:EchoQuery    文件:SqlFormatter.java   
@Override
protected Void visitSingleColumn(SingleColumn node, Integer indent)
{
    builder.append(formatExpression(node.getExpression()));
    if (node.getAlias().isPresent()) {
        builder.append(' ')
                .append('"')
                .append(node.getAlias().get())
                .append('"'); // TODO: handle quoting properly
    }

    return null;
}
项目:presto    文件:StatementAnalyzer.java   
private List<FieldOrExpression> analyzeSelect(QuerySpecification node, RelationType tupleDescriptor, AnalysisContext context)
{
    ImmutableList.Builder<FieldOrExpression> outputExpressionBuilder = ImmutableList.builder();

    for (SelectItem item : node.getSelect().getSelectItems()) {
        if (item instanceof AllColumns) {
            // expand * and T.*
            Optional<QualifiedName> starPrefix = ((AllColumns) item).getPrefix();

            List<Field> fields = tupleDescriptor.resolveFieldsWithPrefix(starPrefix);
            if (fields.isEmpty()) {
                if (starPrefix.isPresent()) {
                    throw new SemanticException(MISSING_TABLE, item, "Table '%s' not found", starPrefix.get());
                }
                else {
                    throw new SemanticException(WILDCARD_WITHOUT_FROM, item, "SELECT * not allowed in queries without FROM clause");
                }
            }

            for (Field field : fields) {
                int fieldIndex = tupleDescriptor.indexOf(field);
                outputExpressionBuilder.add(new FieldOrExpression(fieldIndex));

                if (node.getSelect().isDistinct() && !field.getType().isComparable()) {
                    throw new SemanticException(TYPE_MISMATCH, node.getSelect(), "DISTINCT can only be applied to comparable types (actual: %s)", field.getType());
                }
            }
        }
        else if (item instanceof SingleColumn) {
            SingleColumn column = (SingleColumn) item;
            ExpressionAnalysis expressionAnalysis = analyzeExpression(column.getExpression(), tupleDescriptor, context);
            analysis.recordSubqueries(node, expressionAnalysis);
            outputExpressionBuilder.add(new FieldOrExpression(column.getExpression()));

            Type type = expressionAnalysis.getType(column.getExpression());
            if (node.getSelect().isDistinct() && !type.isComparable()) {
                throw new SemanticException(TYPE_MISMATCH, node.getSelect(), "DISTINCT can only be applied to comparable types (actual: %s): %s", type, column.getExpression());
            }
        }
        else {
            throw new IllegalArgumentException("Unsupported SelectItem type: " + item.getClass().getName());
        }
    }

    ImmutableList<FieldOrExpression> result = outputExpressionBuilder.build();
    analysis.setOutputExpressions(node, result);

    return result;
}
项目:presto    文件:QueryUtil.java   
public static SelectItem unaliasedName(String name)
{
    return new SingleColumn(nameReference(name));
}
项目:presto    文件:QueryUtil.java   
public static SelectItem aliasedName(String name, String alias)
{
    return new SingleColumn(nameReference(name), alias);
}
项目:presto    文件:QueryUtil.java   
public static SelectItem aliasedNullToEmpty(String column, String alias)
{
    return new SingleColumn(new CoalesceExpression(nameReference(column), new StringLiteral("")), alias);
}