Gustav Elmgren
08/26/2022, 8:30 AMfun distanceInKm(lat1: Column<Double>, long1: Column<Double>, lat2: Column<Double>, long2: Column<Double>) =
Expression.build {
ACos(
Sin(
(doubleLiteral(PI) * lat1 / doubleLiteral(180.0))
) *
Sin(doubleLiteral(PI) * lat2 / doubleLiteral(180.0))
+
Cos(doubleLiteral(PI) * lat1 / doubleLiteral(180.0)) *
Cos(doubleLiteral(PI) * lat2 / doubleLiteral(180.0)) *
Cos(doubleLiteral(PI) * (long1 - long2) / doubleLiteral(180.0))
).times(
doubleLiteral(180.0) / doubleLiteral(PI) * doubleLiteral(60.0) * doubleLiteral(1.1515) * doubleLiteral(
1.609344
)
)
}
But I just realized that two of the columns are nullable (lat2
, long2
), which breaks the method. Is there anything like !!
in exposed? Given I know the values are not null because of my where
.Gustav Elmgren
08/26/2022, 8:32 AMval distance = distanceInKm(
entityA.lat,
entityA.long,
entityB.lat, <--- Nullable
entityB.long <--- Nullable
)
Gustav Elmgren
08/26/2022, 8:34 AMval distanceRounded = RoundNumeric(distance, 1).alias("distanceRounded")
....
.slice(distanceRounded, entityB.id.countDistinct())
.select {
(entityB.lat.isNotNull()) and (entityB.long.isNotNull()) and ...
}
Gustav Elmgren
08/26/2022, 8:44 AMparameter
to ExpressionWithColumnType
and then cast entityB.lat
?