【问题标题】:ParseExpection: no viable alternative at inputParseExpection:输入时没有可行的替代方案
【发布时间】:2021-12-31 09:32:15
【问题描述】:

我试图在 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)

然后我收到以下错误

ParseException: 在输入 'with pre_file_users AS 时没有可行的替代方案 (\n select id, \n typid, in case\n 当 dttm 为 null 或 dttm = '' then cast('1900-01-01 00:00:00.000 as timestamp)\n end as dttm\n from dde_pre_file_user_supp\n)'

我可以在数据块中使用 WITH 子句还是有其他替代方法?

【问题讨论】:

  • 您只是在声明 CTE,但并未使用它。尝试在 cte 后添加select * from pre_file_user

标签: sql apache-spark pyspark apache-spark-sql azure-databricks


【解决方案1】:

我已经提到了可能导致“输入时没有可行的替代方案”错误的原因:

  1. 当我们键入的字符不适合该行的上下文时,会出现 “输入时没有可行的替代方案” 错误消息。
  2. 还要检查某些字段的数据类型是否可能不匹配。

“输入时没有可行的替代”错误没有提及我们使用了哪个错误字符。

参考thispiotrwest的回答

也可以参考这个article

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    相关资源
    最近更新 更多