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);
}
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);
}
}
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;
}
Aggregations