Print Thread
Beautifier handling large merge expression wrong
#65833 08/16/24 06:15 AM
Joined: Aug 2024
Posts: 1
S
Member
OP Offline
Member
S
Joined: Aug 2024
Posts: 1
I am trying to beautify a merge expression in my package.
Here is my expression, manually indented, WITHOUT the beautifier:
SQL Query
  MERGE INTO Kap_Formatted_Fm_Black_List t
  USING (SELECT Id,
                Bl.Sourcerecid,
                Bl.Name_Lat,
                CASE
                   WHEN Bl.Rowid IS NULL THEN
                    1
                 END AS Delete_Flag
           FROM Fmblacklist Bl
           FULL OUTER JOIN Kap_Formatted_Fm_Black_List Kpbl
          USING (Id)) Src
  ON (t.Id = Src.Id)
  WHEN MATCHED THEN
    UPDATE
       SET t.Sourcerecid        = Src.Sourcerecid,
           t.Name_Lat           = Src.Name_Lat,
           t.First_Word         = UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', '')),
           t.Second_Word        = UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', '')),
           t.Third_Word         = UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')),
           t.Length_First_Word  = NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', '')), 0),
           t.Length_Second_Word = NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', '')), 0),
           t.Length_Third_Word  = NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')), 0),
           t.Exists_First_Word  = NVL2(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', ''), 1, 0),
           t.Exists_Second_Word = NVL2(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', ''), 1, 0),
           t.Exists_Third_Word  = CASE
                                    WHEN LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')) > 2 THEN
                                     1
                                    ELSE
                                     0
                                  END
     WHERE t.Name_Lat <> Src.Name_Lat
        OR t.Sourcerecid <> Src.Sourcerecid --
     DELETE
     WHERE Src.Delete_Flag = 1 --
     WHEN NOT MATCHED THEN --
      INSERT
        (t.Id,
         t.Sourcerecid,
         t.Name_Lat,
         t.First_Word,
         t.Second_Word,
         t.Third_Word,
         t.Length_First_Word,
         t.Length_Second_Word,
         t.Length_Third_Word,
         t.Exists_First_Word,
         t.Exists_Second_Word,
         t.Exists_Third_Word) --
      VALUES
        (Src.Id,
         Src.Sourcerecid,
         Src.Name_Lat,
         UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', '')),
         UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', '')),
         UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')),
         NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', '')), 0),
         NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', '')), 0),
         NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')), 0),
         NVL2(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', ''), 1, 0),
         NVL2(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', ''), 1, 0),
         CASE WHEN LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')) > 2 THEN 1 ELSE 0 END);




Here is the result WITH the beautifier:
SQL Query
MERGE INTO Kap_Formatted_Fm_Black_List t
    USING (SELECT Id,
                  Bl.Sourcerecid,
                  Bl.Name_Lat,
                  CASE
                     WHEN Bl.Rowid IS NULL THEN
                      1
                   END AS Delete_Flag
             FROM Fmblacklist Bl
             FULL OUTER JOIN Kap_Formatted_Fm_Black_List Kpbl
            USING (Id)) Src
    ON (t.Id = Src.Id)
    WHEN MATCHED THEN
      UPDATE
         SET t.Sourcerecid        = Src.Sourcerecid,
             t.Name_Lat           = Src.Name_Lat,
             t.First_Word         = UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', '')),
             t.Second_Word        = UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', '')),
             t.Third_Word         = UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')),
             t.Length_First_Word  = NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', '')), 0),
             t.Length_Second_Word = NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', '')), 0),
             t.Length_Third_Word  = NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')), 0),
             t.Exists_First_Word  = NVL2(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', ''), 1, 0),
             t.Exists_Second_Word = NVL2(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', ''), 1, 0),
             t.Exists_Third_Word  = CASE
                                      WHEN LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')) > 2 THEN
                                       1
                                      ELSE
                                       0
                                    END
       WHERE t.Name_Lat <> Src.Name_Lat
          OR t.Sourcerecid <> Src.Sourcerecid --
       DELETE
       WHERE Src.Delete_Flag = 1 --
       WHEN NOT MATCHED THEN --
      INSERT(t.Id, t.Sourcerecid, t.Name_Lat, t.First_Word, t.Second_Word, t.Third_Word, t.Length_First_Word, t.Length_Second_Word, t.Length_Third_Word, t.Exists_First_Word, t.Exists_Second_Word, t.Exists_Third_Word) --
      VALUES(Src.Id, Src.Sourcerecid, Src.Name_Lat, UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', '')), UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', '')), UPPER(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')), NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', '')), 0), NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', '')), 0), NVL(LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')), 0), NVL2(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 1), '[^a-zA-Z0-9'' ]', ''), 1, 0), NVL2(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 2), '[^a-zA-Z0-9'' ]', ''), 1, 0),CASE
        WHEN LENGTH(REGEXP_REPLACE(REGEXP_SUBSTR(Src.Name_Lat, '\S+', 1, 3), '[^a-zA-Z0-9'' ]', '')) > 2 THEN
         1
        ELSE
         0
      END);


Please advice how to fix the problem or is it a bug in the beautifier?

Re: Beautifier handling large merge expression wrong
Sardorbek Khujae #65835 08/16/24 08:39 AM
Joined: Aug 1999
Posts: 22,361
Member
Offline
Member
Joined: Aug 1999
Posts: 22,361
This seems to be a bug, caused by the case expression of the update (t.Exists_Third_Word = CASE ...).

We'll fix it.


Marco Kalter
Allround Automations

Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.029s Queries: 14 (0.006s) Memory: 2.5268 MB (Peak: 3.0397 MB) Data Comp: Off Server Time: 2024-10-14 12:19:07 UTC
Valid HTML 5 and Valid CSS