Search in sources :

Example 1 with RelationNode

use of org.apache.hyracks.algebricks.examples.piglet.ast.RelationNode in project asterixdb by apache.

the class PigletCompiler method translate.

private ILogicalPlan translate(List<ASTNode> ast) throws PigletException {
    Map<String, Relation> symMap = new HashMap<String, Relation>();
    List<Mutable<ILogicalOperator>> roots = new ArrayList<Mutable<ILogicalOperator>>();
    previousOp = null;
    for (ASTNode an : ast) {
        switch(an.getTag()) {
            case DUMP:
                {
                    DumpNode dn = (DumpNode) an;
                    Relation input = symMap.get(dn.getAlias());
                    List<Mutable<ILogicalExpression>> expressions = new ArrayList<Mutable<ILogicalExpression>>();
                    for (LogicalVariable v : input.schema.values()) {
                        expressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(v)));
                    }
                    PigletFileDataSink dataSink = new PigletFileDataSink(dn.getFile());
                    ILogicalOperator op = new WriteOperator(expressions, dataSink);
                    op.getInputs().add(new MutableObject<ILogicalOperator>(input.op));
                    roots.add(new MutableObject<ILogicalOperator>(op));
                }
                break;
            case ASSIGNMENT:
                {
                    AssignmentNode asn = (AssignmentNode) an;
                    String alias = asn.getAlias();
                    RelationNode rn = asn.getRelation();
                    Relation rel = translate(rn, symMap);
                    previousOp = rel.op;
                    rel.alias = alias;
                    symMap.put(alias, rel);
                }
                break;
        }
    }
    return new ALogicalPlanImpl(roots);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) RelationNode(org.apache.hyracks.algebricks.examples.piglet.ast.RelationNode) AssignmentNode(org.apache.hyracks.algebricks.examples.piglet.ast.AssignmentNode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) DumpNode(org.apache.hyracks.algebricks.examples.piglet.ast.DumpNode) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ALogicalPlanImpl(org.apache.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ASTNode(org.apache.hyracks.algebricks.examples.piglet.ast.ASTNode) WriteOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.WriteOperator) List(java.util.List) ArrayList(java.util.ArrayList) PigletFileDataSink(org.apache.hyracks.algebricks.examples.piglet.metadata.PigletFileDataSink) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Mutable (org.apache.commons.lang3.mutable.Mutable)1 MutableObject (org.apache.commons.lang3.mutable.MutableObject)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)1 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)1 WriteOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.WriteOperator)1 ALogicalPlanImpl (org.apache.hyracks.algebricks.core.algebra.plan.ALogicalPlanImpl)1 ASTNode (org.apache.hyracks.algebricks.examples.piglet.ast.ASTNode)1 AssignmentNode (org.apache.hyracks.algebricks.examples.piglet.ast.AssignmentNode)1 DumpNode (org.apache.hyracks.algebricks.examples.piglet.ast.DumpNode)1 RelationNode (org.apache.hyracks.algebricks.examples.piglet.ast.RelationNode)1 PigletFileDataSink (org.apache.hyracks.algebricks.examples.piglet.metadata.PigletFileDataSink)1