com.unisa.hive.udf.getHighestIP.java Source code

Java tutorial

Introduction

Here is the source code for com.unisa.hive.udf.getHighestIP.java

Source

package com.unisa.hive.udf;

/**
 * This file is part of UniSAHadoop.
 * 
 *     UniSAHadoop is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by  
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     UniSAHadoop is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with UniSAHadoop.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.net.UnknownHostException;

import org.apache.commons.net.util.SubnetUtils;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

public final class getHighestIP extends UDF {
    public Text evaluate(Text inputaddr) throws UnknownHostException {

        String high_ip;
        Text ip_out;

        SubnetUtils utils = new SubnetUtils(inputaddr.toString());
        high_ip = utils.getInfo().getHighAddress();

        ip_out = new Text(high_ip);

        return ip_out;
    }
}

//pass in cidr address and return binary highest ip in range