我使用的是Spark 1.3,希望使用python接口(SparkSQL)连接多个列
以下工作:
我首先将它们注册为临时表。
numeric.registerTempTable("numeric")
Ref.registerTempTable("Ref")
test = numeric.join(Ref, numeric.ID == Ref.ID, joinType='inner')
我现在想基于多个列加入它们。
我得到SyntaxError
:以下语法无效:
test = numeric.join(Ref,
numeric.ID == Ref.ID AND numeric.TYPE == Ref.TYPE AND
numeric.STATUS == Ref.STATUS , joinType='inner')
您应该使用
&
/|
运算符,并注意operator precedence(==
的优先级低于按位AND
和OR
):另一种方法是:
哪些输出:
其主要优点是连接表的列在输出中不重复,从而降低了遇到诸如
org.apache.spark.sql.AnalysisException: Reference 'x1' is ambiguous, could be: x1#50L, x1#57L.
之类错误的风险每当两个表中的列具有不同的名称时(例如在上面的示例中,
df2
具有列y1
、y2
和y4
),可以使用以下语法:相关问题 更多 >
编程相关推荐