首页 > 解决方案 > 得到这个错误:不匹配的输入'来自'期待而 Spark SQL

问题描述

运行 Spark SQL 时,mismatched input 'from' expecting <EOF>出现错误。

我检查了可能发生但没有发现的常见语法错误。

val prevPartitionDate = spark.sql(
"select to_date(concat(year_p,'-',month_p,'-',day_p)) 
from ips.command_room_table 
where 
to_date(concat(year_p,'-',month_p,'-',day_p)) < to_date(concat($yearAsInt,'-',$monthAsInt,'-',$dayAsInt)) 
group by year_p, month_p, day_p 
order by to_date(concat(year_p,'-',month_p,'-',day_p)) desc limit 1"
).first.getDate(0)

我能做些什么来解决这个问题?

标签: apache-sparkapache-spark-sql

解决方案


不用担心,能够弄清楚问题。当我在查询中使用变量时,我只需在查询的开头添加“s”,如下所示:

val prevPartitionDate = spark.sql(s
"select to_date(concat(year_p,'-',month_p,'-',day_p)) 
from ips.command_room_table 
where 
to_date(concat(year_p,'-',month_p,'-',day_p)) < to_date(concat($yearAsInt,'-',$monthAsInt,'-',$dayAsInt)) 
group by year_p, month_p, day_p 
order by to_date(concat(year_p,'-',month_p,'-',day_p)) desc limit 1"
).first.getDate(0)

推荐阅读