-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImplCreator.java
183 lines (158 loc) · 7.6 KB
/
ImplCreator.java
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.drill.exec.physical.impl;
import java.util.Collections;
import java.util.List;
import org.apache.drill.common.exceptions.ExecutionSetupException;
import org.apache.drill.exec.ops.FragmentContext;
import org.apache.drill.exec.physical.base.AbstractPhysicalVisitor;
import org.apache.drill.exec.physical.base.FragmentRoot;
import org.apache.drill.exec.physical.base.PhysicalOperator;
import org.apache.drill.exec.physical.base.SubScan;
import org.apache.drill.exec.physical.config.*;
import org.apache.drill.exec.physical.impl.aggregate.AggBatchCreator;
import org.apache.drill.exec.physical.config.Union;
import org.apache.drill.exec.physical.impl.filter.FilterBatchCreator;
import org.apache.drill.exec.physical.impl.join.MergeJoinCreator;
import org.apache.drill.exec.physical.impl.limit.LimitBatchCreator;
import org.apache.drill.exec.physical.impl.partitionsender.PartitionSenderCreator;
import org.apache.drill.exec.physical.impl.project.ProjectBatchCreator;
import org.apache.drill.exec.physical.impl.sort.SortBatchCreator;
import org.apache.drill.exec.physical.impl.svremover.SVRemoverCreator;
import org.apache.drill.exec.physical.impl.union.UnionBatchCreator;
import org.apache.drill.exec.record.RecordBatch;
import org.apache.drill.exec.store.json.JSONScanBatchCreator;
import org.apache.drill.exec.store.json.JSONSubScan;
import org.apache.drill.exec.store.mock.MockScanBatchCreator;
import org.apache.drill.exec.store.mock.MockSubScanPOP;
import org.apache.drill.exec.store.parquet.ParquetRowGroupScan;
import org.apache.drill.exec.store.parquet.ParquetScanBatchCreator;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
/**
* Implementation of the physical operator visitor
*/
public class ImplCreator extends AbstractPhysicalVisitor<RecordBatch, FragmentContext, ExecutionSetupException>{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ImplCreator.class);
// Element creators supported by this visitor
private MockScanBatchCreator msc = new MockScanBatchCreator();
private ParquetScanBatchCreator parquetScan = new ParquetScanBatchCreator();
private ScreenCreator sc = new ScreenCreator();
private RandomReceiverCreator rrc = new RandomReceiverCreator();
private PartitionSenderCreator hsc = new PartitionSenderCreator();
private SingleSenderCreator ssc = new SingleSenderCreator();
private ProjectBatchCreator pbc = new ProjectBatchCreator();
private FilterBatchCreator fbc = new FilterBatchCreator();
private LimitBatchCreator lbc = new LimitBatchCreator();
private UnionBatchCreator unionbc = new UnionBatchCreator();
private SVRemoverCreator svc = new SVRemoverCreator();
private SortBatchCreator sbc = new SortBatchCreator();
private AggBatchCreator abc = new AggBatchCreator();
private MergeJoinCreator mjc = new MergeJoinCreator();
private RootExec root = null;
private ImplCreator(){}
public RootExec getRoot(){
return root;
}
@Override
public RecordBatch visitProject(Project op, FragmentContext context) throws ExecutionSetupException {
return pbc.getBatch(context, op, getChildren(op, context));
}
@Override
public RecordBatch visitSubScan(SubScan subScan, FragmentContext context) throws ExecutionSetupException {
Preconditions.checkNotNull(subScan);
Preconditions.checkNotNull(context);
if (subScan instanceof MockSubScanPOP) {
return msc.getBatch(context, (MockSubScanPOP) subScan, Collections.<RecordBatch> emptyList());
} else if (subScan instanceof JSONSubScan) {
return new JSONScanBatchCreator().getBatch(context, (JSONSubScan) subScan, Collections.<RecordBatch> emptyList());
} else if (subScan instanceof ParquetRowGroupScan) {
return parquetScan.getBatch(context, (ParquetRowGroupScan) subScan, Collections.<RecordBatch> emptyList());
} else {
return super.visitSubScan(subScan, context);
}
}
@Override
public RecordBatch visitOp(PhysicalOperator op, FragmentContext context) throws ExecutionSetupException {
if (op instanceof SelectionVectorRemover) {
return svc.getBatch(context, (SelectionVectorRemover) op, getChildren(op, context));
} else {
return super.visitOp(op, context);
}
}
@Override
public RecordBatch visitSort(Sort sort, FragmentContext context) throws ExecutionSetupException {
return sbc.getBatch(context, sort, getChildren(sort, context));
}
@Override
public RecordBatch visitLimit(Limit limit, FragmentContext context) throws ExecutionSetupException {
return lbc.getBatch(context, limit, getChildren(limit, context));
}
@Override
public RecordBatch visitMergeJoin(MergeJoinPOP op, FragmentContext context) throws ExecutionSetupException {
return mjc.getBatch(context, op, getChildren(op, context));
}
@Override
public RecordBatch visitScreen(Screen op, FragmentContext context) throws ExecutionSetupException {
Preconditions.checkArgument(root == null);
root = sc.getRoot(context, op, getChildren(op, context));
return null;
}
@Override
public RecordBatch visitHashPartitionSender(HashPartitionSender op, FragmentContext context) throws ExecutionSetupException {
root = hsc.getRoot(context, op, getChildren(op, context));
return null;
}
@Override
public RecordBatch visitFilter(Filter filter, FragmentContext context) throws ExecutionSetupException {
return fbc.getBatch(context, filter, getChildren(filter, context));
}
@Override
public RecordBatch visitStreamingAggregate(StreamingAggregate config, FragmentContext context)
throws ExecutionSetupException {
return abc.getBatch(context, config, getChildren(config, context));
}
@Override
public RecordBatch visitUnion(Union union, FragmentContext context) throws ExecutionSetupException {
return unionbc.getBatch(context, union, getChildren(union, context));
}
@Override
public RecordBatch visitSingleSender(SingleSender op, FragmentContext context) throws ExecutionSetupException {
root = ssc.getRoot(context, op, getChildren(op, context));
return null;
}
@Override
public RecordBatch visitRandomReceiver(RandomReceiver op, FragmentContext context) throws ExecutionSetupException {
return rrc.getBatch(context, op, null);
}
private List<RecordBatch> getChildren(PhysicalOperator op, FragmentContext context) throws ExecutionSetupException {
List<RecordBatch> children = Lists.newArrayList();
for (PhysicalOperator child : op) {
children.add(child.accept(this, context));
}
return children;
}
public static RootExec getExec(FragmentContext context, FragmentRoot root) throws ExecutionSetupException {
ImplCreator i = new ImplCreator();
root.accept(i, context);
if (i.root == null)
throw new ExecutionSetupException(
"The provided fragment did not have a root node that correctly created a RootExec value.");
return i.getRoot();
}
}