将查询从Sybase IQ转换为impala

问题描述 投票:0回答:1
SELECT f.exch 
FROM   ( 
              SELECT 
                     CASE 
                            WHEN sourcedesk IN ('GOBUS_NY', 
                                                'GOBUS_UK', 
                                                'PETRDAES', 
                                                'PEETRAD') THEN clientid 
                            WHEN sourcedesk = 'AESLDN' 
                            AND    clientid != '' THEN clientid 
                            ELSE owner 
                     END                               AS aclient, 
                     clientid                          AS client, 
                     orderid                           AS gaotag, 
                     exchange                          AS exch, 
                     side                              AS side, 
                     securityid                        AS sym, 
                     cumulativequantity*executionprice AS value, 
                     cumulativequantity                AS qdone, 
                     fillid                            AS gaftag, 
                     executionexchangetimestamplcl     AS xstamp, 
                     executionprice                    AS lprice, 
                     executionexchangeid               AS xftag, 
                     serverid                          AS srvid, 
                     reasoncode                        AS rescode, 
                     rootfillid                        AS rgaftag, 
                     miccode                           AS miccode, 
                     mifidtradeflags                   AS mifidtradeflags, 
                     sourcedesk                        AS desk 
              FROM   fillsastextdatestring 
              WHERE  agoralocaltradedate = '190205' 
              AND    exchange = 'VEX' 
              AND    sourceservicename LIKE 'vexprod%' 
              AND    securityid LIKE '%.%' 
              UNION ALL 
              SELECT 
                     CASE 
                            WHEN sourcedesk IN ('GOBUS_NY', 
                                                'GOBUS_UK', 
                                                'PETRDAES', 
                                                'PEETRAD', 
                                                'VEXSVC', 
                                                'LLSOR') THEN clientid 
                            WHEN sourcedesk = 'AESLDN' 
                            AND    clientid != '' THEN clientid 
                            ELSE owner 
                     END                               AS aclient, 
                     clientid                          AS client, 
                     orderid                           AS gaotag, 
                     exchange                          AS exch, 
                     side                              AS side, 
                     securityid                        AS sym, 
                     cumulativequantity*executionprice AS value, 
                     cumulativequantity                AS qdone, 
                     fillid                            AS gaftag, 
                     executionexchangetimestamplcl     AS xstamp, 
                     executionprice                    AS lprice, 
                     executionexchangeid               AS xftag, 
                     serverid                          AS srvid, 
                     reasoncode                        AS rescode, 
                     rootfillid                        AS rgaftag, 
                     miccode                           AS miccode, 
                     mifidtradeflags                   AS mifidtradeflags, 
                     sourcedesk                        AS desk 
              FROM   fillsastextdatestring 
              WHERE  agoralocaltradedate = '190205' 
              AND    sourceservicename IN ('SORUK', 
                                           'PRODSorBkFlr', 
                                           'PRODFixBkFlr', 
                                           'PRODFixBkFlr1', 
                                           'PRODFixBkFlr2', 
                                           'PRODSmgBkFlr', 
                                           'ECGaia2Agora') 
              AND    owner NOT LIKE 'tree%' 
              AND    securityid LIKE '%.%' 
              UNION ALL 
              SELECT 
                     CASE 
                            WHEN sourcedesk IN ('GOBUS_NY', 
                                                'GOBUS_UK', 
                                                'PETRDAES', 
                                                'PEETRAD', 
                                                'VEXSVC', 
                                                'LLSOR') THEN clientid 
                            WHEN sourcedesk = 'AESLDN' 
                            AND    clientid != '' THEN clientid 
                            ELSE owner 
                     END                               AS aclient, 
                     clientid                          AS client, 
                     orderid                           AS gaotag, 
                     exchange                          AS exch, 
                     side                              AS side, 
                     securityid                        AS sym, 
                     cumulativequantity*executionprice AS value, 
                     cumulativequantity                AS qdone, 
                     fillid                            AS gaftag, 
                     executionexchangetimestamplcl     AS xstamp, 
                     executionprice                    AS lprice, 
                     executionexchangeid               AS xftag, 
                     serverid                          AS srvid, 
                     reasoncode                        AS rescode, 
                     rootfillid                        AS rgaftag, 
                     miccode                           AS miccode, 
                     mifidtradeflags                   AS mifidtradeflags, 
                     sourcedesk                        AS desk 
              FROM   fillsastextdatestring 
              WHERE  agoralocaltradedate = '190205' 
              AND    securityid LIKE '%.%' 
              AND    exchange = 'BENCHMKX' 
              AND    sourceservicename LIKE 'BENCHM_%' 
              UNION ALL 
              SELECT 
                     CASE 
                            WHEN sourcedesk IN ('GOBUS_NY', 
                                                'GOBUS_UK', 
                                                'PETRDAES', 
                                                'PEETRAD', 
                                                'VEXSVC', 
                                                'LLSOR') THEN clientid 
                            WHEN sourcedesk = 'AESLDN' 
                            AND    clientid != '' THEN clientid 
                            ELSE owner 
                     END                               AS aclient, 
                     clientid                          AS client, 
                     orderid                           AS gaotag, 
                     exchange                          AS exch, 
                     side                              AS side, 
                     securityid                        AS sym, 
                     cumulativequantity*executionprice AS value, 
                     cumulativequantity                AS qdone, 
                     fillid                            AS gaftag, 
                     executionexchangetimestamplcl     AS xstamp, 
                     executionprice                    AS lprice, 
                     executionexchangeid               AS xftag, 
                     serverid                          AS srvid, 
                     reasoncode                        AS rescode, 
                     rootfillid                        AS rgaftag, 
                     miccode                           AS miccode, 
                     mifidtradeflags                   AS mifidtradeflags, 
                     sourcedesk                        AS desk 
              FROM   fillsastextdatestring 
              WHERE  agoralocaltradedate = '190205' 
              AND    sourceservicename = 'ECGaia2Agora' 
              AND    owner NOT LIKE 'tree%' 
              AND    exchange IN ('BATS', 
                                  'CHIX') 
              AND    reasoncode = 'NT' 
              AND    side = 'B' 
              UNION ALL 
              SELECT 
                     CASE 
                            WHEN sourcedesk IN ('GOBUS_NY', 
                                                'GOBUS_UK', 
                                                'PETRDAES', 
                                                'PEETRAD', 
                                                'VEXSVC', 
                                                'LLSOR') THEN clientid 
                            WHEN sourcedesk = 'AESLDN' 
                            AND    clientid != '' THEN clientid 
                            ELSE owner 
                     END                               AS aclient, 
                     clientid                          AS client, 
                     orderid                           AS gaotag, 
                     exchange                          AS exch, 
                     side                              AS side, 
                     securityid                        AS sym, 
                     cumulativequantity*executionprice AS value, 
                     cumulativequantity                AS qdone, 
                     fillid                            AS gaftag, 
                     executionexchangetimestamplcl     AS xstamp, 
                     executionprice                    AS lprice, 
                     executionexchangeid               AS xftag, 
                     serverid                          AS srvid, 
                     reasoncode                        AS rescode, 
                     rootfillid                        AS rgaftag, 
                     miccode                           AS miccode, 
                     mifidtradeflags                   AS mifidtradeflags, 
                     sourcedesk                        AS desk 
              FROM   fillsastextdatestring 
              WHERE  agoralocaltradedate = '190205' 
              AND    sourceservicename LIKE 'tars_%' ) AS f, 
       ( 
              SELECT orderid             AS gaotag, 
                     serverid            AS srvid, 
                     securityidasentered AS enteredsym, 
                     securityid          AS sym, 
                     rootorderid         AS rgaotag, 
                     timeinforce         AS tif, 
                     settletype          AS settletype, 
                     sourceservicename   AS appl, 
                     account             AS acct 
              FROM   ordersastextdatestring 
              WHERE  agoralocaltradedate = '190205' 
              AND    destinationdesk IN ('BENCHX', 
                                         'VEXSVC', 
                                         'SORMKT', 
                                         'MAIA', 
                                         'LLSOR', 
                                         'TARSSVC')) AS o, 
where  f.gaotag = o.gaotag

上面的查询失败,impala中出现以下错误:

AnalysisException:第4行中的语法错误:undefined:其中f.gaotag = o.gaotag ^遇到:WHERE预期:DEFAULT,IDENTIFIER CAUSED BY:异常:语法错误

我通过以下cloudera链接:https://www.cloudera.com/documentation/enterprise/5-4-x/topics/impala_subqueries.html但无法使这项工作。

我是Sybase IQ和Impala的新手。

sql impala sybase-iq
1个回答
0
投票

您可以尝试用下面的查询替换最后一个查询并尝试运行它 -

SELECT f.exch 
FROM   (SELECT CASE 
                 WHEN sourcedesk IN ( 'GOBUS_NY', 'GOBUS_UK', 'PETRDAES', 
                                      'PEETRAD' ) 
                       THEN 
                 clientid 
                 WHEN sourcedesk = 'AESLDN' 
                      AND clientid != '' THEN clientid 
                 ELSE owner 
               END                                 AS aclient, 
               clientid                            AS client, 
               orderid                             AS gaotag, 
               exchange                            AS exch, 
               side                                AS side, 
               securityid                          AS sym, 
               cumulativequantity * executionprice AS value, 
               cumulativequantity                  AS qdone, 
               fillid                              AS gaftag, 
               executionexchangetimestamplcl       AS xstamp, 
               executionprice                      AS lprice, 
               executionexchangeid                 AS xftag, 
               serverid                            AS srvid, 
               reasoncode                          AS rescode, 
               rootfillid                          AS rgaftag, 
               miccode                             AS miccode, 
               mifidtradeflags                     AS mifidtradeflags, 
               sourcedesk                          AS desk 
        FROM   fillsastextdatestring 
        WHERE  agoralocaltradedate = '190205' 
               AND exchange = 'VEX' 
               AND sourceservicename LIKE 'vexprod%' 
               AND securityid LIKE '%.%' 
        UNION ALL 
        SELECT CASE 
                 WHEN sourcedesk IN ( 'GOBUS_NY', 'GOBUS_UK', 'PETRDAES', 
                                      'PEETRAD', 
                                      'VEXSVC', 'LLSOR' ) THEN clientid 
                 WHEN sourcedesk = 'AESLDN' 
                      AND clientid != '' THEN clientid 
                 ELSE owner 
               END                                 AS aclient, 
               clientid                            AS client, 
               orderid                             AS gaotag, 
               exchange                            AS exch, 
               side                                AS side, 
               securityid                          AS sym, 
               cumulativequantity * executionprice AS value, 
               cumulativequantity                  AS qdone, 
               fillid                              AS gaftag, 
               executionexchangetimestamplcl       AS xstamp, 
               executionprice                      AS lprice, 
               executionexchangeid                 AS xftag, 
               serverid                            AS srvid, 
               reasoncode                          AS rescode, 
               rootfillid                          AS rgaftag, 
               miccode                             AS miccode, 
               mifidtradeflags                     AS mifidtradeflags, 
               sourcedesk                          AS desk 
        FROM   fillsastextdatestring 
        WHERE  agoralocaltradedate = '190205' 
               AND sourceservicename IN ( 'SORUK', 'PRODSorBkFlr', 
                                          'PRODFixBkFlr', 
                                          'PRODFixBkFlr1', 
                                          'PRODFixBkFlr2', 'PRODSmgBkFlr', 
                                          'ECGaia2Agora' ) 
               AND owner NOT LIKE 'tree%' 
               AND securityid LIKE '%.%' 
        UNION ALL 
        SELECT CASE 
                 WHEN sourcedesk IN ( 'GOBUS_NY', 'GOBUS_UK', 'PETRDAES', 
                                      'PEETRAD', 
                                      'VEXSVC', 'LLSOR' ) THEN clientid 
                 WHEN sourcedesk = 'AESLDN' 
                      AND clientid != '' THEN clientid 
                 ELSE owner 
               END                                 AS aclient, 
               clientid                            AS client, 
               orderid                             AS gaotag, 
               exchange                            AS exch, 
               side                                AS side, 
               securityid                          AS sym, 
               cumulativequantity * executionprice AS value, 
               cumulativequantity                  AS qdone, 
               fillid                              AS gaftag, 
               executionexchangetimestamplcl       AS xstamp, 
               executionprice                      AS lprice, 
               executionexchangeid                 AS xftag, 
               serverid                            AS srvid, 
               reasoncode                          AS rescode, 
               rootfillid                          AS rgaftag, 
               miccode                             AS miccode, 
               mifidtradeflags                     AS mifidtradeflags, 
               sourcedesk                          AS desk 
        FROM   fillsastextdatestring 
        WHERE  agoralocaltradedate = '190205' 
               AND securityid LIKE '%.%' 
               AND exchange = 'BENCHMKX' 
               AND sourceservicename LIKE 'BENCHM_%' 
        UNION ALL 
        SELECT CASE 
                 WHEN sourcedesk IN ( 'GOBUS_NY', 'GOBUS_UK', 'PETRDAES', 
                                      'PEETRAD', 
                                      'VEXSVC', 'LLSOR' ) THEN clientid 
                 WHEN sourcedesk = 'AESLDN' 
                      AND clientid != '' THEN clientid 
                 ELSE owner 
               END                                 AS aclient, 
               clientid                            AS client, 
               orderid                             AS gaotag, 
               exchange                            AS exch, 
               side                                AS side, 
               securityid                          AS sym, 
               cumulativequantity * executionprice AS value, 
               cumulativequantity                  AS qdone, 
               fillid                              AS gaftag, 
               executionexchangetimestamplcl       AS xstamp, 
               executionprice                      AS lprice, 
               executionexchangeid                 AS xftag, 
               serverid                            AS srvid, 
               reasoncode                          AS rescode, 
               rootfillid                          AS rgaftag, 
               miccode                             AS miccode, 
               mifidtradeflags                     AS mifidtradeflags, 
               sourcedesk                          AS desk 
        FROM   fillsastextdatestring 
        WHERE  agoralocaltradedate = '190205' 
               AND sourceservicename = 'ECGaia2Agora' 
               AND owner NOT LIKE 'tree%' 
               AND exchange IN ( 'BATS', 'CHIX' ) 
               AND reasoncode = 'NT' 
               AND side = 'B' 
        UNION ALL 
        SELECT CASE 
                 WHEN sourcedesk IN ( 'GOBUS_NY', 'GOBUS_UK', 'PETRDAES', 
                                      'PEETRAD', 
                                      'VEXSVC', 'LLSOR' ) THEN clientid 
                 WHEN sourcedesk = 'AESLDN' 
                      AND clientid != '' THEN clientid 
                 ELSE owner 
               END                                 AS aclient, 
               clientid                            AS client, 
               orderid                             AS gaotag, 
               exchange                            AS exch, 
               side                                AS side, 
               securityid                          AS sym, 
               cumulativequantity * executionprice AS value, 
               cumulativequantity                  AS qdone, 
               fillid                              AS gaftag, 
               executionexchangetimestamplcl       AS xstamp, 
               executionprice                      AS lprice, 
               executionexchangeid                 AS xftag, 
               serverid                            AS srvid, 
               reasoncode                          AS rescode, 
               rootfillid                          AS rgaftag, 
               miccode                             AS miccode, 
               mifidtradeflags                     AS mifidtradeflags, 
               sourcedesk                          AS desk 
        FROM   fillsastextdatestring 
        WHERE  agoralocaltradedate = '190205' 
               AND sourceservicename LIKE 'tars_%') AS f 
       INNER JOIN (SELECT orderid             AS gaotag, 
                          serverid            AS srvid, 
                          securityidasentered AS enteredsym, 
                          securityid          AS sym, 
                          rootorderid         AS rgaotag, 
                          timeinforce         AS tif, 
                          settletype          AS settletype, 
                          sourceservicename   AS appl, 
                          account             AS acct 
                   FROM   ordersastextdatestring 
                   WHERE  agoralocaltradedate = '190205' 
                          AND destinationdesk IN ( 'BENCHX', 'VEXSVC', 'SORMKT', 
                                                   'MAIA' 
                                                   , 
                                                   'LLSOR', 'TARSSVC' )) o 
               ON f.gaotag = o.gaotag;
© www.soinside.com 2019 - 2024. All rights reserved.