felipebz / zpa

Parser and static code analysis tool for PL/SQL and Oracle SQL.
https://zpa.felipebz.com
GNU Lesser General Public License v3.0
211 stars 77 forks source link

Issue with group by grouping sets (()) #168

Closed ktzevelekidis closed 1 year ago

ktzevelekidis commented 1 year ago

Hello!

I am trying to use ZPA analyzer with my PL/SQL code. I have the following code:

create or replace package test_pkg as
  function function_name return sys_refcursor;
end;
/

create or replace package body test_pkg as
  function function_name
    return sys_refcursor as
    select_cursor sys_refcursor;
  begin

    open select_cursor for
      select
        *
      from
        table_name
      group by grouping sets (());

    return select_cursor;
  end;
end;
/

When trying to analyze this code, I get the following error:

{
  "issues": [
    {
      "engineId": "zpa",
      "ruleId": "ParsingError",
      "severity": "INFO",
      "type": "CODE_SMELL",
      "primaryLocation": {
        "message": "This code wasn\u0027t parsed correctly. No issue will be registered on it.",
        "filePath": "test.sql",
        "textRange": {
          "startLine": 6,
          "endLine": 6,
          "startColumn": 0,
          "endColumn": 42
        }
      },
      "duration": "",
      "secondaryLocations": [],
      "effortMinutes": 0
    },
    {
      "engineId": "zpa",
      "ruleId": "ParsingError",
      "severity": "INFO",
      "type": "CODE_SMELL",
      "primaryLocation": {
        "message": "This code wasn\u0027t parsed correctly. No issue will be registered on it.",
        "filePath": "test.sql",
        "textRange": {
          "startLine": 8,
          "endLine": 12,
          "startColumn": 25,
          "endColumn": 26
        }
      },
      "duration": "",
      "secondaryLocations": [],
      "effortMinutes": 0
    },
    {
      "engineId": "zpa",
      "ruleId": "ParsingError",
      "severity": "INFO",
      "type": "CODE_SMELL",
      "primaryLocation": {
        "message": "This code wasn\u0027t parsed correctly. No issue will be registered on it.",
        "filePath": "test.sql",
        "textRange": {
          "startLine": 17,
          "endLine": 21,
          "startColumn": 24,
          "endColumn": 4
        }
      },
      "duration": "",
      "secondaryLocations": [],
      "effortMinutes": 0
    },
    {
      "engineId": "zpa",
      "ruleId": "SelectAllColumns",
      "severity": "MAJOR",
      "type": "CODE_SMELL",
      "primaryLocation": {
        "message": "SELECT * should not be used.",
        "filePath": "test.sql",
        "textRange": {
          "startLine": 14,
          "endLine": 14,
          "startColumn": 8,
          "endColumn": 9
        }
      },
      "duration": "30min",
      "secondaryLocations": [],
      "effortMinutes": 30
    }
  ]
}

The interesting part here, is that even I get this parsing error the analysis finishes for this simple file. However, in real world example (more complicated query), the analysis does not end (it was running for one hour).

Can you please elaborate?

felipebz commented 1 year ago

Hi,

Thanks for reporting this issue. I've fixed the parsing error, but I'm not sure why the analysis is hanging on a more complicated query.

Could you please test it with the early-access release to check if that also fixes the hanging?

ktzevelekidis commented 1 year ago

Hello!

Thanks for the prompt reply. I tried the zpa-cli-2.0.0-SNAPSHOT version, but I get exactly the same error.

felipebz commented 1 year ago

Hi, I’m sorry for the inconvenience. There was a problem with the packaging process and the zip file wasn't updated. Could you please try again and let me know if it works? Thank you for your patience and feedback.

ktzevelekidis commented 1 year ago

Hello! I tested the new version and the parsing error is fixed. Also, I tried to run the analysis for the more complex query, and it seems it works fine for it as well (the analysis ends successfully). I will install on sonarqube this early access version, in order to see if it works as expected and I will let you know. Thanks a lot for your effort!

felipebz commented 1 year ago

Thanks for you feedback 😊