ParseExpection:输入时没有可行的替代方案

ven*_*at 4 sql apache-spark apache-spark-sql pyspark azure-databricks

我试图在 Azure 数据块中运行以下查询。

query=s"""WITH pre_file_user AS(
            SELECT id,
            typeid,
          CASE when dttm is null or dttm='' then cast('1900-01-01 00:00:00.000' as timestamp)
          else cast(dttm as timestamp)
          end as dttm
          from dde_pre_file_user_supp
)"""

spark.sql(query)
Run Code Online (Sandbox Code Playgroud)

然后我收到以下错误

ParseException:在输入“with pre_file_users AS”时没有可行的替代方案(\n选择id,\n typepid,以防\n当dttm为空或dttm =''然后强制转换('1900-01-01 00:00:00.000作为时间戳)\n 以 dttm\n 结尾,来自 dde_pre_file_user_supp\n )'

我可以在数据块中使用WITH子句吗还是有其他选择吗?

小智 6

我已经提到了可能导致\xe2\x80\x98no 可行替代方案 at input\xe2\x80\x99 错误的原因:

\n
    \n
  1. 当我们键入不适合该行上下文的字符时,就会出现 \xe2\x80\x98no Vivaal Alternative at input\xe2\x80\x99 错误消息
  2. \n
  3. 还要检查某些字段的数据类型是否可能不匹配。
  4. \n
\n

输入 \xe2\x80\x98 错误中的 \xe2\x80\x98no 可行替代方案\ xe2\x80\x99 没有提及我们使用了哪个不正确的字符。

\n

参考piotrwest的这个答案

\n

另请参考这篇文章

\n