I was working on creating a function which takes in connection string, SQL query and connection properties as a arguments.
The First Scenario Works fine but the Second Scenario Fails with the error mentioned.
First Scenario Works:
val readSqlData = spark.read.jdbc(connectionString,_:String,connectionProps)
val data= readSqlData("(SELECT * FROM TestTable) as TestTable")
The above two lines give me a data value of type DataFrame.
Second Scenario :
Now I was trying to create a function that can be called from anywhere as a helper function so we don't have to pass connection String and connection Properties for each and every SQL statement that we create as below:
import org.apache.spark.sql.DataFrame
def PerformSqlOperations(): String => DataFrame = {
spark.read.jdbc(connectionString,_:String,connectionProps)
}
The function compiles properly, but, when I call this function by passing Sql Query to execute as below:
PerformSqlOperations("(SELECT * FROM TestTable) as TestTable")
Now I get the error too many arguments for method PerformSqlOperations()..
I am not able to understand why this is happening as the above code that works is similar to this and I was just trying to wrap that inside the function to make things simpler for multiple calls.
Any help or idea would be helpful in letting me know why the function creation and execution gives the error mentioned.