scalaazure-synapseazure-synapse-analytics

Azure Synapse Analytics - output not displayed


Following Scala code in Azure Synapse should print: Hello, World!. But instead, it prints: defined object Geeks.

Question: What could be the issue and how can we fix it?

object Geeks { 

// Main method 
def main(args: Array[String]) 
{   
    // prints Hello, Geeks! 
    println("Hello, World!") 
} 
}

UPDATE:

I encounter the exact same issue when I run the above notebook in Databricks Community edition from Databricks company.


Solution

  • When you define an object with a main method in a notebook, the object is compiled and loaded into memory, but the main method is not automatically executed. To execute the main method, you need to call it explicitly outside of the object definition. Below is the way to call the main function inside the object,

    Geeks.main(Array())
    

    Here, I gave an empty array value as it doesnot have any impact for this code. You can pass the required arguments while calling different objects.