Postgresql LOC miscalculation

  • ALM used (GitHub)
  • CI system used (Github Workflow)
  • Scanner command used when applicable (sonar-scanner -Dsonar.projectBaseDir=.)
  • Languages of the repository - Go, Vue, psql
  • Error observed (loc metrics not tally on postgresql file.)
  • scanner cli version: SonarScanner CLI 8.1.0.6389
  • Steps to reproduce
    • create a psql query and save in two file with .sql and .pgsql extensions.
      ensure sql file scanned by plsql analyzer and pgsql by postgresql analyzer

Hi, I faced some issue regarding the LOC metrics when processing the psql files. Anyone facing the same issue?

I saved postgresql sql into two file extensions: sql and psql.
analyze result:

  1. plsql analyzer - parsing error but LOC match the file content.
  2. postgresql analyzer - syntax parsing without issue but LOC not tally with the file content.

Hey @chml0204, welcome to the Community!

Assuming you’re using CI-based analysis: could you check the logs to confirm that indeed both files are being parsed and analyzed correctly? Are there any warnings? Would you mind sharing debug-level logs?

Hi there,

I observed some errors on parsing the sql file but that was expected. I checked the logs and there’s no errors when it came to the pgsql files. pgsql files are indexed as PostgreSQL, no issue on parsing, analyzing & Detection of duplications.

No sure how’s the LOC determined but I would be expecting LOC values closer to sql file copies.

herewith the debug logs.
workflow.log (202.7 KB)

Hey, thanks for sharing the logs, I’m going to flag this for the team to have a look.

Hello,

Thanks for the report.

I have a question regarding your files two and four: are they PostgreSQL function with a lot of code inside the $$ block? If so, does the number of lines of code reported in the Postgres analyzer match the number of lines of code outside the $$ block?

For your sample file, the behavior is unexpected since it was analyzed without a parsing error.
Could you send the .sql files? If they are sensitive, you could also send them to me privately.

Have a nice day,

Hi @ghislain.piot

Herewith the SQL files tested. The loc reported by Postgres Analyzer not tally with loc outside the $$ block.

Let me know if additional information required.

two.txt (1.3 KB)

sample.txt (1.1 KB)

four.txt (1.4 KB)

Thanks for the files, I have been able to reproduce it. The counts match if you exclude the $$ blocks and some slight side-effects.

I have created a ticket for this.

Have a nice day,

Hello,

This should work now on SonarQube Cloud.