Skip to content

Commit

Permalink
feat: remove unused json_merge method and add coalesce method to SQLi…
Browse files Browse the repository at this point in the history
…te provider; update incident field mapping to include alert_event
  • Loading branch information
skynetigor committed Jan 15, 2025
1 parent f621435 commit c3cead5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
3 changes: 0 additions & 3 deletions keep/api/core/cel_to_sql/sql_providers/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from keep.api.core.cel_to_sql.sql_providers.base import BaseCelToSqlProvider

class CelToMySqlProvider(BaseCelToSqlProvider):
def _json_merge(self, columns: List[str]) -> str:
return f"json_patch({', '.join(columns)})"

def json_extract(self, column: str, path: str) -> str:
return f"JSON_UNQUOTE(JSON_EXTRACT({column}, \"$.{path}\"))"

Expand Down
6 changes: 3 additions & 3 deletions keep/api/core/cel_to_sql/sql_providers/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from keep.api.core.cel_to_sql.sql_providers.base import BaseCelToSqlProvider

class CelToSqliteProvider(BaseCelToSqlProvider):
def _json_merge(self, columns: List[str]) -> str:
return f"json_patch({', '.join(columns)})"

def json_extract(self, column: str, path: str) -> str:
return f"json_extract({column}, \"$.{path}\")"

def coalesce(self, args):
return f"COALESCE({', '.join(args)})"

def _visit_contains_method_calling(self, property_path: str, method_args: List[str]) -> str:
return f"{property_path} LIKE \"%{method_args[0]}%\""

Expand Down
7 changes: 3 additions & 4 deletions keep/api/core/incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
)
from keep.api.models.db.facet import FacetType
from keep.api.models.facet import FacetDto, FacetOptionDto
from sqlalchemy.dialects import mysql
import uuid

# from keep.api.models.db.facet import Facet, FacetEntityType

incident_field_configurations = [
FieldMappingConfiguration("user_generated_name", "user_generated_name"),
Expand All @@ -54,7 +51,7 @@
FieldMappingConfiguration("merged_at", "merged_at"),
FieldMappingConfiguration("merged_by", "merged_by"),
FieldMappingConfiguration("alert.provider_type", "incident_alert_provider_type"),
FieldMappingConfiguration(map_from_pattern = "alert.*", map_to=["alert_enrichments"], is_json=True),
FieldMappingConfiguration(map_from_pattern = "alert.*", map_to=["alert_enrichments", "alert_event"], is_json=True),
]

properties_metadata = PropertiesMetadata(incident_field_configurations)
Expand Down Expand Up @@ -270,6 +267,8 @@ def __build_facets_data_query(
elif isinstance(metadata[0], SimpleMapping):
group_by_exp.append(item.map_to)

group_by_exp += ['NULL']

union_queries.append(
select(
literal(facet_name).label("facet_name"),
Expand Down

0 comments on commit c3cead5

Please sign in to comment.