Search in sources :

Example 1 with SelectRegular

use of org.apache.asterix.lang.sqlpp.clause.SelectRegular in project asterixdb by apache.

the class DeepCopyVisitor method visit.

@Override
public SelectClause visit(SelectClause selectClause, Void arg) throws CompilationException {
    SelectElement selectElement = null;
    SelectRegular selectRegular = null;
    if (selectClause.selectElement()) {
        selectElement = (SelectElement) selectClause.getSelectElement().accept(this, arg);
    }
    if (selectClause.selectRegular()) {
        selectRegular = (SelectRegular) selectClause.getSelectRegular().accept(this, arg);
    }
    return new SelectClause(selectElement, selectRegular, selectClause.distinct());
}
Also used : SelectRegular(org.apache.asterix.lang.sqlpp.clause.SelectRegular) SelectElement(org.apache.asterix.lang.sqlpp.clause.SelectElement) SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause)

Example 2 with SelectRegular

use of org.apache.asterix.lang.sqlpp.clause.SelectRegular in project asterixdb by apache.

the class SqlppExpressionToPlanTranslator method generateReturnExpr.

// Generates the return expression for a select clause.
private Expression generateReturnExpr(SelectClause selectClause, SelectBlock selectBlock) {
    SelectRegular selectRegular = selectClause.getSelectRegular();
    List<FieldBinding> fieldBindings = new ArrayList<>();
    List<Projection> projections = selectRegular.getProjections();
    for (Projection projection : projections) {
        if (projection.star()) {
            if (selectBlock.hasGroupbyClause()) {
                fieldBindings.addAll(getGroupBindings(selectBlock.getGroupbyClause()));
            } else if (selectBlock.hasFromClause()) {
                fieldBindings.addAll(getFromBindings(selectBlock.getFromClause()));
            }
        } else {
            fieldBindings.add(new FieldBinding(new LiteralExpr(new StringLiteral(projection.getName())), projection.getExpression()));
        }
    }
    return new RecordConstructor(fieldBindings);
}
Also used : SelectRegular(org.apache.asterix.lang.sqlpp.clause.SelectRegular) StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) ArrayList(java.util.ArrayList) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding) Projection(org.apache.asterix.lang.sqlpp.clause.Projection) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) RecordConstructor(org.apache.asterix.lang.common.expression.RecordConstructor)

Aggregations

SelectRegular (org.apache.asterix.lang.sqlpp.clause.SelectRegular)2 ArrayList (java.util.ArrayList)1 FieldBinding (org.apache.asterix.lang.common.expression.FieldBinding)1 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)1 RecordConstructor (org.apache.asterix.lang.common.expression.RecordConstructor)1 StringLiteral (org.apache.asterix.lang.common.literal.StringLiteral)1 Projection (org.apache.asterix.lang.sqlpp.clause.Projection)1 SelectClause (org.apache.asterix.lang.sqlpp.clause.SelectClause)1 SelectElement (org.apache.asterix.lang.sqlpp.clause.SelectElement)1