Search in sources :

Example 1 with FieldBinding

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

the class LangExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(RecordConstructor rc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
    LogicalVariable v1 = context.newVar();
    AssignOperator a = new AssignOperator(v1, new MutableObject<>(f));
    Mutable<ILogicalOperator> topOp = tupSource;
    for (FieldBinding fb : rc.getFbList()) {
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = langExprToAlgExpression(fb.getLeftExpr(), topOp);
        f.getArguments().add(new MutableObject<>(eo1.first));
        topOp = eo1.second;
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = langExprToAlgExpression(fb.getRightExpr(), topOp);
        f.getArguments().add(new MutableObject<>(eo2.first));
        topOp = eo2.second;
    }
    a.getInputs().add(topOp);
    return new Pair<>(a, v1);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) 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 FieldBinding

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

the class InlineColumnAliasVisitor method mapRecordConstructor.

private Map<Expression, Expression> mapRecordConstructor(RecordConstructor rc) {
    Map<Expression, Expression> exprMap = new HashMap<>();
    for (FieldBinding binding : rc.getFbList()) {
        Expression leftExpr = binding.getLeftExpr();
        // (e.g., foo.name AS name) in regular SQL SELECT.
        if (leftExpr.getKind() != Kind.LITERAL_EXPRESSION) {
            continue;
        }
        LiteralExpr literalExpr = (LiteralExpr) leftExpr;
        if (literalExpr.getValue().getLiteralType() == Literal.Type.STRING) {
            String fieldName = SqlppVariableUtil.toInternalVariableName(literalExpr.getValue().getStringValue());
            exprMap.put(new VariableExpr(new VarIdentifier(fieldName)), binding.getRightExpr());
        }
    }
    return exprMap;
}
Also used : HashMap(java.util.HashMap) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 3 with FieldBinding

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

the class QueryPrintVisitor method visit.

@Override
public Void visit(RecordConstructor rc, Integer step) throws CompilationException {
    out.println(skip(step) + "RecordConstructor [");
    // fbList accept visitor
    for (FieldBinding fb : rc.getFbList()) {
        out.println(skip(step + 1) + "(");
        fb.getLeftExpr().accept(this, step + 2);
        out.println(skip(step + 2) + ":");
        fb.getRightExpr().accept(this, step + 2);
        out.println(skip(step + 1) + ")");
    }
    out.println(skip(step) + "]");
    return null;
}
Also used : FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding)

Example 4 with FieldBinding

use of org.apache.asterix.lang.common.expression.FieldBinding 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 5 with FieldBinding

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

the class FreeVariableVisitor method visit.

@Override
public Void visit(RecordConstructor rc, Collection<VariableExpr> freeVars) throws CompilationException {
    for (FieldBinding binding : rc.getFbList()) {
        binding.getLeftExpr().accept(this, freeVars);
        binding.getRightExpr().accept(this, freeVars);
    }
    return null;
}
Also used : FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding)

Aggregations

FieldBinding (org.apache.asterix.lang.common.expression.FieldBinding)14 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)4 ArrayList (java.util.ArrayList)3 RecordConstructor (org.apache.asterix.lang.common.expression.RecordConstructor)3 Expression (org.apache.asterix.lang.common.base.Expression)2 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)2 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)2 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 RecordBuilder (org.apache.asterix.builders.RecordBuilder)1 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)1 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)1 StringLiteral (org.apache.asterix.lang.common.literal.StringLiteral)1 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)1 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)1 Projection (org.apache.asterix.lang.sqlpp.clause.Projection)1 SelectRegular (org.apache.asterix.lang.sqlpp.clause.SelectRegular)1 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)1