Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * 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.pig.newplan.logical.visitor;
This validator checks the correctness of use of scalar variables in logical operators. It assesses the validity of the expression by making sure there is no projection in it. Currently it works for Limit and Sample (see PIG-1926)
    public static final String ERR_MSG_SCALAR = "Expression in Limit/Sample should be scalar";
    public ScalarVariableValidator(OperatorPlan planthrows FrontendException {
        super(plannew DependencyOrderWalker(plan));
    }
    @Override
    public void visit(LOLimit limitthrows FrontendException {
        LogicalExpressionPlan expression = limit.getLimitPlan();
        if (expression != null) {
            ProjectFinder pf = new ProjectFinder(expression,
                    new ReverseDependencyOrderWalker(expression));
            pf.visit();
            if (pf.found()) {
                int errCode = 1131;
                throw new VisitorException(limiterrCode,
                        .);
            }
        }
    }
    @Override
    public void visit(LOFilter filterthrows FrontendException {
        LogicalExpressionPlan expression = filter.getFilterPlan();
        if (expression != null) {
            // if it is a Sample, the expression must be scalar
            if (filter.isSample()) {
                ProjectFinder pf = new ProjectFinder(expression,
                        new ReverseDependencyOrderWalker(expression));
                pf.visit();
                if (pf.found()) {
                    int errCode = 1131;
                    throw new VisitorException(filtererrCode,
                            .);
                }
            }
        }
    }
    public static class ProjectFinder extends LogicalExpressionVisitor {
        private boolean foundProject;
        public boolean found() {
            return ;
        }
        protected ProjectFinder(OperatorPlan pPlanWalker walker)
                throws FrontendException {
            super(pwalker);
        }
        @Override
        public void visit(ProjectExpression project) {
             = true;
        }
    }
New to GrepCode? Check out our FAQ X