【问题标题】:Getting pyspark.sql.utils.ParseException: missing ')' at 'in' in pyspark sql获取 pyspark.sql.utils.ParseException: 在 pyspark sql 的“in”处缺少“)”
【发布时间】:2021-12-23 15:52:12
【问题描述】:

您好,我在 pyspark sql 上运行以下查询,但出现错误。请帮助我在哪里缺少')'。

查询-

`with cte1 as (select `Project Number`, indication,rank() over (partition by `Project Number`,REGEXP_REPLACE(indication,'[^a-zA-Z0-9]+', '') order by `Project Number`,indication) as rnk from (select distinct `Project Number`, indication from vw_onco_pharma onco_pharma union select distinct `Project Number`, indication from vw_onco_cell_gene cell_gene union select distinct `Project Number`, indication from vw_non_onco_cell_gene onco_cell_gene union select distinct `Project Number`, indication from vw_non_onco_pharma non_onco_pharma union select distinct `Project Number`, indication from vw_plasma_protein plasma_protein)),y as (select max(cast(project_id as integer)) as max_prj_id from vw_project_id) select nvl(max_prj_id,0)+ROW_NUMBER () OVER (ORDER BY `Project Number`,indication) as project_id,`Project Number`,indication,date_format(current_timestamp(),'yyyy-MM-dd hh:mm:ss') as HTA_INSERT_DT from (select cte1.`Project Number`, cte1.indication,max_prj_id from cte1 left join vw_project_id prj on cte1.`Project Number` = prj.`Project Number` and REGEXP_REPLACE(cte1.indicatio,'[^a-zA-Z0-9]+', '') = REGEXP_REPLACE(prj.indication,'[^a-zA-Z0-9]+', '') left join  y on 1 = 1 where rnk = 1 and prj.project_id is null and cte1.`project number` in (select `project number` from cte1 group by `project number` having count(*) > 1) union select cte1.`Project Number`, null as indication,max_prj_id from cte1 left join vw_project_id prj on cte1.`Project Number` = prj.`Project Number` left join y on 1 = 1 where rnk = 1 and prj.project_id is null and cte1.`project number` in (select `project number` from cte1 groupby `project number` having count(*) = 1))`

错误-

pyspark.sql.utils.ParseException:
missing ')' at 'in'(line 1, pos 1575)

【问题讨论】:

    标签: pyspark apache-spark-sql


    【解决方案1】:

    最后一个groupby 应该是group by

    还可以尝试格式化您的查询,使其可读:

    with cte1 as (
      select
        ` Project Number `,
        indication,
        rank() over (
          partition by ` Project Number `,
          REGEXP_REPLACE(indication, '[^a-zA-Z0-9]+', '')
          order by
            ` Project Number `,
            indication
        ) as rnk
      from
        (
          select
            distinct ` Project Number `,
            indication
          from
            vw_onco_pharma onco_pharma
          union
          select
            distinct ` Project Number `,
            indication
          from
            vw_onco_cell_gene cell_gene
          union
          select
            distinct ` Project Number `,
            indication
          from
            vw_non_onco_cell_gene onco_cell_gene
          union
          select
            distinct ` Project Number `,
            indication
          from
            vw_non_onco_pharma non_onco_pharma
          union
          select
            distinct ` Project Number `,
            indication
          from
            vw_plasma_protein plasma_protein
        )
    ),
    y as (
      select
        max(cast(project_id as integer)) as max_prj_id
      from
        vw_project_id
    )
    select
      nvl(max_prj_id, 0) + ROW_NUMBER () OVER (
        ORDER BY
          ` Project Number `,
          indication
      ) as project_id,
      ` Project Number `,
      indication,
      date_format(current_timestamp(), 'yyyy-MM-dd hh:mm:ss') as HTA_INSERT_DT
    from
      (
        select
          cte1.` Project Number `,
          cte1.indication,
          max_prj_id
        from
          cte1
          left join vw_project_id prj on cte1.` Project Number ` = prj.` Project Number `
          and REGEXP_REPLACE(cte1.indicatio, '[^a-zA-Z0-9]+', '') = REGEXP_REPLACE(prj.indication, '[^a-zA-Z0-9]+', '')
          left join y on 1 = 1
        where
          rnk = 1
          and prj.project_id is null
          and cte1.` project number ` in (
            select
              ` project number `
            from
              cte1
            group by
              ` project number `
            having
              count(*) > 1
          )
        union
        select
          cte1.` Project Number `,
          null as indication,
          max_prj_id
        from
          cte1
          left join vw_project_id prj on cte1.` Project Number ` = prj.` Project Number `
          left join y on 1 = 1
        where
          rnk = 1
          and prj.project_id is null
          and cte1.` project number ` in (
            select
              ` project number `
            from
              cte1 group by ` project number `
            having
              count(*) = 1
          )
      )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 2012-08-05
      • 1970-01-01
      相关资源
      最近更新 更多