У меня возникают проблемы при выполнении UDF с geoip2 (maxmind) в качестве зависимости под Hive 2.3.4 (java 8), тот же код отлично работает в старых версиях hive, которые используют java 7, а также в Presto, которые используют java 8.
Я пытался использовать точные зависимости (maven) и ручную компиляцию, несколько версий улья, сокращая код и зависимости до минимума
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import com.maxmind.geoip2.record.City;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.model.CityResponse;
import com.maxmind.geoip2.exception.GeoIp2Exception;
public final class CityName extends UDF {
public String evaluate(String dbFile) throws IOException,GeoIp2Exception {
File database = new File(dbFile);
InetAddress ipAddress = InetAddress.getByName("127.0.0.1");
DatabaseReader reader = new DatabaseReader.Builder(database).build();
return "Database: "+dbFile.toString();
}
}
Сообщение об ошибке
2019-05-21T16:31:56,631 ERROR [ce3bca33-87aa-4468-b1ed-7080e95efb2d main([])]: ql.Driver (SessionState.java:printError(1126)) - FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments ''/root/GeoIP2-City.mmdb'': org.apache.hadoop.hive.ql.metadata.HiveException: Unable to execute method public java.lang.String com.example.hive.udf.CityName.evaluate(java.lang.String) throws java.io.IOException,com.maxmind.geoip2.exception.GeoIp2Exception,java.net.UnknownHostException with arguments {/root/GeoIP2-City.mmdb}:com.maxmind.geoip2.DatabaseReader.(Lcom/maxmind/geoip2/DatabaseReader$Builder;Lcom/maxmind/geoip2/DatabaseReader$1;)V
org.apache.hadoop.hive.ql.parse.SemanticException: Line 1:7 Wrong arguments ''/root/GeoIP2-City.mmdb'': org.apache.hadoop.hive.ql.metadata.HiveException: Unable to execute method public java.lang.String com.example.hive.udf.CityName.evaluate(java.lang.String) throws java.io.IOException,com.maxmind.geoip2.exception.GeoIp2Exception,java.net.UnknownHostException with arguments {/root/GeoIP2-City.mmdb}:com.maxmind.geoip2.DatabaseReader.(Lcom/maxmind/geoip2/DatabaseReader$Builder;Lcom/maxmind/geoip2/DatabaseReader$1;)V
at org.apache.hadoop.hive.ql.parse.TypeCheckProcFactory$DefaultExprProcessor.process(TypeCheckProcFactory.java:1367)
at org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher.dispatch(DefaultRuleDispatcher.java:90)
at org.apache.hadoop.hive.ql.lib.DefaultGraphWalker.dispatchAndReturn(DefaultGraphWalker.java:105)
.......
Caused by: java.lang.NoSuchMethodError: com.maxmind.geoip2.DatabaseReader.(Lcom/maxmind/geoip2/DatabaseReader$Builder;Lcom/maxmind/geoip2/DatabaseReader$1;)V
at com.maxmind.geoip2.DatabaseReader$Builder.build(DatabaseReader.java:160)
at com.example.hive.udf.CityName.evaluate(CityName.java:20)
... 47 more