Search in sources :

Example 1 with RecordConstructor

use of org.apache.asterix.lang.common.expression.RecordConstructor in project asterixdb by apache.

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(RecordConstructor rc, VariableSubstitutionEnvironment env) throws CompilationException {
    List<FieldBinding> oldFbs = rc.getFbList();
    ArrayList<FieldBinding> newFbs = new ArrayList<>(oldFbs.size());
    for (FieldBinding fb : oldFbs) {
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fb.getLeftExpr().accept(this, env);
        Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = fb.getRightExpr().accept(this, env);
        FieldBinding fb2 = new FieldBinding((Expression) p1.first, (Expression) p2.first);
        newFbs.add(fb2);
    }
    RecordConstructor newRc = new RecordConstructor(newFbs);
    return new Pair<>(newRc, env);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding) ArrayList(java.util.ArrayList) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) RecordConstructor(org.apache.asterix.lang.common.expression.RecordConstructor) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 2 with RecordConstructor

use of org.apache.asterix.lang.common.expression.RecordConstructor 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)

Example 3 with RecordConstructor

use of org.apache.asterix.lang.common.expression.RecordConstructor in project asterixdb by apache.

the class DeepCopyVisitor method visit.

@Override
public RecordConstructor visit(RecordConstructor rc, Void arg) throws CompilationException {
    List<FieldBinding> bindings = new ArrayList<>();
    for (FieldBinding binding : rc.getFbList()) {
        FieldBinding fb = new FieldBinding((Expression) binding.getLeftExpr().accept(this, arg), (Expression) binding.getRightExpr().accept(this, arg));
        bindings.add(fb);
    }
    return new RecordConstructor(bindings);
}
Also used : ArrayList(java.util.ArrayList) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding) RecordConstructor(org.apache.asterix.lang.common.expression.RecordConstructor)

Aggregations

ArrayList (java.util.ArrayList)3 FieldBinding (org.apache.asterix.lang.common.expression.FieldBinding)3 RecordConstructor (org.apache.asterix.lang.common.expression.RecordConstructor)3 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)1 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)1 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)1 StringLiteral (org.apache.asterix.lang.common.literal.StringLiteral)1 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)1 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)1 Projection (org.apache.asterix.lang.sqlpp.clause.Projection)1 SelectRegular (org.apache.asterix.lang.sqlpp.clause.SelectRegular)1 Pair (org.apache.hyracks.algebricks.common.utils.Pair)1