【发布时间】:2017-03-18 05:02:03
【问题描述】:
我正在尝试在 spark (1.6.2) 中进行左外连接,但它不起作用。我的sql查询是这样的:
sqlContext.sql("select t.type, t.uuid, p.uuid
from symptom_type t LEFT JOIN plugin p
ON t.uuid = p.uuid
where t.created_year = 2016
and p.created_year = 2016").show()
结果是这样的:
+--------------------+--------------------+--------------------+
| type| uuid| uuid|
+--------------------+--------------------+--------------------+
| tained|89759dcc-50c0-490...|89759dcc-50c0-490...|
| swapper|740cd0d4-53ee-438...|740cd0d4-53ee-438...|
我使用 LEFT JOIN 或 LEFT OUTER JOIN 得到了相同的结果(第二个 uuid 不为空)。
我希望第二个 uuid 列仅为 null。如何正确进行左外连接?
=== 附加信息 ==
如果我使用数据框进行左外连接,我得到了正确的结果。
s = sqlCtx.sql('select * from symptom_type where created_year = 2016')
p = sqlCtx.sql('select * from plugin where created_year = 2016')
s.join(p, s.uuid == p.uuid, 'left_outer')
.select(s.type, s.uuid.alias('s_uuid'),
p.uuid.alias('p_uuid'), s.created_date, p.created_year, p.created_month).show()
我得到这样的结果:
+-------------------+--------------------+-----------------+--------------------+------------+-------------+
| type| s_uuid| p_uuid| created_date|created_year|created_month|
+-------------------+--------------------+-----------------+--------------------+------------+-------------+
| tained|6d688688-96a4-341...| null|2016-01-28 00:27:...| null| null|
| tained|6d688688-96a4-341...| null|2016-01-28 00:27:...| null| null|
| tained|6d688688-96a4-341...| null|2016-01-28 00:27:...| null| null|
谢谢,
【问题讨论】:
标签: apache-spark pyspark apache-spark-sql