From ad51c464329d0fb7d9cf6ce9ecb5d565049c7b6c Mon Sep 17 00:00:00 2001 From: Fabiano Francesconi Date: Mon, 17 Feb 2020 22:29:40 +0100 Subject: [PATCH] Using UDFs in Java --- .../main/scala/net/teralytics/terahex/TeraHex.scala | 7 ------- .../scala/net/teralytics/terahex/TeraHexSpark.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 jvm/src/main/scala/net/teralytics/terahex/TeraHexSpark.java diff --git a/jvm/src/main/scala/net/teralytics/terahex/TeraHex.scala b/jvm/src/main/scala/net/teralytics/terahex/TeraHex.scala index 09bf857..e038ec8 100644 --- a/jvm/src/main/scala/net/teralytics/terahex/TeraHex.scala +++ b/jvm/src/main/scala/net/teralytics/terahex/TeraHex.scala @@ -15,11 +15,4 @@ object TeraHex { def decode(code: Long): Zone = encoding.decode(code) def size(level: Int): Double = grid.size(level) -} - -object TeraHexSparkUDF extends UDF3[Double, Double, Integer, Long] { - - override def call(longitude: Double, latitude: Double, level: Integer): Long = { - TeraHex.encode(LatLon(Lon(longitude), Lat(latitude)), level) - } } \ No newline at end of file diff --git a/jvm/src/main/scala/net/teralytics/terahex/TeraHexSpark.java b/jvm/src/main/scala/net/teralytics/terahex/TeraHexSpark.java new file mode 100644 index 0000000..401632d --- /dev/null +++ b/jvm/src/main/scala/net/teralytics/terahex/TeraHexSpark.java @@ -0,0 +1,11 @@ +package net.teralytics.terahex; + +import org.apache.spark.sql.api.java.UDF3; + +public class TeraHexSpark implements UDF3 { + @Override + public Long call(Double longitude, Double latitude, Integer level) throws Exception { + return TeraHex.encode(new LatLon(longitude, latitude), level); + } +} +