Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.tajo.plan.rewrite.rules;
import org.apache.tajo.exception.TajoException;
import org.apache.tajo.plan.LogicalPlan;
import org.apache.tajo.plan.expr.*;
import org.apache.tajo.plan.logical.JoinNode;
import org.apache.tajo.plan.logical.LogicalNode;
import org.apache.tajo.plan.logical.NodeType;
import org.apache.tajo.plan.logical.SelectionNode;
import org.apache.tajo.plan.rewrite.LogicalPlanRewriteRule;
import org.apache.tajo.plan.rewrite.LogicalPlanRewriteRuleContext;
import org.apache.tajo.plan.visitor.BasicLogicalPlanVisitor;
import org.apache.tajo.util.TUtil;
import java.util.Set;
import java.util.Stack;
/**
* Condition reduce rule reduces the query predicate based on distributivity.
* For example, the query
*
* SELECT *
* FROM t
* WHERE (t.a = 1 OR t.b = 10) AND (t.a = 1 OR t.c = 100)
*
* is converted into
*
* SELECT *
* FROM t
* WHERE t.a = 1 OR (t.b = 10 AND t.c = 100).
*
*/
public class CommonConditionReduceRule implements LogicalPlanRewriteRule {
private Rewriter rewriter;
@Override
public String getName() {
return "CommonConditionReduceRule";
}
@Override
public boolean isEligible(LogicalPlanRewriteRuleContext context) {
for (LogicalPlan.QueryBlock block : context.getPlan().getQueryBlocks()) {
if (block.hasNode(NodeType.SELECTION) || block.hasNode(NodeType.JOIN)) {
rewriter = new Rewriter(context.getPlan());
return true;
}
}
return false;
}
@Override
public LogicalPlan rewrite(LogicalPlanRewriteRuleContext context) throws TajoException {
rewriter.visit(null, context.getPlan(), context.getPlan().getRootBlock());
return context.getPlan();
}
/**
* Rewriter simply triggers rewriting evals while visiting logical nodes.
*/
private final static class Rewriter extends BasicLogicalPlanVisitor