-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
executable file
·117 lines (106 loc) · 2.86 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import sys
from common import *
from TAggregate import TAggregate
from TBucketize import TBucketize
from TClosure import TClosure
from TDifference import TDifference
from TFilter import TFilter
from TIntersection import TIntersection
from TJoin import TJoin
from TPartition import TPartition
from TRead import TRead
from TSort import TSort
from TUnion import TUnion
from TXpand import TXpand
from TWrite import TWrite
#----------------------------------------------------------------------
# Maps string to operator classes
#
OPERATION_MAP = {
'ta' : TAggregate,
'tb' : TBucketize,
'tc' : TClosure,
'td' : TDifference,
'tf' : TFilter,
'ti' : TIntersection,
'tj' : TJoin,
'tp' : TPartition,
'tr' : TRead,
'ts' : TSort,
'tu' : TUnion,
'tx' : TXpand,
'tw' : TWrite,
}
def log(message):
sys.stderr.write(message)
def die(message = None, exitCode = -1):
if message is not None:
log(message)
log(NL)
sys.exit(exitCode)
def buildPipeline(tokens):
if len(tokens) == 0:
return None
#
def addSeg(p, pclass, pargs):
p2 = pclass(pargs)
if p:
if p2.ninputs > 0 and p2.options.in1 == "-":
p2.t1 = p
elif p2.ninputs > 1 and p2.options.in2 == "-":
p2.t2 = p
pargs[:] = []
return p2
#
pclass = None
p = None
pargs = []
i = 0
stack = []
while i < len(tokens):
t = tokens[i]
if t == "(":
stack.append((pclass, p, pargs, i))
pclass = None
p = None
pargs = []
elif t == ")":
pp = addSeg(p, pclass, pargs)
(pclass, p, pargs, j) = stack.pop()
pargs.append(pp)
elif t == "|":
p = addSeg(p, pclass, pargs)
elif i==0 or tokens[i-1] in ["(","|"]:
pclass = OPERATION_MAP.get(t,None)
if pclass is None: die("Unknown operator specified: " + t)
else:
pargs.append(t)
i = i + 1
p=addSeg(p, pclass, pargs)
#
return p
def pp(p, d=0):
indent = " "*d
print indent, "%s(%d)"%(p.__class__.__name__, p.id)
if p.ninputs == 0:
print indent, "f=", p.options.filename
if type(p.options.filename ) is not types.StringType:
print indent, "Huh."
pp(p.options.filename, d+1)
if p.ninputs > 0:
print indent, "t1="
pp(p.t1, d+1)
if p.ninputs > 1:
print indent, "t2="
pp(p.t2, d+1)
def interpretCommandLine(args):
if type(args) is types.StringType:
args = args.strip().split()
ttobj = buildPipeline(args)
if ttobj.__class__ is not TWrite:
tw = TWrite(["-o", "-"])
tw.t1 = ttobj
ttobj = tw
#pp(ttobj)
for row in ttobj:
pass