我有两个表学生和员工具有相同的列作为位置我想在spark sql中编写一个查询来创建一个位置列的下拉列表,该列表应该包含来自两个表的记录。
答案 0 :(得分:0)
您应该分别从两个表中阅读location
列,然后使用union
合并它们。
val employees:DataFrame = ... //read from employees table
val students:DataFrame = ... //read from students table
val locations:DataFrame = employees.select("location").union(students.select("location")).dropDuplicates
从JDBC读取(取自spark documentation):
val jdbcDF = spark.read
.format("jdbc")
.option("url", "jdbc:postgresql:dbserver")
.option("dbtable", "schema.tablename")
.option("user", "username")
.option("password", "password")
.load()