Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Read sql table name from user input using scala

Read sql table name from user input using scala

Rising Star

I need my scala script to read the table name from user and load it .

Can I know how ?

val x = sqlContext.read.format("jdbc").option("driver","oracle.jdbc.driver.OracleDriver").option("url","jdbc:oracle:......").option("dbtable", "my_table").load();
1 REPLY 1

Re: Read sql table name from user input using scala

@Dinesh Das

Where is the table name coming from? In your case, is the user able to specify this (either manually or through code) when the job is submitted? If so, you can have the user specify the table name (and any other parameters) as a command line argument, such as:

./bin/spark-submit --class classname project.jar your_table_name

Reference this within your scala code to read in your argument(s):

val my_table = args(0)
Don't have an account?
Coming from Hortonworks? Activate your account here