【发布时间】:2017-11-06 11:34:58
【问题描述】:
我有一个场景,其中有两张表(csv)。为它创建了两个表。 当有一个好的数据时,我可以将它与第二个表中的值(id 统计值)映射。如果我有错误的数据,我应该再次将其映射到 id 统计值(但值不同)。但是,我无法在 spark SQL 中使用 not exists 。我得到以下错误:
不匹配的输入 'from' 期望 {、'WHERE'、'GROUP'、'ORDER'、'HAVING'、'LIMIT'、'LATERAL'、'WINDOW'、'UNION'、'EXCEPT'、'INTERSECT' , 'SORT', 'CLUSTER', 'DISTRIBUTE'}(第 1 行,位置 386)
at org.apache.spark.sql.catalyst.parser.ParseException.withCommand(ParseDriver.scala:197)
at org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parse(ParseDriver.scala:99)
at org.apache.spark.sql.execution.SparkSqlParser.parse(SparkSqlParser.scala:45)
代码:
select
a.ptf_id,a.ptf_code,a.share_id,a.share_code,a.bench_id,a.bench_code
, a.l1_calculation_date,a.l1_begin_date,a.l1_end_date,a.l1_running_date
, a.l1_frequency,a.l1_calculation_step,a.l1_performance_currency
, a.l1_configuration,a.l1_valuation_source,a.l1_nav_valuation_type
, a.l1_setting_reference_type, a.l1_setting_valuation_type
, a.l1_sharpe_ratio_annualized as value,b.id_statistic
from
parquetFile a,
pairRDD b,
stats c
where
a.l1_nav_valuation_type= b.l1_nav_valuation_type
and a.l1_valuation_source = b.l1_valuation_source
and b.l1_Perf = 'l1_sharpe_ratio_annualized'
OR (a.ptf_id not EXISTS (
select e.ptf_id from pairRDD d, parquetFile e
where d.l1_valuation_source = e.l1_valuation_source
AND d.l1_nav_valuation_type = e.l1_nav_valuation_type)
and b.l1_valuation_source ='')
如果我使用“NOT in”,此查询在 SQL 中有效 请帮助我了解在这种情况下使用的其他选项,而不是不存在。
【问题讨论】:
-
一种选择是使用外连接;坦率地说,您的查询有点难以阅读,但我想说您应该能够使用联接对其进行转换。祝你好运。
标签: java apache-spark