Skip to content

Commit

Permalink
Merge pull request #31 from teralytics/spark-sql-udf
Browse files Browse the repository at this point in the history
Added UDF
  • Loading branch information
franzhcs authored Feb 17, 2020
2 parents 1085ad0 + 8b83471 commit 107bf65
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions jvm/src/main/scala/net/teralytics/terahex/TeraHex.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.teralytics.terahex

import org.apache.spark.sql.api.java.UDF3

object TeraHex {

Expand All @@ -16,9 +17,9 @@ object TeraHex {
def size(level: Int): Double = grid.size(level)
}

object TeraHexSpark {
import org.apache.spark.sql.expressions.UserDefinedFunction
import org.apache.spark.sql.functions.udf
object TeraHexSparkUDF extends UDF3[Double, Double, Integer, Long] {

def getUdf(level: Int): UserDefinedFunction = udf((lat: Double, lon: Double) => TeraHex.encode(LatLon(Lon(lon),Lat(lat)), level))
override def call(longitude: Double, latitude: Double, level: Integer): Long = {
TeraHex.encode(LatLon(Lon(longitude), Lat(latitude)), level)
}
}

0 comments on commit 107bf65

Please sign in to comment.