【发布时间】:2016-10-31 07:33:55
【问题描述】:
我现在正在将 sql server 查询转换为 spark。我在转换给定查询时遇到问题
and not exists (Select 1 from @TT t2 where t2.TID = f.ID)
我已经研究过了,并且了解到 spark 不支持“不存在”命令 我用过 except 但错误是
pyspark.sql.utils.AnalysisException: u'Except can only be performed on tables with the same number of columns, but the left table has 7 columns and the right has 31;'
我也尝试过内连接操作 所以除了不适用于不均匀的表列数。什么将是火花中此查询的兼容替代查询请帮助我 我正在使用 pyspark 2.0
【问题讨论】:
-
请提供示例数据和预期输出,以便重现您的问题。
-
spark.sql("选择 f.id 作为 TID,f.BldgID 作为 TBldgID,f.LeaseID 作为 TLeaseID,f.Period 作为 TPeriod,f.ChargeAmt 作为 TChargeAmt1,0 作为 TChargeAmt2,l. EXPIR as TBreakDate from Fact_CMCharges f join LEAS l on l.BLDGID = f.BldgID and l.LEASID = f.LeaseID and date_format(date_add(l.EXPIR,1),'D')1 and f.Period=Expirvalue (l.EXPIR) and (l.VACATE is null or l.VACATE >('select RunDate from RunDate')) where f.ActualProjected='Lease' except("Select 1 from TT t2 where t2.TID = f.ID ")").show() 这是我的代码,虽然它很乱。我使用了 except 命令来期待关于上述问题的结果
-
请为您的问题提供最少的数据集和预期输出,而不是复制粘贴不相关的代码到 cmets。
-
幸运的是我已经解决了我的问题。感谢您的回复:) 波纹管部分已经完成了“....except(select * from TT1 t2 left semi join Fact_CMCharges f2 on t2.TID=f2.ID).....”
标签: apache-spark pyspark apache-spark-sql pyspark-sql