From 59428c0bc40f8247a8ab6b65f7ae36d9a3eef6bd Mon Sep 17 00:00:00 2001 From: Jasper Deflander Date: Fri, 24 Mar 2023 08:10:01 +0100 Subject: [PATCH] Support new AQL operators --- .../api/_encode_expression.py | 23 ++++++++ src/elimity_insights_client/api/expression.py | 21 +++++++ tests/elimity_insights_client/api/schema.json | 55 +++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/src/elimity_insights_client/api/_encode_expression.py b/src/elimity_insights_client/api/_encode_expression.py index dd4474a..bc07643 100644 --- a/src/elimity_insights_client/api/_encode_expression.py +++ b/src/elimity_insights_client/api/_encode_expression.py @@ -22,6 +22,7 @@ DateTimeExpression, DirectLinkAggregateNumberExpression, DirectlyLinkedToBooleanExpression, + ExistsBooleanExpression, IdInBooleanExpression, IdStringExpression, LinkAggregateNumberExpression, @@ -40,6 +41,7 @@ LiteralStringExpression, LiteralTimeExpression, MatchBooleanExpression, + MatchesPatternBooleanExpression, MatchMode, MatchOperator, NameStringExpression, @@ -109,6 +111,16 @@ def encode_boolean_expression(expression: BooleanExpression) -> object: "type": "directlyLinkedTo", } + if isinstance(expression, ExistsBooleanExpression): + condition = encode_boolean_expression(expression.condition) + return { + "alias": expression.alias, + "condition": condition, + "entityType": expression.entity_type, + "sourceId": expression.source_id, + "type": "exists", + } + if isinstance(expression, IdInBooleanExpression): return { "ids": expression.ids, @@ -154,6 +166,14 @@ def encode_boolean_expression(expression: BooleanExpression) -> object: "type": "match", } + if isinstance(expression, MatchesPatternBooleanExpression): + expr = encode_string_expression(expression.expr) + return { + "expr": expr, + "pattern": expression.pattern, + "type": "matchesPattern", + } + if isinstance(expression, NotBooleanExpression): expr = encode_boolean_expression(expression.expr) return {"expr": expr, "type": "not"} @@ -410,6 +430,9 @@ def _encode_match_operator(operator: MatchOperator) -> object: if operator is MatchOperator.EQUALS: return "equals" + if operator is MatchOperator.SPLIT_INTERSECTS: + return "splitIntersects" + if operator is MatchOperator.STARTS_WITH: return "startsWith" diff --git a/src/elimity_insights_client/api/expression.py b/src/elimity_insights_client/api/expression.py index 297896f..16600c4 100644 --- a/src/elimity_insights_client/api/expression.py +++ b/src/elimity_insights_client/api/expression.py @@ -146,6 +146,16 @@ class DirectLinkAggregateNumberExpression: source_id: int +@dataclass +class ExistsBooleanExpression: + """Expression evaluating whether a given condition holds for some entity of a given type.""" + + alias: str + condition: "BooleanExpression" + entity_type: str + source_id: int + + @dataclass class IdInBooleanExpression: """Expression evaluating whether an entity's identifier occurs in a given list.""" @@ -304,9 +314,18 @@ class MatchOperator(Enum): CONTAINS = auto() ENDS_WITH = auto() EQUALS = auto() + SPLIT_INTERSECTS = auto() STARTS_WITH = auto() +@dataclass +class MatchesPatternBooleanExpression: + """Expression matching the result of a given expression to a given pattern.""" + + expr: "StringExpression" + pattern: str + + @dataclass class NameStringExpression: """Expression evaluating to a given entity's name.""" @@ -404,12 +423,14 @@ class TimeCmpBooleanExpression: DateCmpBooleanExpression, DateTimeCmpBooleanExpression, DirectlyLinkedToBooleanExpression, + ExistsBooleanExpression, IdInBooleanExpression, LinkAssignedBooleanExpression, LinkAttributeBooleanExpression, LinkedToBooleanExpression, LiteralBooleanExpression, MatchBooleanExpression, + MatchesPatternBooleanExpression, NotBooleanExpression, NumberCmpBooleanExpression, TimeCmpBooleanExpression, diff --git a/tests/elimity_insights_client/api/schema.json b/tests/elimity_insights_client/api/schema.json index 1c60d11..a396618 100644 --- a/tests/elimity_insights_client/api/schema.json +++ b/tests/elimity_insights_client/api/schema.json @@ -166,6 +166,9 @@ { "$ref": "#/definitions/directlyLinkedToBooleanExpression" }, + { + "$ref": "#/definitions/existsBooleanExpression" + }, { "$ref": "#/definitions/idInBooleanExpression" }, @@ -184,6 +187,9 @@ { "$ref": "#/definitions/matchBooleanExpression" }, + { + "$ref": "#/definitions/matchesPatternBooleanExpression" + }, { "$ref": "#/definitions/notBooleanExpression" }, @@ -493,6 +499,34 @@ ], "type": "object" }, + "existsBooleanExpression": { + "additionalProperties": false, + "properties": { + "alias": { + "type": "string" + }, + "condition": { + "$ref": "#/definitions/booleanExpression" + }, + "entityType": { + "type": "string" + }, + "sourceId": { + "type": "integer" + }, + "type": { + "const": "exists" + } + }, + "required": [ + "alias", + "condition", + "entityType", + "sourceId", + "type" + ], + "type": "object" + }, "grouping": { "additionalProperties": false, "properties": { @@ -852,6 +886,26 @@ ], "type": "object" }, + "matchesPatternBooleanExpression": { + "additionalProperties": false, + "properties": { + "expr": { + "$ref": "#/definitions/stringExpression" + }, + "pattern": { + "type": "string" + }, + "type": { + "const": "matchesPattern" + } + }, + "required": [ + "expr", + "pattern", + "type" + ], + "type": "object" + }, "matchMode": { "enum": [ "caseInsensitive", @@ -863,6 +917,7 @@ "contains", "endsWith", "equals", + "splitIntersects", "startsWith" ] },