Skip to content

Commit

Permalink
Merge pull request #101 from rki-mf1/fix/match-multi-prop
Browse files Browse the repository at this point in the history
Fix matching on multiple properties and profiles
  • Loading branch information
matthuska authored Sep 12, 2023
2 parents 47c3b76 + 383c6b4 commit 14e6387
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/covsonar/dbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2390,9 +2389,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
Expand Down Expand Up @@ -2442,15 +2441,18 @@ 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
if not match:
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)
Expand Down Expand Up @@ -2551,7 +2553,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"

Expand Down

0 comments on commit 14e6387

Please sign in to comment.