/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PartitionConditionRemover.java
Java | 87 lines | 41 code | 13 blank | 33 comment | 1 complexity | 37ab913bbc14a23bd9d54097f4e8e51c MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
- /**
- * 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.hadoop.hive.ql.optimizer.pcr;
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.apache.hadoop.hive.ql.lib.DefaultGraphWalker;
- import org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher;
- import org.apache.hadoop.hive.ql.lib.Dispatcher;
- import org.apache.hadoop.hive.ql.lib.GraphWalker;
- import org.apache.hadoop.hive.ql.lib.Node;
- import org.apache.hadoop.hive.ql.lib.NodeProcessor;
- import org.apache.hadoop.hive.ql.lib.Rule;
- import org.apache.hadoop.hive.ql.lib.RuleRegExp;
- import org.apache.hadoop.hive.ql.optimizer.Transform;
- import org.apache.hadoop.hive.ql.parse.ParseContext;
- import org.apache.hadoop.hive.ql.parse.SemanticException;
- /**
- * The transformation step that does partition condition remover.
- *
- */
- public class PartitionConditionRemover implements Transform {
- // The log
- private static final Log LOG = LogFactory
- .getLog("hive.ql.optimizer.pcr.PartitionConditionRemover");
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.hadoop.hive.ql.optimizer.Transform#transform(org.apache.hadoop
- * .hive.ql.parse.ParseContext)
- */
- @Override
- public ParseContext transform(ParseContext pctx) throws SemanticException {
- // create a the context for walking operators
- List<PcrOpWalkerCtx.OpToDeleteInfo> opToRemove =
- new ArrayList<PcrOpWalkerCtx.OpToDeleteInfo>();
- PcrOpWalkerCtx opWalkerCtx = new PcrOpWalkerCtx(pctx, opToRemove);
- Map<Rule, NodeProcessor> opRules = new LinkedHashMap<Rule, NodeProcessor>();
- opRules.put(new RuleRegExp("R1", "(TS%FIL%)|(TS%FIL%FIL%)"), PcrOpProcFactory
- .getFilterProc());
- // The dispatcher fires the processor corresponding to the closest matching
- // rule and passes the context along
- Dispatcher disp = new DefaultRuleDispatcher(PcrOpProcFactory.getDefaultProc(),
- opRules, opWalkerCtx);
- GraphWalker ogw = new DefaultGraphWalker(disp);
- // Create a list of topop nodes
- ArrayList<Node> topNodes = new ArrayList<Node>();
- topNodes.addAll(pctx.getTopOps().values());
- ogw.startWalking(topNodes, null);
- for (PcrOpWalkerCtx.OpToDeleteInfo entry : opToRemove) {
- entry.getParent().removeChildAndAdoptItsChildren(entry.getOperator());
- }
- return pctx;
- }
- }