Initial import into git.
[galago.git] / java / pig-galago / src / com / yahoo / pig / impl / logicalLayer / LogicalPlan.java
blob63b4eca2f12b03820009761863aaa3202f8cd960
1 /*
2 * Copyright (c) 2007 Yahoo! Inc. All rights reserved.
3 * See accompanying LICENSE file.
4 */
5 package com.yahoo.pig.impl.logicalLayer;
7 import java.util.LinkedList;
8 import java.util.List;
10 import com.yahoo.pig.impl.PigContext;
13 public class LogicalPlan {
14 public String alias;
15 LogicalOperator root;
16 PigContext pigContext;
18 public LogicalPlan(LogicalOperator rootIn, PigContext pigContext) {
19 this.pigContext = pigContext;
20 root = rootIn;
21 alias = root.alias;
24 public LogicalOperator root() {
25 return root;
28 public void setRoot(LogicalOperator newRoot) {
29 root = newRoot;
32 public PigContext getPigContext() {
33 return pigContext;
36 public List<String> getFuncs() {
37 if (root == null) return new LinkedList<String>();
38 else return root.getFuncs();
41 // indentation for root is 0
42 public String toString() {
43 StringBuffer sb = new StringBuffer();
44 sb.append(root.name() +"(" + root.arguments() +")\n");
45 sb.append(appendChildren(root, 1));
46 return sb.toString();
48 public String appendChildren(LogicalOperator parent, int indentation) {
49 StringBuffer sb = new StringBuffer();
50 LogicalOperator[] children = parent.children();
51 for(int i=0; i != children.length; i++) {
52 for(int j=0; j != indentation; j++) {
53 sb.append("\t");
55 sb.append(children[i].name() + "(" + children[i].arguments()+ ")\n");
56 sb.append(appendChildren(children[i], indentation+1));
58 return sb.toString();
61 public int getOutputType(){
62 return root.getOutputType();