Parseexpection: No Viable Alternative at Input

Parseexpection: No Viable Alternative at Input

I was trying to run the below query in Azure data bricks.

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)

then I was getting the following error

ParseException:no viable alternative at input 'with pre_file_users AS (\n select id, \n typid, in case\n when dttm is null or dttm = '' then cast('1900-01-01 00:00:00.000 as timestamp)\n end as dttm\n from dde_pre_file_user_supp\n )'

Can I use WITH clause in data bricks or is there any alternative?

1

1 Answer

I have mentioned reasons that may cause ‘no viable alternative at input’ error:

  1. The ‘no viable alternative at input’ error message happens when we type a character that doesn’t fit in the context of that line.
  2. Also check if data type for some field may mismatch.

The ‘no viable alternative at input‘ error doesn’t mention which incorrect character we used.

Refer this answer by piotrwest

Also refer this article

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.