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.rules;
public class OptimizerUtils {
    
Find generate op from the foreach operator.

Parameters:
foreach the LOForEach instance
Returns:
LOGenerate instance
    public static LOGenerate findGenerate(LOForEach foreach) {
        LogicalPlan inner = foreach.getInnerPlan();
        return (LOGenerate)inner.getSinks().get(0);
    }

    
Check if a given LOGenerate operator has any flatten fields.

Parameters:
gen the given LOGenerate instance
Returns:
true if LOGenerate instance contains flatten fields, false otherwise
    public static boolean hasFlatten(LOGenerate gen) {
        boolean hasFlatten = false;
        boolean[] flattenFlags = gen.getFlattenFlags();
        ifflattenFlags != null ) {
            forboolean flatten : flattenFlags ) {
                ifflatten ) {
                    hasFlatten = true;
                    break;
                }
            }
        }
        return hasFlatten;
    }

    
Helper method to find if a given LOForEach instance contains any flatten fields.

Parameters:
foreach foreach the LOForEach instance
Returns:
true if LOForEach instance contains flatten fields, false otherwise
    public static boolean hasFlatten(LOForEach foreach) {
        LOGenerate gen = findGenerateforeach );
        return hasFlattengen );
    }

    
Helper method to determine if the logical expression plan for a Filter contains non-deterministic operations and should therefore be treated extra carefully during optimization.

Parameters:
filterPlan
Returns:
true of the filter plan contains a non-deterministic UDF
Throws:
org.apache.pig.impl.logicalLayer.FrontendException
    public static boolean planHasNonDeterministicUdf(LogicalExpressionPlan filterPlan)
    throws FrontendException {
        Iterator<Operatorit = filterPlan.getOperators();
        whileit.hasNext() ) {
            Operator op = it.next();
            ifop instanceof UserFuncExpression ) {
                if(! ((UserFuncExpression)op).isDeterministic() ){
                    return true;
                }
            }
        }
        return false;
    }
New to GrepCode? Check out our FAQ X