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.builtin;
Generates the maximum of a set of values. This class implements org.apache.pig.Algebraic, so if possible the execution will performed in a distributed fashion.

MAX can operate on any numeric type and on chararrays. It can also operate on bytearrays, which it will cast to doubles. It expects a bag of tuples of one record each. If Pig knows from the schema that this function will be passed a bag of integers or longs, it will use a specially adapted version of MAX that uses integer arithmetic for comparing the data. The return type of MAX will match the input type.

MAX implements the org.apache.pig.Accumulator interface as well. While this will never be the preferred method of usage it is available in case the combiner can not be used for a given calculation.

public class MAX extends AlgebraicByteArrayMathBase {
    public MAX() {
        setOp(.);
    }
    public static class Intermediate extends AlgebraicByteArrayMathBase.Intermediate {
        @Override
        public KNOWN_OP getOp() {
            return .;
            }
        }
    public static class Final extends AlgebraicByteArrayMathBase.Final {
        @Override
        public KNOWN_OP getOp() {
            return .;
        }
    }
    
    /* (non-Javadoc)
     * @see org.apache.pig.EvalFunc#getArgToFuncMapping()
     */
    @Override
    public List<FuncSpecgetArgToFuncMapping() throws FrontendException {
        List<FuncSpecfuncList = new ArrayList<FuncSpec>();
        funcList.add(new FuncSpec(this.getClass().getName(), Schema.generateNestedSchema(..)));
        funcList.add(new FuncSpec(DoubleMax.class.getName(), Schema.generateNestedSchema(..)));
        funcList.add(new FuncSpec(FloatMax.class.getName(), Schema.generateNestedSchema(..)));
        funcList.add(new FuncSpec(IntMax.class.getName(), Schema.generateNestedSchema(..)));
        funcList.add(new FuncSpec(LongMax.class.getName(), Schema.generateNestedSchema(..)));
        funcList.add(new FuncSpec(StringMax.class.getName(), Schema.generateNestedSchema(..)));
        funcList.add(new FuncSpec(DateTimeMax.class.getName(), Schema.generateNestedSchema(..)));
        return funcList;
    }
New to GrepCode? Check out our FAQ X