Search in sources :

Example 1 with ASTNode

use of org.apache.hyracks.algebricks.examples.piglet.ast.ASTNode 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)

Example 2 with ASTNode

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

the class PigletTestCase method testPiglet.

@Test
public void testPiglet() {
    try {
        FileReader in = new FileReader(file);
        try {
            PigletCompiler c = new PigletCompiler();
            List<ASTNode> ast = c.parse(in);
            JobSpecification jobSpec = c.compile(ast);
            System.err.println(jobSpec.toJSON());
        } finally {
            in.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PigletCompiler(org.apache.hyracks.algebricks.examples.piglet.compiler.PigletCompiler) ASTNode(org.apache.hyracks.algebricks.examples.piglet.ast.ASTNode) FileReader(java.io.FileReader) JobSpecification(org.apache.hyracks.api.job.JobSpecification) Test(org.junit.Test)

Example 3 with ASTNode

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

the class PigletCompiler method parse.

public List<ASTNode> parse(Reader in) throws ParseException {
    PigletParser parser = new PigletParser(in);
    List<ASTNode> statements = parser.Statements();
    return statements;
}
Also used : ASTNode(org.apache.hyracks.algebricks.examples.piglet.ast.ASTNode) PigletParser(org.apache.hyracks.algebricks.examples.piglet.parser.PigletParser)

Aggregations

ASTNode (org.apache.hyracks.algebricks.examples.piglet.ast.ASTNode)3 FileReader (java.io.FileReader)1 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 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 PigletCompiler (org.apache.hyracks.algebricks.examples.piglet.compiler.PigletCompiler)1 PigletFileDataSink (org.apache.hyracks.algebricks.examples.piglet.metadata.PigletFileDataSink)1 PigletParser (org.apache.hyracks.algebricks.examples.piglet.parser.PigletParser)1