I am trying to call one of the utility functions, but unable to return value to the caller, but somehow I am not able to return the response to the caller; i.e the main function. What could be the issue?
I tried reassigning the response to a local variable and returning that; but did not work
// main function
def main(args: Array[String]): Unit = {
val res = fetchFromDruid()
// res comes as null here
}
def fetchFromDruid(): GroupByResponse {
// creating an execution context
// creating a local druid client
// constructing a group by query
// executing the query
client(query).onComplete {
//this will be executed if data is fetched successfully
case Success(response) =>
return response
//this will be executed if there is an exception
case Failure(ex) =>
ex.printStackTrace()
return null
}
}
Expected: The main method (caller) should get the response
Actual: The caller does not get the response after the callback returns