Skip to content
Advertisement

Load the ResultSet of query in dataframe using Spark / java

I want to load the Result Set of a select query in dataframe Spark.

I’m using the following code :

There is any posibility to load the ResultSet in a dataframe ?

I need your help

Thank you .

Advertisement

Answer

If I understand your question correctly, you want to load a SQL table in a data frame. To do that, you need to do the following things:

  1. Create an object of sparkSession.
  2. Put your JDBC connection in a Properties object.
  3. Load the SQL table by the read method.
  4. You can apply your relevant filter based on the loaded data frame.

Please find below the code as a sample to do so.

You can apply any kind of operation like a filter, select, or any other SQL operation on these dataframe.

I am running this code in my local system. I have added the comment in the code so that you can understand it easily. Do let me know if you have any doubt.

I hope this should give you a fair idea about how to begin loading the SQL table as dataframe.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement