输入')'不匹配,需要END

时间:2019-05-31 08:25:20

标签: apache-pig

我需要创建此猪脚本所示的DMS_EPRPFL实体:

DMS_EPRPFL = FOREACH ORDER_EPSE_ENEE_ENR  GENERATE

GROUP_EPSE_ENEE_ENR::IDT_GCP           AS    IDT_GCP,
GROUP_EPSE_ENEE_ENR::CD_FRM_JUR        AS    CD_FRM_JUR,
GROUP_EPSE_ENEE_ENR::DA_CRE_EPS        AS    DA_CRE_EPS,
GROUP_EPSE_ENEE_ENR::NO_SIREN           AS   NO_SIREN,
GROUP_EPSE_ENEE_ENR::CD_POST            AS   CD_POST,
GROUP_EPSE_ENEE_ENR::CD_OSCE_PAYS_FIS    AS  CD_OSCE_PAYS_FIS,
GROUP_EPSE_ENEE_ENR::CD_NAF              AS  CD_NAF,
GROUP_EPSE_ENEE_ENR::CD_NACE             AS  CD_NACE,
(CASE (GROUP_EPSE_ENEE_ENR::CD_AXE_MCH)
WHEN ('PLIB' OR 'ATPE' OR 'COMM') THEN 'P'
WHEN ('PME') THEN 'E'
WHEN ('AGRI') THEN 'A'
WHEN ('OBNL') THEN 'O'
WHEN ('COLL') THEN 'C'
WHEN ('EFIN') THEN 'B'
WHEN ('NONA' OR 'SCI') THEN 'X')               AS CD_MARCHE,
GROUP_EPSE_ENEE_ENR::CD_AXE_SNIV_MCH           AS CD_AXE_SNIV_MCH,
MIN(GROUP_EPSE_ENEE_ENR::A_PRM_CTR)            AS A_PRM_CTR,
MIN(GROUP_EPSE_ENEE_ENR::A_PRM_CAV)            AS A_PRM_CAV,
MIN(GROUP_EPSE_ENEE_ENR::A_PRPRE)              AS A_PRPRE,
GROUP_EPSE_ENEE_ENR::CD_NOT                    AS CD_NOT;

问题与CD_MARCHE有关。实际上,我需要根据特定条件并使用case运算符来生成它。

执行脚本时出现此错误:

  

输入')'不匹配,需要END

在此行

 WHEN ('NONA' OR 'SCI') THEN 'X')               AS CD_MARCHE,

我在那里找不到问题。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

来自 http://pig.apache.org/docs/latest/basic.html#arithmetic

CASE要么

CASE expression [ WHEN value THEN value ]+ [ ELSE value ]? END

OR

CASE [ WHEN condition THEN value ]+ [ ELSE value ]? END

在您的示例中,您使用的是前者但混合条件(A或B),其中它仅接受值。需要进行两项更改。

在case语句的末尾添加“ END”,并使用后面的CASE语句。

重写

(CASE (field)
    WHEN ( 'PLIB' OR 'ATPE' OR 'COMM' ) THEN 'P' 
    WHEN ('PME') THEN 'E'
    ...
    WHEN ('NONA' OR 'SCI') THEN 'X') AS CD_MARCHE,

(CASE 
    WHEN (field in ('PLIB','ATPE','COMM') ) THEN 'P' 
    WHEN (field == 'PME') THEN 'E'
    ...
    WHEN (field in ('NONA','SCI')) THEN 'X' END) AS CD_MARCHE,