0

Ok, so I am trying to run this piece of code:

%%spark

spark.sql(f'''select t2.ANOT_PDA_PRD
         ,t2.VLR_PDA_PRD AS MAX_VLR_PDA
         ,(CASE t1.cd_gr_mdld_prd_pd
                WHEN 7 THEN t3.DEF_B4
                WHEN 8 THEN t3.DEF_B4
                WHEN 9 THEN t3.DEF_B4
                WHEN 10 THEN t3.DEF_B5
                WHEN 11 THEN t3.DEF_B4
                WHEN 12 THEN t3.DEF_B5
                WHEN 13 THEN t3.DEF_B4
                WHEN 14 THEN t3.DEF_B4
                WHEN 15 THEN t3.DEF_B5
                WHEN 16 THEN t3.DEF_B4
                WHEN 17 THEN t3.DEF_B4
                WHEN 18 THEN t3.DEF_B4
                WHEN 22 THEN t3.DEF_B5
                ELSE 0 END) AS TMP_QUALI
          ,T3.ANOT_PDA_CLI
          from temp_vars_qlt as t1
          left join temp_vars_qlt as t2
          on t1.dt_mvtc = t2.dt_mvtc and t1.cd_cli = t2.cd_cli and T1.cd_gr_mdld_prd_pd=t2.cd_gr_mdld_prd_pd
          left join temp_vars_qlt as t3
          on t1.dt_mvtc = t3.dt_mvtc and t1.cd_cli = t3.cd_cli
          where t1.dt_mvtc between({data_inicial} , {data_final})
          ''').createOrReplaceTempView("temp_safras_qlt_aux")

But I got the following error:

SparkStatementException: "\nmismatched input 'from' expecting <EOF>(line 19, pos 14)\n\n== SQL 
==\nselect t2.ANOT_PDA_PRD\n             ,t2.VLR_PDA_PRD AS MAX_VLR_PDA\n             ,(CASE 
t1.cd_gr_mdld_prd_pd\n                    WHEN 7 THEN t3.DEF_B4\n                    WHEN 8 
THEN t3.DEF_B4\n  .................

whi A LOT of other lines, but altough is not readable entirely, I believe the important part is in the first line. But I do not know what "\nmismatched input 'from' expecting <EOF> was supposed to mean anyway.

So, the question is simple: what is wrong?

1 Answer 1

0

between syntax is BETWEEN 2 AND 5, try to change yours to between {data_inicial} and {data_final}

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I tried. It was this syntax before. But, in that case it gives cannot resolve t1.dt_mvtc >= ((2017 - 1) - 31) due to data type mismatch: differing types (date and int). But I double checked and { data_inicial} and {data_final} are strings, then I tried to change with to_date() but it still raises the same error
so that's something you have to fix, as you were saying t1.dt_mvtc is date, data_inicial and data_final are string, and the error you see is int?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.