我想一次在控制台上显示多个数据框

时间:2019-08-23 07:09:27

标签: scala apache-spark

我试图返回数据框的列表或元组并显示它们,但是我无法显示它,所以有人可以帮忙

我尝试返回list(dataframes),然后在主目录中调用.show 方法

def dbReader():List[DataFrame]= {

val abcd_df_user = spark.read
  .format("jdbc")
  .option("url", "jdbc:postgresql://localhost/abcd?user=postgres&password=postgres")
  .option("dbtable", "User_Testing")
  .option("user", "postgres")
  .option("password", "postgres")
  .option("driver", "org.postgresql.Driver")
  .load()
  .createOrReplaceTempView("abcd_user_testing")

val user_Testing = spark.sql("""select * from abcd_user_testing""")
//.createOrReplaceTempView("All_User__Data")

val abcd_df_employee = spark.read
  .format("jdbc")
  .option("url", "jdbc:postgresql://localhost/abcd?user=postgres&password=postgres")
  .option("dbtable", "employee")
  .option("user", "postgres")
  .option("password", "postgres")
  .option("driver", "org.postgresql.Driver")
  .load()
  .createOrReplaceTempView("Employee_Table")

  val employee_df = spark.sql("""select emp_id,emp_name from Employee_Table""")

  List(employee_df,user_Testing)

}

主要方法:

object readinfromdbusingdf extends App {

  val readingfromdbusingdf=new readingfromdbusingdf()

  readingfromdbusingdf.dbReader().show(10)

预期结果:应该在控制台上同时显示两个数据框

0 个答案:

没有答案