From e0c1a5b31442b6ae4ef1227c104c5e4a6a224c2a Mon Sep 17 00:00:00 2001 From: "Huska, Matthew" Date: Tue, 5 Sep 2023 17:17:22 +0200 Subject: [PATCH 1/2] Make the previous fix work for profile searches and mixes of properties and profiles, including negation --- src/covsonar/dbm.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/covsonar/dbm.py b/src/covsonar/dbm.py index e47c07c..e1cfb56 100755 --- a/src/covsonar/dbm.py +++ b/src/covsonar/dbm.py @@ -2390,9 +2390,9 @@ def create_sample_property_case( pid += 1 case, val = self.build_sample_property_condition(pname.lstrip("."), *vals) property_cases.append( - f"CASE WHEN {' AND '.join(case)} THEN 1 ELSE 0 END AS property_{pid}" + f"SUM(CASE WHEN {' AND '.join(case)} THEN 1 ELSE 0 END) AS property_{pid}" ) - property_conditions.append(f"property_{pid} = 1") + property_conditions.append(f"property_{pid} >= 1") property_vals.extend(val) return property_cases, property_conditions, property_vals @@ -2442,7 +2442,7 @@ def create_profile_cases( if match: case, val = processing_funcs[mutation_type](match) cases.append( - f"CASE WHEN {' AND '.join(case)} THEN 1 ELSE 0 END AS mutation_{ids[mutation]}" + f"SUM(CASE WHEN {' AND '.join(case)} THEN 1 ELSE 0 END) AS mutation_{ids[mutation]}" ) vals.extend(val) break @@ -2450,7 +2450,10 @@ def create_profile_cases( LOGGER.error(f"Invalid mutation notation '{mutation}'.") sys.exit(1) - where_conditions.append(f"mutation_{ids[mutation]} = {count}") + if count == 0: + where_conditions.append(f"mutation_{ids[mutation]} = {count}") + else: + where_conditions.append(f"mutation_{ids[mutation]} >= {count}") if len(where_conditions) == 1: wheres.extend(where_conditions) @@ -2551,7 +2554,7 @@ def create_sample_selection_sql( if conditions: conditions = " AND ".join(conditions) - sql += f" WHERE {conditions}" + sql += f" GROUP BY s.id HAVING {conditions}" sql += ") AS sub" From 383c6b4c2cd09b7f61a072a71be120a73421adb3 Mon Sep 17 00:00:00 2001 From: "Huska, Matthew" Date: Wed, 6 Sep 2023 10:32:42 +0200 Subject: [PATCH 2/2] Don't strip '%' from lineage LIKE queries (e.g. B.1%), because SQL needs it. --- src/covsonar/dbm.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/covsonar/dbm.py b/src/covsonar/dbm.py index e1cfb56..5469c5e 100755 --- a/src/covsonar/dbm.py +++ b/src/covsonar/dbm.py @@ -2016,7 +2016,6 @@ def build_string_condition( ) # Add the value to the corresponding operator set - val = sonarDbManager.custom_strip(val, "%") data[operator].append(val) # Assemble query conditions and values