From 24a29f46be34473a9d3042e7891b2dc67de3c649 Mon Sep 17 00:00:00 2001 From: Taus Date: Wed, 26 Nov 2025 17:03:03 +0000 Subject: [PATCH] Python: Fix all metrics-related compilation failures In hindsight, having a `.getMetrics()` method that just returns `this` is somewhat weird. It's possible that it predates the existence of the inline cast, however. --- python/ql/src/Functions/OverlyComplexDelMethod.ql | 2 +- python/ql/src/Metrics/CLinesOfCode.ql | 5 +++-- python/ql/src/Metrics/ClassAfferentCoupling.ql | 1 + python/ql/src/Metrics/ClassEfferentCoupling.ql | 1 + python/ql/src/Metrics/CommentRatio.ql | 8 +++++--- python/ql/src/Metrics/CyclomaticComplexity.ql | 5 +++-- python/ql/src/Metrics/DocStringRatio.ql | 7 ++++--- python/ql/src/Metrics/FLines.ql | 5 +++-- python/ql/src/Metrics/FLinesOfCode.ql | 5 +++-- python/ql/src/Metrics/FLinesOfComments.ql | 6 +++--- python/ql/src/Metrics/FunctionNumberOfCalls.ql | 1 + python/ql/src/Metrics/FunctionStatementNestingDepth.ql | 1 + python/ql/src/Metrics/History/HChurn.ql | 5 +++-- python/ql/src/Metrics/History/HLinesAdded.ql | 5 +++-- python/ql/src/Metrics/History/HLinesDeleted.ql | 5 +++-- python/ql/src/Metrics/History/HNumberOfAuthors.ql | 5 +++-- python/ql/src/Metrics/History/HNumberOfCoCommits.ql | 5 +++-- python/ql/src/Metrics/History/HNumberOfReCommits.ql | 5 +++-- python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql | 5 +++-- .../ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql | 5 +++-- python/ql/src/Metrics/LackofCohesionInMethodsCK.ql | 1 + python/ql/src/Metrics/LackofCohesionInMethodsHM.ql | 1 + python/ql/src/Metrics/ModuleAfferentCoupling.ql | 1 + python/ql/src/Metrics/ModuleEfferentCoupling.ql | 1 + python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql | 1 + python/ql/src/Statements/DocStrings.ql | 4 ++-- python/ql/src/Summary/LinesOfCode.ql | 3 ++- python/ql/src/Summary/LinesOfUserCode.ql | 5 +++-- python/ql/src/analysis/Summary.ql | 1 + python/ql/src/meta/debug/DebugStats.ql | 6 +++--- .../ql/test/library-tests/ControlFlow/general/Comments.ql | 5 +++-- python/ql/test/library-tests/ControlFlow/general/Cyclo.ql | 5 +++-- python/ql/test/library-tests/ControlFlow/general/Lines.ql | 5 +++-- python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql | 7 ++++--- 34 files changed, 82 insertions(+), 51 deletions(-) diff --git a/python/ql/src/Functions/OverlyComplexDelMethod.ql b/python/ql/src/Functions/OverlyComplexDelMethod.ql index d9fa3e750e6..12776db1b60 100644 --- a/python/ql/src/Functions/OverlyComplexDelMethod.ql +++ b/python/ql/src/Functions/OverlyComplexDelMethod.ql @@ -18,6 +18,6 @@ from FunctionValue method where exists(ClassValue c | c.declaredAttribute("__del__") = method and - method.getScope().getMetrics().getCyclomaticComplexity() > 3 + method.getScope().(FunctionMetrics).getCyclomaticComplexity() > 3 ) select method, "Overly complex '__del__' method." diff --git a/python/ql/src/Metrics/CLinesOfCode.ql b/python/ql/src/Metrics/CLinesOfCode.ql index c7b29615593..66a107a521f 100644 --- a/python/ql/src/Metrics/CLinesOfCode.ql +++ b/python/ql/src/Metrics/CLinesOfCode.ql @@ -10,6 +10,7 @@ */ import python +private import LegacyPointsTo -from Function f -select f, f.getMetrics().getNumberOfLinesOfCode() as n order by n desc +from FunctionMetrics f +select f, f.getNumberOfLinesOfCode() as n order by n desc diff --git a/python/ql/src/Metrics/ClassAfferentCoupling.ql b/python/ql/src/Metrics/ClassAfferentCoupling.ql index 295e8c61a6c..3faf714d09c 100644 --- a/python/ql/src/Metrics/ClassAfferentCoupling.ql +++ b/python/ql/src/Metrics/ClassAfferentCoupling.ql @@ -11,6 +11,7 @@ */ import python +private import LegacyPointsTo from ClassMetrics cls select cls, cls.getAfferentCoupling() as n order by n desc diff --git a/python/ql/src/Metrics/ClassEfferentCoupling.ql b/python/ql/src/Metrics/ClassEfferentCoupling.ql index d960c0142e3..b4c5a29696b 100644 --- a/python/ql/src/Metrics/ClassEfferentCoupling.ql +++ b/python/ql/src/Metrics/ClassEfferentCoupling.ql @@ -11,6 +11,7 @@ */ import python +private import LegacyPointsTo from ClassMetrics cls select cls, cls.getEfferentCoupling() as n order by n desc diff --git a/python/ql/src/Metrics/CommentRatio.ql b/python/ql/src/Metrics/CommentRatio.ql index 8ebb27cf304..38394c1bf4f 100644 --- a/python/ql/src/Metrics/CommentRatio.ql +++ b/python/ql/src/Metrics/CommentRatio.ql @@ -12,8 +12,10 @@ */ import python +private import LegacyPointsTo -from Module m, ModuleMetrics mm -where mm = m.getMetrics() and mm.getNumberOfLines() > 0 -select m, 100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio +from ModuleMetrics mm +where mm.getNumberOfLines() > 0 +select mm, + 100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio order by ratio desc diff --git a/python/ql/src/Metrics/CyclomaticComplexity.ql b/python/ql/src/Metrics/CyclomaticComplexity.ql index 1e332f4ec9f..3d9ca10dd99 100644 --- a/python/ql/src/Metrics/CyclomaticComplexity.ql +++ b/python/ql/src/Metrics/CyclomaticComplexity.ql @@ -13,7 +13,8 @@ */ import python +private import LegacyPointsTo -from Function func, int complexity -where complexity = func.getMetrics().getCyclomaticComplexity() +from FunctionMetrics func, int complexity +where complexity = func.getCyclomaticComplexity() select func, complexity order by complexity desc diff --git a/python/ql/src/Metrics/DocStringRatio.ql b/python/ql/src/Metrics/DocStringRatio.ql index a8cd8b8dc4e..824ff5a3509 100644 --- a/python/ql/src/Metrics/DocStringRatio.ql +++ b/python/ql/src/Metrics/DocStringRatio.ql @@ -11,9 +11,10 @@ */ import python +private import LegacyPointsTo -from Module m, ModuleMetrics mm -where mm = m.getMetrics() and mm.getNumberOfLines() > 0 -select m, +from ModuleMetrics mm +where mm.getNumberOfLines() > 0 +select mm, 100.0 * (mm.getNumberOfLinesOfDocStrings().(float) / mm.getNumberOfLines().(float)) as ratio order by ratio desc diff --git a/python/ql/src/Metrics/FLines.ql b/python/ql/src/Metrics/FLines.ql index 340fb6f58ea..dc5418711c9 100644 --- a/python/ql/src/Metrics/FLines.ql +++ b/python/ql/src/Metrics/FLines.ql @@ -9,7 +9,8 @@ */ import python +private import LegacyPointsTo -from Module m, int n -where n = m.getMetrics().getNumberOfLines() +from ModuleMetrics m, int n +where n = m.getNumberOfLines() select m, n order by n desc diff --git a/python/ql/src/Metrics/FLinesOfCode.ql b/python/ql/src/Metrics/FLinesOfCode.ql index 84c952f9267..8159eb86c57 100644 --- a/python/ql/src/Metrics/FLinesOfCode.ql +++ b/python/ql/src/Metrics/FLinesOfCode.ql @@ -11,7 +11,8 @@ */ import python +private import LegacyPointsTo -from Module m, int n -where n = m.getMetrics().getNumberOfLinesOfCode() +from ModuleMetrics m, int n +where n = m.getNumberOfLinesOfCode() select m, n order by n desc diff --git a/python/ql/src/Metrics/FLinesOfComments.ql b/python/ql/src/Metrics/FLinesOfComments.ql index 18a234eef67..ac4b295003a 100644 --- a/python/ql/src/Metrics/FLinesOfComments.ql +++ b/python/ql/src/Metrics/FLinesOfComments.ql @@ -10,8 +10,8 @@ */ import python +private import LegacyPointsTo -from Module m, int n -where - n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings() +from ModuleMetrics m, int n +where n = m.getNumberOfLinesOfComments() + m.getNumberOfLinesOfDocStrings() select m, n order by n desc diff --git a/python/ql/src/Metrics/FunctionNumberOfCalls.ql b/python/ql/src/Metrics/FunctionNumberOfCalls.ql index fb4dfe5a9d2..60171c790bf 100644 --- a/python/ql/src/Metrics/FunctionNumberOfCalls.ql +++ b/python/ql/src/Metrics/FunctionNumberOfCalls.ql @@ -9,6 +9,7 @@ */ import python +private import LegacyPointsTo from FunctionMetrics func select func, func.getNumberOfCalls() as n order by n desc diff --git a/python/ql/src/Metrics/FunctionStatementNestingDepth.ql b/python/ql/src/Metrics/FunctionStatementNestingDepth.ql index ab40cc6068d..94f7e355750 100644 --- a/python/ql/src/Metrics/FunctionStatementNestingDepth.ql +++ b/python/ql/src/Metrics/FunctionStatementNestingDepth.ql @@ -11,6 +11,7 @@ */ import python +private import LegacyPointsTo from FunctionMetrics func select func, func.getStatementNestingDepth() as n order by n desc diff --git a/python/ql/src/Metrics/History/HChurn.ql b/python/ql/src/Metrics/History/HChurn.ql index d6a8722e6e2..dba28843670 100644 --- a/python/ql/src/Metrics/History/HChurn.ql +++ b/python/ql/src/Metrics/History/HChurn.ql @@ -10,8 +10,9 @@ import python import external.VCS +private import LegacyPointsTo -from Module m, int n +from ModuleMetrics m, int n where n = sum(Commit entry, int churn | @@ -19,5 +20,5 @@ where | churn ) and - exists(m.getMetrics().getNumberOfLinesOfCode()) + exists(m.getNumberOfLinesOfCode()) select m, n order by n desc diff --git a/python/ql/src/Metrics/History/HLinesAdded.ql b/python/ql/src/Metrics/History/HLinesAdded.ql index 3ecec917ab1..51a0af62460 100644 --- a/python/ql/src/Metrics/History/HLinesAdded.ql +++ b/python/ql/src/Metrics/History/HLinesAdded.ql @@ -10,8 +10,9 @@ import python import external.VCS +private import LegacyPointsTo -from Module m, int n +from ModuleMetrics m, int n where n = sum(Commit entry, int churn | @@ -19,5 +20,5 @@ where | churn ) and - exists(m.getMetrics().getNumberOfLinesOfCode()) + exists(m.getNumberOfLinesOfCode()) select m, n order by n desc diff --git a/python/ql/src/Metrics/History/HLinesDeleted.ql b/python/ql/src/Metrics/History/HLinesDeleted.ql index ded74756d55..3016c9f128b 100644 --- a/python/ql/src/Metrics/History/HLinesDeleted.ql +++ b/python/ql/src/Metrics/History/HLinesDeleted.ql @@ -10,8 +10,9 @@ import python import external.VCS +private import LegacyPointsTo -from Module m, int n +from ModuleMetrics m, int n where n = sum(Commit entry, int churn | @@ -19,5 +20,5 @@ where | churn ) and - exists(m.getMetrics().getNumberOfLinesOfCode()) + exists(m.getNumberOfLinesOfCode()) select m, n order by n desc diff --git a/python/ql/src/Metrics/History/HNumberOfAuthors.ql b/python/ql/src/Metrics/History/HNumberOfAuthors.ql index 15e679e58c5..ff00773d98c 100644 --- a/python/ql/src/Metrics/History/HNumberOfAuthors.ql +++ b/python/ql/src/Metrics/History/HNumberOfAuthors.ql @@ -10,7 +10,8 @@ import python import external.VCS +private import LegacyPointsTo -from Module m -where exists(m.getMetrics().getNumberOfLinesOfCode()) +from ModuleMetrics m +where exists(m.getNumberOfLinesOfCode()) select m, count(Author author | author.getAnEditedFile() = m.getFile()) diff --git a/python/ql/src/Metrics/History/HNumberOfCoCommits.ql b/python/ql/src/Metrics/History/HNumberOfCoCommits.ql index afb62353a03..4192ecf57ac 100644 --- a/python/ql/src/Metrics/History/HNumberOfCoCommits.ql +++ b/python/ql/src/Metrics/History/HNumberOfCoCommits.ql @@ -10,11 +10,12 @@ import python import external.VCS +private import LegacyPointsTo int committedFiles(Commit commit) { result = count(commit.getAnAffectedFile()) } -from Module m -where exists(m.getMetrics().getNumberOfLinesOfCode()) +from ModuleMetrics m +where exists(m.getNumberOfLinesOfCode()) select m, avg(Commit commit, int toAvg | commit.getAnAffectedFile() = m.getFile() and toAvg = committedFiles(commit) - 1 diff --git a/python/ql/src/Metrics/History/HNumberOfReCommits.ql b/python/ql/src/Metrics/History/HNumberOfReCommits.ql index 5df9194ee34..f12c51840dc 100644 --- a/python/ql/src/Metrics/History/HNumberOfReCommits.ql +++ b/python/ql/src/Metrics/History/HNumberOfReCommits.ql @@ -10,6 +10,7 @@ import python import external.VCS +private import LegacyPointsTo predicate inRange(Commit first, Commit second) { first.getAnAffectedFile() = second.getAnAffectedFile() and @@ -29,6 +30,6 @@ int recommitsForFile(File f) { ) } -from Module m -where exists(m.getMetrics().getNumberOfLinesOfCode()) +from ModuleMetrics m +where exists(m.getNumberOfLinesOfCode()) select m, recommitsForFile(m.getFile()) diff --git a/python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql b/python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql index e04baa491f4..9b787f52957 100644 --- a/python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql +++ b/python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql @@ -10,9 +10,10 @@ import python import external.VCS +private import LegacyPointsTo -from Module m -where exists(m.getMetrics().getNumberOfLinesOfCode()) +from ModuleMetrics m +where exists(m.getNumberOfLinesOfCode()) select m, count(Author author | exists(Commit e | diff --git a/python/ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql b/python/ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql index f0d8473b302..501094907af 100644 --- a/python/ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql +++ b/python/ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql @@ -10,11 +10,12 @@ import python import external.VCS +private import LegacyPointsTo -from Module m +from ModuleMetrics m where exists(Commit e | e.getAnAffectedFile() = m.getFile() and e.daysToNow() <= 180 and not artificialChange(e) ) and - exists(m.getMetrics().getNumberOfLinesOfCode()) + exists(m.getNumberOfLinesOfCode()) select m, 1 diff --git a/python/ql/src/Metrics/LackofCohesionInMethodsCK.ql b/python/ql/src/Metrics/LackofCohesionInMethodsCK.ql index c0ef582c32b..f06b050827c 100644 --- a/python/ql/src/Metrics/LackofCohesionInMethodsCK.ql +++ b/python/ql/src/Metrics/LackofCohesionInMethodsCK.ql @@ -9,6 +9,7 @@ */ import python +private import LegacyPointsTo from ClassMetrics cls select cls, cls.getLackOfCohesionCK() as n order by n desc diff --git a/python/ql/src/Metrics/LackofCohesionInMethodsHM.ql b/python/ql/src/Metrics/LackofCohesionInMethodsHM.ql index 5cc77ecfb4f..1456b76b286 100644 --- a/python/ql/src/Metrics/LackofCohesionInMethodsHM.ql +++ b/python/ql/src/Metrics/LackofCohesionInMethodsHM.ql @@ -9,6 +9,7 @@ */ import python +private import LegacyPointsTo from ClassMetrics cls select cls, cls.getLackOfCohesionHM() as n order by n desc diff --git a/python/ql/src/Metrics/ModuleAfferentCoupling.ql b/python/ql/src/Metrics/ModuleAfferentCoupling.ql index 7bf51433785..d61cc61e4da 100644 --- a/python/ql/src/Metrics/ModuleAfferentCoupling.ql +++ b/python/ql/src/Metrics/ModuleAfferentCoupling.ql @@ -11,6 +11,7 @@ */ import python +private import LegacyPointsTo from ModuleMetrics m select m, m.getAfferentCoupling() as n order by n desc diff --git a/python/ql/src/Metrics/ModuleEfferentCoupling.ql b/python/ql/src/Metrics/ModuleEfferentCoupling.ql index 51fdcf5423b..bfabf4b6012 100644 --- a/python/ql/src/Metrics/ModuleEfferentCoupling.ql +++ b/python/ql/src/Metrics/ModuleEfferentCoupling.ql @@ -11,6 +11,7 @@ */ import python +private import LegacyPointsTo from ModuleMetrics m select m, m.getEfferentCoupling() as n order by n desc diff --git a/python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql b/python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql index 00a4c1bf0db..e5164499331 100644 --- a/python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql +++ b/python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql @@ -11,6 +11,7 @@ */ import python +private import LegacyPointsTo from FunctionMetrics func select func, func.getNumberOfParametersWithoutDefault() as n order by n desc diff --git a/python/ql/src/Statements/DocStrings.ql b/python/ql/src/Statements/DocStrings.ql index d7df570a7ef..df7b09a963e 100644 --- a/python/ql/src/Statements/DocStrings.ql +++ b/python/ql/src/Statements/DocStrings.ql @@ -28,12 +28,12 @@ predicate needs_docstring(Scope s) { ) } -predicate function_needs_docstring(Function f) { +predicate function_needs_docstring(FunctionMetrics f) { not exists(FunctionValue fo, FunctionValue base | fo.overrides(base) and fo.getScope() = f | not function_needs_docstring(base.getScope()) ) and f.getName() != "lambda" and - (f.getMetrics().getNumberOfLinesOfCode() - count(f.getADecorator())) > 2 and + (f.getNumberOfLinesOfCode() - count(f.getADecorator())) > 2 and not exists(PythonPropertyObject p | p.getGetter().getFunction() = f or p.getSetter().getFunction() = f diff --git a/python/ql/src/Summary/LinesOfCode.ql b/python/ql/src/Summary/LinesOfCode.ql index a07a896c4ca..04cb33a3451 100644 --- a/python/ql/src/Summary/LinesOfCode.ql +++ b/python/ql/src/Summary/LinesOfCode.ql @@ -10,5 +10,6 @@ */ import python +private import LegacyPointsTo -select sum(Module m | | m.getMetrics().getNumberOfLinesOfCode()) +select sum(ModuleMetrics m | | m.getNumberOfLinesOfCode()) diff --git a/python/ql/src/Summary/LinesOfUserCode.ql b/python/ql/src/Summary/LinesOfUserCode.ql index f6d6f25872f..f920ebb51f4 100644 --- a/python/ql/src/Summary/LinesOfUserCode.ql +++ b/python/ql/src/Summary/LinesOfUserCode.ql @@ -14,10 +14,11 @@ import python import semmle.python.filters.GeneratedCode +private import LegacyPointsTo -select sum(Module m | +select sum(ModuleMetrics m | exists(m.getFile().getRelativePath()) and not m.getFile() instanceof GeneratedFile | - m.getMetrics().getNumberOfLinesOfCode() + m.getNumberOfLinesOfCode() ) diff --git a/python/ql/src/analysis/Summary.ql b/python/ql/src/analysis/Summary.ql index 630f4e2678b..bad5070a9ef 100644 --- a/python/ql/src/analysis/Summary.ql +++ b/python/ql/src/analysis/Summary.ql @@ -3,6 +3,7 @@ */ import python +private import LegacyPointsTo from string key, string value where diff --git a/python/ql/src/meta/debug/DebugStats.ql b/python/ql/src/meta/debug/DebugStats.ql index 5ebbe963943..03ecaae27e2 100644 --- a/python/ql/src/meta/debug/DebugStats.ql +++ b/python/ql/src/meta/debug/DebugStats.ql @@ -1,15 +1,15 @@ import python +private import LegacyPointsTo from string msg, int cnt, int sort where sort = 0 and msg = "Lines of code in DB" and - cnt = sum(Module m | | m.getMetrics().getNumberOfLinesOfCode()) + cnt = sum(ModuleMetrics m | | m.getNumberOfLinesOfCode()) or sort = 1 and msg = "Lines of code in repo" and - cnt = - sum(Module m | exists(m.getFile().getRelativePath()) | m.getMetrics().getNumberOfLinesOfCode()) + cnt = sum(ModuleMetrics m | exists(m.getFile().getRelativePath()) | m.getNumberOfLinesOfCode()) or sort = 2 and msg = "Files" and diff --git a/python/ql/test/library-tests/ControlFlow/general/Comments.ql b/python/ql/test/library-tests/ControlFlow/general/Comments.ql index 71d00f1a8d4..7fe0545c795 100644 --- a/python/ql/test/library-tests/ControlFlow/general/Comments.ql +++ b/python/ql/test/library-tests/ControlFlow/general/Comments.ql @@ -1,5 +1,6 @@ import python +private import LegacyPointsTo -from Module m, int n -where n = m.getMetrics().getNumberOfLinesOfComments() +from ModuleMetrics m, int n +where n = m.getNumberOfLinesOfComments() select m.toString(), n diff --git a/python/ql/test/library-tests/ControlFlow/general/Cyclo.ql b/python/ql/test/library-tests/ControlFlow/general/Cyclo.ql index fb801a29002..a36375b7f3d 100644 --- a/python/ql/test/library-tests/ControlFlow/general/Cyclo.ql +++ b/python/ql/test/library-tests/ControlFlow/general/Cyclo.ql @@ -1,4 +1,5 @@ import python +private import LegacyPointsTo -from Function func -select func.toString(), func.getMetrics().getCyclomaticComplexity() +from FunctionMetrics func +select func.toString(), func.getCyclomaticComplexity() diff --git a/python/ql/test/library-tests/ControlFlow/general/Lines.ql b/python/ql/test/library-tests/ControlFlow/general/Lines.ql index ca6e7715538..2e861691fbb 100644 --- a/python/ql/test/library-tests/ControlFlow/general/Lines.ql +++ b/python/ql/test/library-tests/ControlFlow/general/Lines.ql @@ -1,8 +1,9 @@ import python +private import LegacyPointsTo from Scope s, int n where - exists(Function f | f = s | n = f.getMetrics().getNumberOfLines()) + exists(FunctionMetrics f | f = s | n = f.getNumberOfLines()) or - exists(Module m | m = s | n = m.getMetrics().getNumberOfLines()) + exists(ModuleMetrics m | m = s | n = m.getNumberOfLines()) select s.toString(), n diff --git a/python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql b/python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql index 745568f2405..a5c563b1123 100644 --- a/python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql +++ b/python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql @@ -1,6 +1,7 @@ import python +private import LegacyPointsTo -from Module m, ModuleMetrics mm -where mm = m.getMetrics() and mm.getNumberOfLines() > 0 -select m, 100.0 * (mm.getNumberOfLinesOfCode().(float) / mm.getNumberOfLines().(float)) as ratio +from ModuleMetrics mm +where mm.getNumberOfLines() > 0 +select mm, 100.0 * (mm.getNumberOfLinesOfCode().(float) / mm.getNumberOfLines().(float)) as ratio order by ratio desc