Java tutorial
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; //pass in cidr address and return binary lowest ip in range public final class getLowestIP extends UDF { public Text evaluate(Text inputaddr) throws UnknownHostException { String low_ip; Text ip_out; SubnetUtils utils = new SubnetUtils(inputaddr.toString()); low_ip = utils.getInfo().getLowAddress(); ip_out = new Text(low_ip); return ip_out; } }